View | Details | Raw Unified | Return to bug 195402 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/rse/tests/subsystems/files/RSEFileSubsystemTestSuite.java (+2 lines)
Lines 8-13 Link Here
8
 * Contributors: 
8
 * Contributors: 
9
 * Martin Oberhuber (Wind River) - initial API and implementation
9
 * Martin Oberhuber (Wind River) - initial API and implementation
10
 * Martin Oberhuber (Wind River) - organize, enable and tag test cases
10
 * Martin Oberhuber (Wind River) - organize, enable and tag test cases
11
 * Johnson Ma       (Wind River) - [195402] Add tar.gz archive support
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.rse.tests.subsystems.files;
13
package org.eclipse.rse.tests.subsystems.files;
13
14
Lines 54-59 Link Here
54
		// we run in problems with that. The test needs to be executed manually with
55
		// we run in problems with that. The test needs to be executed manually with
55
		// the ftp server to use possibly changed to whatever host will do.
56
		// the ftp server to use possibly changed to whatever host will do.
56
		suite.addTestSuite(FTPFileSubsystemTestCase.class);
57
		suite.addTestSuite(FTPFileSubsystemTestCase.class);
58
		suite.addTestSuite(FileServiceTgzArchiveTest.class);
57
		
59
		
58
		return suite;
60
		return suite;
59
	}
61
	}
(-)src/org/eclipse/rse/tests/subsystems/files/FileServiceArchiveTest.java (-893 / +8 lines)
Lines 9-21 Link Here
9
 * Xuan Chen (IBM)               - initial API and implementation
9
 * Xuan Chen (IBM)               - initial API and implementation
10
 * Martin Oberhuber (Wind River) - Fix Javadoc warnings
10
 * Martin Oberhuber (Wind River) - Fix Javadoc warnings
11
 * Martin Oberhuber (Wind River) - organize, enable and tag test cases
11
 * Martin Oberhuber (Wind River) - organize, enable and tag test cases
12
 * Johnson Ma       (Wind River) - [195402] Add tar.gz archive support
12
 *******************************************************************************/
13
 *******************************************************************************/
13
package org.eclipse.rse.tests.subsystems.files;
14
package org.eclipse.rse.tests.subsystems.files;
14
15
15
import org.eclipse.core.filesystem.EFS;
16
import org.eclipse.core.filesystem.EFS;
16
import org.eclipse.core.filesystem.IFileStore;
17
import org.eclipse.core.filesystem.IFileStore;
17
import org.eclipse.core.resources.IWorkspace;
18
import org.eclipse.core.resources.ResourcesPlugin;
19
import org.eclipse.core.runtime.IAdaptable;
18
import org.eclipse.core.runtime.IAdaptable;
20
import org.eclipse.rse.core.IRSESystemType;
19
import org.eclipse.rse.core.IRSESystemType;
21
import org.eclipse.rse.core.model.ISystemResourceSet;
20
import org.eclipse.rse.core.model.ISystemResourceSet;
Lines 27-52 Link Here
27
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
26
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
28
import org.eclipse.rse.tests.RSETestsPlugin;
27
import org.eclipse.rse.tests.RSETestsPlugin;
29
28
30
public class FileServiceArchiveTest extends FileServiceBaseTest {
29
public class FileServiceArchiveTest extends FileServiceArchiveBaseTest {
31
30
32
	protected String folderToCopyName1 = "RemoteSystemsConnections";
33
	protected String folderToCopyName2 = "6YLT5Xa";
34
	protected String folderToCopyName3 = "folderToCopy";
35
	
31
	
36
	protected String zipSourceFileName1 = "closedBefore.zip";
32
	protected String zipSourceFileName1 = "closedBefore.zip";
37
	protected String zipSourceFileName2 = "mynewzip.zip";
33
	protected String zipSourceFileName2 = "mynewzip.zip";
38
	
34
	
39
	protected String tarSourceFileName1 = "source.tar";
40
	protected String tarSourceFileName2 = "mynewtar.tar";
41
	
42
	protected String tarSourceFolderName1 = "META-INF";
43
	protected String tarSourceFolderName2 = "org";
44
	
45
	protected String tarSourceForOpenTest = "tarSourceForOpen.tar";
46
	protected String tarSourceForOpenFolderName1 = "META-INF";
47
	protected String tarSourceForOpenFolderName2 = "org";
48
	
49
	protected String fileContentString1 = "this is just some dummy content \n to a remote file \n to test an open operation";
50
	protected String ZIP_SOURCE_DIR = "";
35
	protected String ZIP_SOURCE_DIR = "";
51
	protected String TEST_DIR = "";
36
	protected String TEST_DIR = "";
52
	protected String SYSTEM_TYPE_ID = IRSESystemType.SYSTEMTYPE_LOCAL_ID;
37
	protected String SYSTEM_TYPE_ID = IRSESystemType.SYSTEMTYPE_LOCAL_ID;
Lines 54-123 Link Here
54
	protected String SYSTEM_NAME = "";
39
	protected String SYSTEM_NAME = "";
55
	protected String USER_ID = "";
40
	protected String USER_ID = "";
56
	protected String PASSWORD = "";
41
	protected String PASSWORD = "";
57
	
42
58
	public static IWorkspace getWorkspace() {
43
	public FileServiceArchiveTest() {
59
		return ResourcesPlugin.getWorkspace();
44
		tarSourceFileName1 = "source.tar";
60
	}
45
		tarSourceFileName2 = "mynewtar.tar";
61
	
46
		tarSourceForOpenTest = "tarSourceForOpen.tar";
62
	public void createSourceFolders() throws Exception
47
		testName = "dummy.tar";
63
	{
64
		String tempPath = getWorkspace().getRoot().getLocation().append("temp").toString();
65
		IFileStore temp = createDir(tempPath, true);
66
		String content = getRandomString();
67
		
68
		// create the source folder used for copy or move
69
		IFileStore folderToCopy = temp.getChild(folderToCopyName3);
70
		createDir(folderToCopy, true);
71
		//Now, populate the contents in the folderToCopy.
72
		IFileStore aaaaaaaa = folderToCopy.getChild("aaaaaaaa");
73
		createDir(aaaaaaaa, true);
74
		//create file inside the aaaaaaaa folder.
75
		IFileStore adsf = aaaaaaaa.getChild("adsf");
76
		content = getRandomString();
77
		createFile(adsf, content);
78
		IFileStore eclipse_SDK_3_3M6_win32_zip = aaaaaaaa.getChild("eclipse-SDK-3.3M6-win32.zip");
79
		createFile(eclipse_SDK_3_3M6_win32_zip, "");
80
		IFileStore epdcdump01_hex12 = aaaaaaaa.getChild("epdcdump01.hex12");
81
		content = getRandomString();
82
		createFile(epdcdump01_hex12, content);
83
		IFileStore epdcdump01_hex12aaaa = aaaaaaaa.getChild("epdcdump01.hex12aaaa");
84
		content = getRandomString();
85
		createFile(epdcdump01_hex12aaaa, content);
86
		
87
		IFileStore aaaab = folderToCopy.getChild("aaaab");
88
		createDir(aaaab, true);
89
		IFileStore features = aaaab.getChild("features");
90
		createDir(features, true);
91
		IFileStore dummyFile = features.getChild("dummy.txt");
92
		content = getRandomString();
93
		createFile(dummyFile, content);
94
		//create file inside the aaaab folder.
95
		content = "this is just a simple content \n to a simple file \n to test a 'simple' copy";
96
		IFileStore epdcdump01_hex12a = aaaab.getChild("epdcdump01.hex12a");
97
		content = getRandomString();
98
		createFile(epdcdump01_hex12a, content);
99
		
100
		IFileStore epdcdump01_hex12a1 = folderToCopy.getChild("epdcdump01.hex12a");
101
		content = getRandomString();
102
		createFile(epdcdump01_hex12a1, content);
103
		
104
		IFileStore RSE_SDK_2_0RC1_zip = folderToCopy.getChild("RSE-SDK-2.0RC1.zip");
105
		content = getRandomString();
106
		createFile(RSE_SDK_2_0RC1_zip, content);
107
		
108
		//now, copy folderToCopy into the folder in the remote system
109
		IRemoteFile sourceFolderToCopy3 = localFss.getRemoteFileObject(tempPath + '\\' + folderToCopyName3, mon);
110
		ISystemDragDropAdapter srcAdapter3 = (ISystemDragDropAdapter) ((IAdaptable) sourceFolderToCopy3).getAdapter(ISystemDragDropAdapter.class);
111
		SystemRemoteResourceSet fromSet3 = new SystemRemoteResourceSet(localFss, srcAdapter3);
112
		fromSet3.addResource(sourceFolderToCopy3);
113
		ISystemResourceSet tempObjects3 = srcAdapter3.doDrag(fromSet3, mon);
114
		UniversalFileTransferUtility.uploadResourcesFromWorkspace((SystemWorkspaceResourceSet)tempObjects3, tempDir, mon, true);
115
		
116
		//Then, we need to retrieve children of the tempDir to cache their information.
117
		fss.resolveFilterString(tempDir, null, mon);
118
		
119
		//Then, delete the temp folder in the junit workspace.
120
		temp.delete(EFS.NONE, mon);
121
	}
48
	}
122
	
49
	
123
	public void createSourceZipFiles() throws Exception
50
	public void createSourceZipFiles() throws Exception
Lines 370-590 Link Here
370
		return targetDir;
297
		return targetDir;
371
	}
298
	}
372
	
299
	
373
	protected void createSuperTransferFolder(IFileStore temp) throws Exception 
374
	{
375
		
376
		String content = getRandomString();
377
		
378
		// create the source folder used for copy or move
379
		IFileStore folderToCopy = temp.getChild(folderToCopyName3);
380
		createDir(folderToCopy, true);
381
		//Now, populate the contents in the folderToCopy.
382
		IFileStore aaaaaaaa = folderToCopy.getChild("aaaaaaaa");
383
		createDir(aaaaaaaa, true);
384
		//create file inside the aaaaaaaa folder.
385
		IFileStore adsf = aaaaaaaa.getChild("adsf");
386
		content = getRandomString();
387
		createFile(adsf, content);
388
		IFileStore eclipse_SDK_3_3M6_win32_zip = aaaaaaaa.getChild("eclipse-SDK-3.3M6-win32.zip");
389
		createFile(eclipse_SDK_3_3M6_win32_zip, "");
390
		IFileStore epdcdump01_hex12 = aaaaaaaa.getChild("epdcdump01.hex12");
391
		content = getRandomString();
392
		createFile(epdcdump01_hex12, content);
393
		IFileStore epdcdump01_hex12aaaa = aaaaaaaa.getChild("epdcdump01.hex12aaaa");
394
		content = getRandomString();
395
		createFile(epdcdump01_hex12aaaa, content);
396
		
397
		IFileStore aaaab = folderToCopy.getChild("aaaab");
398
		createDir(aaaab, true);
399
		IFileStore features = aaaab.getChild("features");
400
		createDir(features, true);
401
		IFileStore dummyFile = features.getChild("dummy.txt");
402
		content = getRandomString();
403
		createFile(dummyFile, content);
404
		//create file inside the aaaab folder.
405
		content = "this is just a simple content \n to a simple file \n to test a 'simple' copy";
406
		IFileStore epdcdump01_hex12a = aaaab.getChild("epdcdump01.hex12a");
407
		content = getRandomString();
408
		createFile(epdcdump01_hex12a, content);
409
		
410
		IFileStore epdcdump01_hex12a1 = folderToCopy.getChild("epdcdump01.hex12a");
411
		content = getRandomString();
412
		createFile(epdcdump01_hex12a1, content);
413
		
414
		IFileStore RSE_SDK_2_0RC1_zip = folderToCopy.getChild("RSE-SDK-2.0RC1.zip");
415
		content = getRandomString();
416
		createFile(RSE_SDK_2_0RC1_zip, content);
417
		
418
		return;
419
420
	}
421
	
422
	public void createTarSourceForOpen() throws Exception
423
	{
424
		String tempPath = getWorkspace().getRoot().getLocation().append("temp").toString();
425
		IFileStore temp = createDir(tempPath, true);
426
		String content = getRandomString();
427
		
428
		//Now, we need to construct a "source.tar" archive file
429
		//We will construct the content of the tar file in folders "META-INF" and "org"
430
		//Then we copy this folder into a tar file by RSE API.
431
		IFileStore META_INF = temp.getChild(tarSourceForOpenFolderName1);
432
		createDir(META_INF, true);
433
		//Now, populate the contents in the folder.
434
		IFileStore MANIFEST_MF = META_INF.getChild("MANIFEST.MF");
435
		content = fileContentString1;
436
		createFile(MANIFEST_MF, content);
437
		
438
		//create folder "org"
439
		IFileStore org = temp.getChild("org");
440
		createDir(org, true);
441
		IFileStore eclipse = org.getChild("eclipse");
442
		createDir(eclipse, true);
443
		//create "dstore" folder inside "org"
444
		IFileStore dstore = eclipse.getChild("dstore");
445
		createDir(dstore, true);
446
		//Now, create a few folders inside the dstore folder.
447
		IFileStore core = dstore.getChild("core");
448
		createDir(core, true);
449
		IFileStore internal = dstore.getChild("internal");
450
		createDir(internal, true);
451
		
452
		//now create directory inside "core":
453
		IFileStore client = core.getChild("client");
454
		createDir(client, true);
455
		IFileStore java = core.getChild("java");
456
		createDir(java, true);
457
		IFileStore miners = core.getChild("miners");
458
		createDir(miners, true);
459
		IFileStore model = core.getChild("model");
460
		createDir(model, true);
461
		IFileStore server = core.getChild("server");
462
		createDir(server, true);
463
		IFileStore util = core.getChild("util");
464
		createDir(util, true);
465
		IFileStore Activator_java = core.getChild("Activator.java");
466
		content = fileContentString1;
467
		createFile(Activator_java, content);
468
		
469
		//now, some contents on client folder
470
		IFileStore ClientConnection_java = client.getChild("ClientConnection.java");
471
		content = getRandomString();
472
		createFile(ClientConnection_java, content);
473
		IFileStore ConnectionStatus_java = client.getChild("ConnectionStatus.java");
474
		content = fileContentString1;
475
		createFile(ConnectionStatus_java, content);
476
		
477
		//now, some contents in java folder
478
		IFileStore ClassByteStreamHandler$ReceiveClassInstanceThread_java = java.getChild("ClassByteStreamHandler$ReceiveClassInstanceThread.java");
479
		content = getRandomString();
480
		createFile(ClassByteStreamHandler$ReceiveClassInstanceThread_java, content);
481
		
482
		//now, some contents in miners folder
483
		IFileStore Miner_java = miners.getChild("Miner.java");
484
		content = getRandomString();
485
		createFile(Miner_java, content);
486
		IFileStore MinerThread_java = miners.getChild("MinerThread.java");
487
		content = getRandomString();
488
		createFile(MinerThread_java, content);
489
		
490
		//now, some contents in model folder
491
		IFileStore ByteStreamHandler_java = model.getChild("ByteStreamHandler.java");
492
		content = getRandomString();
493
		createFile(ByteStreamHandler_java, content);
494
		IFileStore DE_java = model.getChild("DE.java");
495
		content = getRandomString();
496
		createFile(DE_java, content);
497
		IFileStore Handler_java = model.getChild("Handler.java");
498
		content = getRandomString();
499
		createFile(Handler_java, content);
500
		
501
		//now, some contents in server folder
502
		IFileStore Server_java = server.getChild("Server.java");
503
		content = getRandomString();
504
		createFile(Server_java, content);
505
		
506
		//now, some contents in util folder
507
		IFileStore StringCompare_java = util.getChild("StringCompare.java");
508
		content = fileContentString1;
509
		createFile(StringCompare_java, content);
510
		
511
		//now, create the contents in "internal" folder
512
		IFileStore core1 = internal.getChild("core");
513
		createDir(core1, true);
514
		
515
		//then create some folder in this "core" folder
516
		IFileStore client1 = core1.getChild("client");
517
		createDir(client1, true);
518
		IFileStore model1 = core1.getChild("model");
519
		createDir(model1, true);
520
		IFileStore server1 = core1.getChild("server");
521
		createDir(server1, true);
522
		IFileStore util1 = core1.getChild("util");
523
		createDir(util1, true);
524
		
525
		//now, some contents on client folder
526
		IFileStore ClientConnection_java1 = client1.getChild("ClientConnection.java");
527
		content = getRandomString();
528
		createFile(ClientConnection_java1, content);
529
		IFileStore ConnectionStatus_java1 = client1.getChild("ConnectionStatus.java");
530
		content = getRandomString();
531
		createFile(ConnectionStatus_java1, content);
532
		
533
		
534
		//now, some contents in model folder
535
		IFileStore ByteStreamHandler_java1 = model1.getChild("ByteStreamHandler.java");
536
		content = getRandomString();
537
		createFile(ByteStreamHandler_java1, content);
538
		IFileStore DE_java1 = model1.getChild("DE.java");
539
		content = getRandomString();
540
		createFile(DE_java1, content);
541
		IFileStore Handler_java1 = model1.getChild("Handler.java");
542
		content = getRandomString();
543
		createFile(Handler_java1, content);
544
		
545
		//now, some contents in server folder
546
		IFileStore Server_java1 = server1.getChild("Server.java");
547
		content = getRandomString();
548
		createFile(Server_java1, content);
549
		
550
		//now, some contents in util folder
551
		IFileStore StringCompare_java1 = util1.getChild("StringCompare.java");
552
		content = getRandomString();
553
		createFile(StringCompare_java1, content);
554
		
555
		//now, copy META_INF into the folder in the remote system
556
		IRemoteFile META_INF_folder = localFss.getRemoteFileObject(tempPath + '\\' + tarSourceForOpenFolderName1, mon);
557
		assertNotNull(META_INF_folder);
558
		ISystemDragDropAdapter srcAdapter1 = (ISystemDragDropAdapter) ((IAdaptable) META_INF_folder).getAdapter(ISystemDragDropAdapter.class);
559
		SystemRemoteResourceSet fromSet = new SystemRemoteResourceSet(localFss, srcAdapter1);
560
		fromSet.addResource(META_INF_folder);
561
		ISystemResourceSet tempObjects1 = srcAdapter1.doDrag(fromSet, mon);
562
		UniversalFileTransferUtility.uploadResourcesFromWorkspace((SystemWorkspaceResourceSet)tempObjects1, tempDir, mon, true);
563
		
564
		//now, copy org into the folder in the remote system
565
		IRemoteFile org_folder = localFss.getRemoteFileObject(tempPath + '\\' + tarSourceForOpenFolderName2, mon);
566
		assertNotNull(org_folder);
567
		ISystemDragDropAdapter srcAdapter2 = (ISystemDragDropAdapter) ((IAdaptable) org_folder).getAdapter(ISystemDragDropAdapter.class);
568
		SystemRemoteResourceSet fromSet2 = new SystemRemoteResourceSet(localFss, srcAdapter2);
569
		fromSet2.addResource(org_folder);
570
		ISystemResourceSet tempObjects2 = srcAdapter2.doDrag(fromSet2, mon);
571
		UniversalFileTransferUtility.uploadResourcesFromWorkspace((SystemWorkspaceResourceSet)tempObjects2, tempDir, mon, true);
572
		
573
		//now, create tar file in the host
574
		IRemoteFile tarSource = createFileOrFolder(tempDir.getAbsolutePath(), tarSourceForOpenTest, false);
575
		assertNotNull(tarSource);
576
		IRemoteFile tarSourceFolder1 = (IRemoteFile)getChildFromFolder(tempDir, tarSourceForOpenFolderName1); 
577
		assertNotNull(tarSourceFolder1);
578
		IRemoteFile tarSourceFolder2 = (IRemoteFile)getChildFromFolder(tempDir, tarSourceForOpenFolderName2);
579
		fss.copy(tarSourceFolder1, tarSource, tarSourceForOpenFolderName1, mon);
580
		fss.copy(tarSourceFolder2, tarSource, tarSourceForOpenFolderName2, mon);
581
		
582
		//Then, we need to retrieve children of the tempDir to cache their information.
583
		fss.resolveFilterString(tempDir, null, mon);
584
		
585
		//Then, delete the temp folder in the junit workspace.
586
		temp.delete(EFS.NONE, mon);
587
	}
588
	
300
	
589
301
590
	public void testCreateZipFile() throws Exception {
302
	public void testCreateZipFile() throws Exception {
Lines 1406-1654 Link Here
1406
		checkFolderContents((IRemoteFile)theCopiedChild, childrenToCheck, typesToCheck);
1118
		checkFolderContents((IRemoteFile)theCopiedChild, childrenToCheck, typesToCheck);
1407
	}
1119
	}
1408
	
1120
	
1409
	public void createSourceTarFiles() throws Exception
1410
	{
1411
		String tempPath = getWorkspace().getRoot().getLocation().append("temp").toString();
1412
		IFileStore temp = createDir(tempPath, true);
1413
		String content = getRandomString();
1414
		
1415
		//Now, we need to construct a "source.tar" archive file
1416
		//We will construct the content of the tar file in folders "META-INF" and "org"
1417
		//Then we copy this folder into a tar file by RSE API.
1418
		IFileStore META_INF = temp.getChild(tarSourceFolderName1);
1419
		createDir(META_INF, true);
1420
		//Now, populate the contents in the folder.
1421
		IFileStore MANIFEST_MF = META_INF.getChild("MANIFEST.MF");
1422
		content = getRandomString();
1423
		createFile(MANIFEST_MF, content);
1424
		//create folder "org"
1425
		IFileStore org = temp.getChild(tarSourceFolderName2);
1426
		createDir(org, true);
1427
		IFileStore eclipse = org.getChild("eclipse");
1428
		createDir(eclipse, true);
1429
		//create "dstore" folder inside "org"
1430
		IFileStore dstore = eclipse.getChild("dstore");
1431
		createDir(dstore, true);
1432
		//Now, create a few folders inside the dstore folder.
1433
		IFileStore core = dstore.getChild("core");
1434
		createDir(core, true);
1435
		IFileStore internal = dstore.getChild("internal");
1436
		createDir(internal, true);
1437
		
1438
		//now create directory inside "core":
1439
		IFileStore client = core.getChild("client");
1440
		createDir(client, true);
1441
		IFileStore java = core.getChild("java");
1442
		createDir(java, true);
1443
		IFileStore miners = core.getChild("miners");
1444
		createDir(miners, true);
1445
		IFileStore model = core.getChild("model");
1446
		createDir(model, true);
1447
		IFileStore server = core.getChild("server");
1448
		createDir(server, true);
1449
		IFileStore util = core.getChild("util");
1450
		createDir(util, true);
1451
		IFileStore Activator_java = core.getChild("Activator.java");
1452
		content = getRandomString();
1453
		createFile(Activator_java, content);
1454
		
1455
		//now, some contents on client folder
1456
		IFileStore ClientConnection_java = client.getChild("ClientConnection.java");
1457
		content = getRandomString();
1458
		createFile(ClientConnection_java, content);
1459
		IFileStore ConnectionStatus_java = client.getChild("ConnectionStatus.java");
1460
		content = getRandomString();
1461
		createFile(ConnectionStatus_java, content);
1462
		
1463
		//now, some contents in java folder
1464
		IFileStore ClassByteStreamHandler$ReceiveClassInstanceThread_java = java.getChild("ClassByteStreamHandler$ReceiveClassInstanceThread.java");
1465
		content = getRandomString();
1466
		createFile(ClassByteStreamHandler$ReceiveClassInstanceThread_java, content);
1467
		
1468
		//now, some contents in miners folder
1469
		IFileStore Miner_java = miners.getChild("Miner.java");
1470
		content = getRandomString();
1471
		createFile(Miner_java, content);
1472
		IFileStore MinerThread_java = miners.getChild("MinerThread.java");
1473
		content = getRandomString();
1474
		createFile(MinerThread_java, content);
1475
		
1476
		//now, some contents in model folder
1477
		IFileStore ByteStreamHandler_java = model.getChild("ByteStreamHandler.java");
1478
		content = getRandomString();
1479
		createFile(ByteStreamHandler_java, content);
1480
		IFileStore DE_java = model.getChild("DE.java");
1481
		content = getRandomString();
1482
		createFile(DE_java, content);
1483
		IFileStore Handler_java = model.getChild("Handler.java");
1484
		content = getRandomString();
1485
		createFile(Handler_java, content);
1486
		
1487
		//now, some contents in server folder
1488
		IFileStore Server_java = server.getChild("Server.java");
1489
		content = getRandomString();
1490
		createFile(Server_java, content);
1491
		
1492
		//now, some contents in util folder
1493
		IFileStore StringCompare_java = util.getChild("StringCompare.java");
1494
		content = getRandomString();
1495
		createFile(StringCompare_java, content);
1496
		
1497
		//now, create the contents in "internal" folder
1498
		IFileStore core1 = internal.getChild("core");
1499
		createDir(core1, true);
1500
		
1501
		//then create some folder in this "core" folder
1502
		IFileStore client1 = core1.getChild("client");
1503
		createDir(client1, true);
1504
		IFileStore model1 = core1.getChild("model");
1505
		createDir(model1, true);
1506
		IFileStore server1 = core1.getChild("server");
1507
		createDir(server1, true);
1508
		IFileStore util1 = core1.getChild("util");
1509
		createDir(util1, true);
1510
		
1511
		//now, some contents on client folder
1512
		IFileStore ClientConnection_java1 = client1.getChild("ClientConnection.java");
1513
		content = getRandomString();
1514
		createFile(ClientConnection_java1, content);
1515
		IFileStore ConnectionStatus_java1 = client1.getChild("ConnectionStatus.java");
1516
		content = getRandomString();
1517
		createFile(ConnectionStatus_java1, content);
1518
		
1519
		
1520
		//now, some contents in model folder
1521
		IFileStore ByteStreamHandler_java1 = model1.getChild("ByteStreamHandler.java");
1522
		content = getRandomString();
1523
		createFile(ByteStreamHandler_java1, content);
1524
		IFileStore DE_java1 = model1.getChild("DE.java");
1525
		content = getRandomString();
1526
		createFile(DE_java1, content);
1527
		IFileStore Handler_java1 = model1.getChild("Handler.java");
1528
		content = getRandomString();
1529
		createFile(Handler_java1, content);
1530
		
1531
		//now, some contents in server folder
1532
		IFileStore Server_java1 = server1.getChild("Server.java");
1533
		content = getRandomString();
1534
		createFile(Server_java1, content);
1535
		
1536
		//now, some contents in util folder
1537
		IFileStore StringCompare_java1 = util1.getChild("StringCompare.java");
1538
		content = getRandomString();
1539
		createFile(StringCompare_java1, content);
1540
		
1541
		//now, copy META_INF into the folder in the remote system
1542
		IRemoteFile META_INF_folder = localFss.getRemoteFileObject(tempPath + '\\' + tarSourceFolderName1, mon);
1543
		assertNotNull(META_INF_folder);
1544
		ISystemDragDropAdapter srcAdapter1 = (ISystemDragDropAdapter) ((IAdaptable) META_INF_folder).getAdapter(ISystemDragDropAdapter.class);
1545
		SystemRemoteResourceSet fromSet = new SystemRemoteResourceSet(localFss, srcAdapter1);
1546
		fromSet.addResource(META_INF_folder);
1547
		ISystemResourceSet tempObjects1 = srcAdapter1.doDrag(fromSet, mon);
1548
		UniversalFileTransferUtility.uploadResourcesFromWorkspace((SystemWorkspaceResourceSet)tempObjects1, tempDir, mon, true);
1549
		
1550
		//now, copy org into the folder in the remote system
1551
		IRemoteFile org_folder = localFss.getRemoteFileObject(tempPath + '\\' + tarSourceFolderName2, mon);
1552
		assertNotNull(org_folder);
1553
		ISystemDragDropAdapter srcAdapter2 = (ISystemDragDropAdapter) ((IAdaptable) org_folder).getAdapter(ISystemDragDropAdapter.class);
1554
		SystemRemoteResourceSet fromSet2 = new SystemRemoteResourceSet(localFss, srcAdapter2);
1555
		fromSet2.addResource(org_folder);
1556
		ISystemResourceSet tempObjects2 = srcAdapter2.doDrag(fromSet2, mon);
1557
		UniversalFileTransferUtility.uploadResourcesFromWorkspace((SystemWorkspaceResourceSet)tempObjects2, tempDir, mon, true);
1558
		
1559
		//now, create tar file in the host
1560
		IRemoteFile tarSource = createFileOrFolder(tempDir.getAbsolutePath(), tarSourceFileName1, false);
1561
		assertNotNull(tarSource);
1562
		IRemoteFile tarSourceFolder1 = (IRemoteFile)getChildFromFolder(tempDir, tarSourceFolderName1); 
1563
		assertNotNull(tarSourceFolder1);
1564
		IRemoteFile tarSourceFolder2 = (IRemoteFile)getChildFromFolder(tempDir, tarSourceFolderName2);
1565
		fss.copy(tarSourceFolder1, tarSource, tarSourceFolderName1, mon);
1566
		fss.copy(tarSourceFolder2, tarSource, tarSourceFolderName2, mon);
1567
	}
1568
	
1121
	
1569
	public void testCreateTarFile() throws Exception {
1570
		//-test-author-:XuanChen
1571
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
1572
		
1573
		//Create the zip file first.
1574
		String testName = "dummy.tar";
1575
		IRemoteFile newArchiveFile = createFileOrFolder(tempDirPath, testName, false);
1576
		assertNotNull(newArchiveFile);
1577
		assertTrue(newArchiveFile.exists());
1578
		assertTrue(newArchiveFile.canRead());
1579
		assertTrue(newArchiveFile.canWrite());
1580
		assertEquals(newArchiveFile.getName(), testName);
1581
		assertEquals(newArchiveFile.getParentPath(), tempDirPath);
1582
		
1583
		//fss.resolveFilterString(filterString, monitor)
1584
		
1585
		//Now, we want to create a text file inside.
1586
		String childName = "aaa.txt";
1587
		IRemoteFile file1 = createFileOrFolder(newArchiveFile.getAbsolutePath(), childName, false);
1588
		assertNotNull(file1);
1589
		
1590
		childName = "bbb.txt";
1591
		IRemoteFile file2 = createFileOrFolder(newArchiveFile.getAbsolutePath(), childName, false);
1592
		assertNotNull(file2);
1593
		
1594
		//Create a folder
1595
		childName = "folder1";
1596
		IRemoteFile folder1 = createFileOrFolder(newArchiveFile.getAbsolutePath(), childName, true);
1597
		assertNotNull(folder1);
1598
		
1599
		//Now, check the contents
1600
		String[] namesToCheck = {"aaa.txt", "bbb.txt", "folder1"};
1601
		int[] typesToCheck = {TYPE_FILE, TYPE_FILE, TYPE_FOLDER};
1602
		checkFolderContents(newArchiveFile, namesToCheck, typesToCheck);
1603
		
1604
		//Now, create some files inside the folder.
1605
		String secondLevelChildName = "ccc.exe";
1606
		IRemoteFile levelTwoChild1 = createFileOrFolder(folder1.getAbsolutePath(), secondLevelChildName, false);
1607
		assertNotNull(levelTwoChild1);
1608
		
1609
		secondLevelChildName = "ddd.bat";
1610
		IRemoteFile levelTwoChild2 = createFileOrFolder(folder1.getAbsolutePath(), secondLevelChildName, false);
1611
		assertNotNull(levelTwoChild2);
1612
		
1613
		secondLevelChildName = "another Folder"; //folder with space
1614
		IRemoteFile levelTwoChild3 = createFileOrFolder(folder1.getAbsolutePath(), secondLevelChildName, true);
1615
		assertNotNull(levelTwoChild3);
1616
		
1617
		//Now, check the contents
1618
		String[] namesToCheck1 = {"ccc.exe", "ddd.bat", "another Folder"};
1619
		int[] typesToCheck1 = {TYPE_FILE, TYPE_FILE, TYPE_FOLDER};
1620
		checkFolderContents(folder1, namesToCheck1, typesToCheck1);
1621
	}
1622
	
1122
	
1623
	public void testCopyToTarArchiveFile() throws Exception {
1624
		//-test-author-:XuanChen
1625
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
1626
		
1627
		//create the source for testing first
1628
		createSourceTarFiles();
1629
		createSourceFolders();
1630
		
1631
		String tarTargetFileName = tarSourceFileName1;
1632
		IRemoteFile targetTarFile = (IRemoteFile)getChildFromFolder(tempDir, tarTargetFileName);
1633
		assertNotNull(targetTarFile);
1634
		
1635
		String sourceFolderName = folderToCopyName3;
1636
		IRemoteFile sourceFolder = (IRemoteFile)getChildFromFolder(tempDir, sourceFolderName);
1637
		assertNotNull(sourceFolder);
1638
		
1639
		//Now, copy one of the folder from the sourceFolder into copiedTargetZipFile
1640
		fss.copy(sourceFolder, targetTarFile, sourceFolder.getName(), mon);
1641
		
1642
		Object theCopiedChild = getChildFromFolder(targetTarFile, sourceFolderName);
1643
		
1644
		assertNotNull(theCopiedChild);
1645
		
1646
		//Also make sure the copied child has the right contents.
1647
		String[] childrenToCheck = {"aaaaaaaa", "aaaab", "epdcdump01.hex12a", "RSE-SDK-2.0RC1.zip"};
1648
		
1649
		int[] typesToCheck = {TYPE_FOLDER, TYPE_FOLDER, TYPE_FILE, TYPE_FILE};
1650
		checkFolderContents((IRemoteFile)theCopiedChild, childrenToCheck, typesToCheck);
1651
	}
1652
1123
1653
	public void testCopyToTarVirtualFileLevelOne() throws Exception {
1124
	public void testCopyToTarVirtualFileLevelOne() throws Exception {
1654
		//-test-author-:XuanChen
1125
		//-test-author-:XuanChen
Lines 1721-1755 Link Here
1721
		checkFolderContents((IRemoteFile)theCopiedChild, childrenToCheck, typesToCheck);
1192
		checkFolderContents((IRemoteFile)theCopiedChild, childrenToCheck, typesToCheck);
1722
	}
1193
	}
1723
1194
1724
	public void testCopyTarVirtualFile() throws Exception {
1725
		//-test-author-:XuanChen
1726
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
1727
		
1728
		//create the source for testing first
1729
		createSourceTarFiles();
1730
		
1731
		String sourceFileName = tarSourceFileName1;
1732
		IRemoteFile sourceTarFile = (IRemoteFile)getChildFromFolder(tempDir, sourceFileName);
1733
		assertNotNull(sourceTarFile);
1734
		
1735
		//then, create a folder inside the tempDir
1736
		String folderName = "folder1";
1737
		IRemoteFile folder1 = createFileOrFolder(tempDirPath, folderName, true);
1738
		assertNotNull(folder1);
1739
		
1740
		//Get one of its fourth level children, and copy the folder to there.
1741
		IRemoteFile firstLevelChild = (IRemoteFile)getChildFromFolder(sourceTarFile, tarSourceFolderName1);
1742
		assertNotNull(firstLevelChild);
1743
		
1744
		fss.copy(firstLevelChild, folder1, tarSourceFolderName1, mon);
1745
		
1746
		Object copiedVirtualFolder = getChildFromFolder(folder1, tarSourceFolderName1);
1747
		assertNotNull(copiedVirtualFolder);
1748
		
1749
		String[] contents = {"MANIFEST.MF"};
1750
		int[] typesToCheck = {TYPE_FILE};
1751
		checkFolderContents((IRemoteFile)copiedVirtualFolder, contents, typesToCheck);
1752
	}
1753
1195
1754
	public void testCopyTarVirtualFileLevelFour() throws Exception {
1196
	public void testCopyTarVirtualFileLevelFour() throws Exception {
1755
		//-test-author-:XuanChen
1197
		//-test-author-:XuanChen
Lines 1799-1836 Link Here
1799
		checkFolderContents((IRemoteFile)copiedVirtualFolder, contents, typesToCheck);
1241
		checkFolderContents((IRemoteFile)copiedVirtualFolder, contents, typesToCheck);
1800
	}
1242
	}
1801
1243
1802
	public void testMoveToTarArchiveFile() throws Exception {
1803
		//-test-author-:XuanChen
1804
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
1805
		
1806
		//create the source for testing first
1807
		createSourceTarFiles();
1808
		createSourceFolders();
1809
		
1810
		String tarTargetFileName = tarSourceFileName1;
1811
		IRemoteFile targetTarFile = (IRemoteFile)getChildFromFolder(tempDir, tarTargetFileName);
1812
		assertNotNull(targetTarFile);
1813
		
1814
		String sourceFolderName = folderToCopyName3;
1815
		IRemoteFile sourceFolder = (IRemoteFile)getChildFromFolder(tempDir, sourceFolderName);
1816
		assertNotNull(sourceFolder);
1817
		
1818
		fss.move(sourceFolder, targetTarFile, sourceFolder.getName(), mon);
1819
		
1820
		Object theMovedChild = getChildFromFolder(targetTarFile, sourceFolderName);
1821
		
1822
		assertNotNull(theMovedChild);
1823
		
1824
		//Also make sure the copied child has the right contents.
1825
		String[] childrenToCheck = {"aaaaaaaa", "aaaab", "epdcdump01.hex12a", "RSE-SDK-2.0RC1.zip"};
1826
		
1827
		int[] typesToCheck = {TYPE_FOLDER, TYPE_FOLDER, TYPE_FILE, TYPE_FILE};
1828
		checkFolderContents((IRemoteFile)theMovedChild, childrenToCheck, typesToCheck);
1829
		
1830
		//make sure the original folder is gone.
1831
		Object originalSource = getChildFromFolder(tempDir, sourceFolderName);
1832
		assertNull(originalSource);
1833
	}
1834
1244
1835
	public void testMoveToTarVirtualFileLevelOne() throws Exception {
1245
	public void testMoveToTarVirtualFileLevelOne() throws Exception {
1836
		//-test-author-:XuanChen
1246
		//-test-author-:XuanChen
Lines 1912-1952 Link Here
1912
		assertNull(originalSource);
1322
		assertNull(originalSource);
1913
	}
1323
	}
1914
1324
1915
	public void testMoveTarVirtualFile() throws Exception {
1916
		//-test-author-:XuanChen
1917
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
1918
		
1919
		//create the source for testing first
1920
		createSourceTarFiles();
1921
		
1922
		String sourceFileName = tarSourceFileName1;
1923
		IRemoteFile sourceTarFile = (IRemoteFile)getChildFromFolder(tempDir, sourceFileName);
1924
		assertNotNull(sourceTarFile);
1925
		
1926
		//then, create a folder inside the tempDir
1927
		//then, create a folder inside the tempDir
1928
		String folderName = "folder1";
1929
		IRemoteFile folder1 = createFileOrFolder(tempDirPath, folderName, true);
1930
		assertNotNull(folder1);
1931
		
1932
		//Now, copy one of the folder from the zip file into folder1
1933
		String movedFolderName = tarSourceFolderName1;
1934
		IRemoteFile firstLevelChild = (IRemoteFile)getChildFromFolder(sourceTarFile, tarSourceFolderName1);
1935
		assertNotNull(firstLevelChild);
1936
		fss.move(firstLevelChild, folder1, movedFolderName, mon);
1937
		
1938
		Object movedVirtualFolder = getChildFromFolder(folder1, movedFolderName);
1939
		
1940
		assertNotNull(movedVirtualFolder);
1941
		
1942
		String[] contents = {"MANIFEST.MF"};
1943
		int[] typesToCheck = {TYPE_FILE};
1944
		checkFolderContents((IRemoteFile)movedVirtualFolder, contents, typesToCheck);
1945
		
1946
		//Now, make sure the moved virtual folder is gone from its original zip file
1947
		IRemoteFile tmp = (IRemoteFile)getChildFromFolder(sourceTarFile, tarSourceFolderName1);
1948
		assertNull(tmp);
1949
	}
1950
1325
1951
	public void testMoveTarVirtualFileLevelFour() throws Exception {
1326
	public void testMoveTarVirtualFileLevelFour() throws Exception {
1952
		//-test-author-:XuanChen
1327
		//-test-author-:XuanChen
Lines 1992-2192 Link Here
1992
		assertNull(result);  //we should not be able to find it.
1367
		assertNull(result);  //we should not be able to find it.
1993
	}
1368
	}
1994
1369
1995
	public void testRenameTarVirtualFile() throws Exception {
1996
		//-test-author-:XuanChen
1997
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
1998
		
1999
		//Create the zip file first.
2000
		String testName = "source.tar";
2001
		IRemoteFile newArchiveFile = createFileOrFolder(tempDirPath, testName, false);
2002
		
2003
		//Now, we want to create a text file inside.
2004
		String childName = "aaa.txt";
2005
		IRemoteFile file1 = createFileOrFolder(newArchiveFile.getAbsolutePath(), childName, false);
2006
		assertNotNull(file1);
2007
		
2008
		childName = "bbb.txt";
2009
		IRemoteFile file2 = createFileOrFolder(newArchiveFile.getAbsolutePath(), childName, false);
2010
		assertNotNull(file2);
2011
		
2012
		//Create a folder
2013
		childName = "folder1";
2014
		IRemoteFile folder1 = createFileOrFolder(newArchiveFile.getAbsolutePath(), childName, true);
2015
		assertNotNull(folder1);
2016
		
2017
		//Now, check the contents
2018
		String[] levelOneNamesToCheck = {"aaa.txt", "bbb.txt", "folder1"};
2019
		int[] levalOneTypesToCheck = {TYPE_FILE, TYPE_FILE, TYPE_FOLDER};
2020
		checkFolderContents(newArchiveFile, levelOneNamesToCheck, levalOneTypesToCheck);
2021
		
2022
		//Now, create some files inside the folder.
2023
		String secondLevelChildName = "ccc.exe";
2024
		IRemoteFile levelTwoChild1 = createFileOrFolder(folder1.getAbsolutePath(), secondLevelChildName, false);
2025
		assertNotNull(levelTwoChild1);
2026
		
2027
		secondLevelChildName = "ddd.bat";
2028
		IRemoteFile levelTwoChild2 = createFileOrFolder(folder1.getAbsolutePath(), secondLevelChildName, false);
2029
		assertNotNull(levelTwoChild2);
2030
		
2031
		secondLevelChildName = "another Folder"; //folder with space
2032
		IRemoteFile levelTwoChild3 = createFileOrFolder(folder1.getAbsolutePath(), secondLevelChildName, true);
2033
		assertNotNull(levelTwoChild3);
2034
		
2035
		//Now, check the contents
2036
		String[] levelTwoNamesToCheck = {"ccc.exe", "ddd.bat", "another Folder"};
2037
		int[] levalTwoTypesToCheck = {TYPE_FILE, TYPE_FILE, TYPE_FOLDER};
2038
		checkFolderContents(folder1, levelTwoNamesToCheck, levalTwoTypesToCheck);
2039
		
2040
		//Now rename one of the text file in the first level:
2041
		IRemoteFile childToRename = (IRemoteFile)getChildFromFolder(newArchiveFile, "aaa.txt");
2042
		fss.rename(childToRename, "aaa1.txt", mon);
2043
		//Now rename one of the folder in the first level
2044
		childToRename = (IRemoteFile)getChildFromFolder(newArchiveFile, "folder1");
2045
		fss.rename(childToRename, "folder2", mon);
2046
		
2047
		//Check the result of rename
2048
		String[] newLevelOneNamesToCheck = {"aaa1.txt", "bbb.txt", "folder2"};
2049
		checkFolderContents(newArchiveFile, newLevelOneNamesToCheck, levalOneTypesToCheck);
2050
		
2051
		//Now rename one of the text file in the second level:
2052
		IRemoteFile thisFolder = (IRemoteFile)getChildFromFolder(newArchiveFile, "folder2");
2053
		childToRename = (IRemoteFile)getChildFromFolder(thisFolder, "ddd.bat");
2054
		fss.rename(childToRename, "ddd1.bat", mon);
2055
		//Now rename one of the folder in the second level
2056
		childToRename = (IRemoteFile)getChildFromFolder(thisFolder, "another Folder");
2057
		fss.rename(childToRename, "some folder$", mon);
2058
		
2059
		//Check the result of rename
2060
		String[] newLevelTwoNamesToCheck = {"ccc.exe", "ddd1.bat", "some folder$"};
2061
		checkFolderContents(thisFolder, newLevelTwoNamesToCheck, levalTwoTypesToCheck);
2062
	}
2063
2064
	public void testDeleteTarVirtualFile() throws Exception {
2065
		//-test-author-:XuanChen
2066
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
2067
		
2068
		//create the source for testing first
2069
		createSourceTarFiles();
2070
		
2071
		String sourceFileName = tarSourceFileName1;
2072
		IRemoteFile sourceTarFile = (IRemoteFile)getChildFromFolder(tempDir, sourceFileName);
2073
		assertNotNull(sourceTarFile);
2074
		
2075
		//delete a file from level 2
2076
		String parentForFileToDeleteName ="META-INF";
2077
		IRemoteFile parentForFileToDelete = (IRemoteFile)getChildFromFolder(sourceTarFile, parentForFileToDeleteName);
2078
		assertNotNull(parentForFileToDelete);
2079
		String deleteFileName = "MANIFEST.MF";
2080
		IRemoteFile fileToToDelete = (IRemoteFile)getChildFromFolder(parentForFileToDelete, deleteFileName);
2081
		assertNotNull(fileToToDelete);
2082
		//Now, delete this file
2083
		fss.delete(fileToToDelete, mon);
2084
		fileToToDelete = (IRemoteFile)getChildFromFolder(parentForFileToDelete, deleteFileName);
2085
		assertNull(fileToToDelete);
2086
		
2087
		//then, get directory "java" under org/eclipse/dstore/core
2088
		String parentForDirectoryToDeleteName ="org";
2089
		IRemoteFile parentForDirectoryToDelete = (IRemoteFile)getChildFromFolder(sourceTarFile, parentForDirectoryToDeleteName);
2090
		assertNotNull(parentForDirectoryToDelete);
2091
		
2092
		parentForDirectoryToDeleteName ="eclipse";
2093
		parentForDirectoryToDelete = (IRemoteFile)getChildFromFolder(parentForDirectoryToDelete, parentForDirectoryToDeleteName);
2094
		assertNotNull(parentForDirectoryToDelete);
2095
		
2096
		parentForDirectoryToDeleteName ="dstore";
2097
		parentForDirectoryToDelete = (IRemoteFile)getChildFromFolder(parentForDirectoryToDelete, parentForDirectoryToDeleteName);
2098
		assertNotNull(parentForDirectoryToDelete);
2099
		
2100
		parentForDirectoryToDeleteName ="core";
2101
		parentForDirectoryToDelete = (IRemoteFile)getChildFromFolder(parentForDirectoryToDelete, parentForDirectoryToDeleteName);
2102
		assertNotNull(parentForDirectoryToDelete);
2103
		
2104
		String directoryToDeleteName = "java";
2105
		IRemoteFile directoryToDelete = (IRemoteFile)getChildFromFolder(parentForDirectoryToDelete, directoryToDeleteName);
2106
		//Now, delete this directory
2107
		fss.delete(directoryToDelete, mon);
2108
		directoryToDelete = (IRemoteFile)getChildFromFolder(parentForDirectoryToDelete, directoryToDeleteName);
2109
		
2110
		//check result of this operation
2111
		String[] contents = {"client", "miners", "model", "server", "util", "Activator.java"};
2112
		int[] typesToCheck = {TYPE_FOLDER, TYPE_FOLDER, TYPE_FOLDER, TYPE_FOLDER, TYPE_FOLDER, TYPE_FILE};
2113
		checkFolderContents(parentForDirectoryToDelete, contents, typesToCheck);
2114
		
2115
		//And check this directory is not there any more.
2116
		directoryToDelete = (IRemoteFile)getChildFromFolder(parentForDirectoryToDelete, directoryToDeleteName);
2117
		assertNull(directoryToDelete);
2118
		
2119
		//Now, delete some files and folder inside the a virtual folder.
2120
		parentForFileToDelete = (IRemoteFile)getChildFromFolder(parentForDirectoryToDelete, "model");
2121
		deleteFileName = "DE.java";
2122
		fileToToDelete = (IRemoteFile)getChildFromFolder(parentForFileToDelete, deleteFileName);
2123
		assertNotNull(fileToToDelete);
2124
		
2125
		fss.delete(fileToToDelete, mon);
2126
		
2127
		//check the result
2128
		fileToToDelete = (IRemoteFile)getChildFromFolder(parentForFileToDelete, deleteFileName);
2129
		
2130
		assertNull(fileToToDelete);
2131
	}
2132
2133
2134
2135
	public void testCopyBatchToTarArchiveFile() throws Exception {
2136
		//-test-author-:XuanChen
2137
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
2138
		
2139
		createSourceTarFiles();
2140
		createSourceFolders();
2141
		
2142
		String tarTargetFileName = tarSourceFileName1;
2143
		IRemoteFile targetTarFile = (IRemoteFile)getChildFromFolder(tempDir, tarTargetFileName);
2144
		assertNotNull(targetTarFile);
2145
		
2146
		//Now, copy the source folder.
2147
		String sourceFolderName = folderToCopyName3;
2148
		IRemoteFile sourceFolder = (IRemoteFile)getChildFromFolder(tempDir,sourceFolderName);
2149
		assertNotNull(sourceFolder);
2150
		
2151
		//Now, copy one of the folder from the sourceFolder into copiedTargetZipFile
2152
		IRemoteFile[] sourceFiles = new IRemoteFile[3];
2153
		//Also add some of its children into the batch.
2154
		String childToCopyName1 = "aaaaaaaa";
2155
		sourceFiles[0] = (IRemoteFile)getChildFromFolder(sourceFolder, childToCopyName1);
2156
		String childToCopyName2 = "aaaab";
2157
		sourceFiles[1] = (IRemoteFile)getChildFromFolder(sourceFolder, childToCopyName2);
2158
		String childToCopyName3 = "epdcdump01.hex12a";
2159
		sourceFiles[2] = (IRemoteFile)getChildFromFolder(sourceFolder, childToCopyName3);
2160
		fss.copyBatch(sourceFiles, targetTarFile, mon);
2161
		
2162
		//Checking the first copied folder
2163
		Object theCopiedChild = getChildFromFolder(targetTarFile, childToCopyName1);
2164
		
2165
		assertNotNull(theCopiedChild);
2166
		
2167
		//Also make sure the copied child has the right contents.
2168
		String[] childrenToCheck1 = {"adsf", "eclipse-SDK-3.3M6-win32.zip", "epdcdump01.hex12", "epdcdump01.hex12aaaa"};
2169
		
2170
		int[] typesToCheck1 = {TYPE_FILE, TYPE_FILE, TYPE_FILE, TYPE_FILE};
2171
		checkFolderContents((IRemoteFile)theCopiedChild, childrenToCheck1, typesToCheck1);
2172
		
2173
		//Checking the second copied folder
2174
		theCopiedChild = getChildFromFolder(targetTarFile, childToCopyName2);
2175
		
2176
		assertNotNull(theCopiedChild);
2177
		
2178
		//Also make sure the copied child has the right contents.
2179
		String[] childrenToCheck2 = {"features"};
2180
		
2181
		int[] typesToCheck2 = {TYPE_FOLDER};
2182
		checkFolderContents((IRemoteFile)theCopiedChild, childrenToCheck2, typesToCheck2);
2183
		
2184
		//Checking the third copied file
2185
		theCopiedChild = getChildFromFolder(targetTarFile, childToCopyName3);
2186
		assertNotNull(theCopiedChild);
2187
		assertTrue(((IRemoteFile)theCopiedChild).isDirectory() != true);
2188
	}
2189
2190
1370
2191
1371
2192
	public void testCopyBatchToTarVirtualFileLevelFour() throws Exception {
1372
	public void testCopyBatchToTarVirtualFileLevelFour() throws Exception {
Lines 2311-2380 Link Here
2311
		Object copiedVirtualFolder3 = getChildFromFolder(folder1, thirdToCopyName);
1491
		Object copiedVirtualFolder3 = getChildFromFolder(folder1, thirdToCopyName);
2312
		assertNotNull(copiedVirtualFolder3);
1492
		assertNotNull(copiedVirtualFolder3);
2313
	}
1493
	}
2314
	
2315
2316
2317
2318
	
2319
	
2320
	public void testOpenFileFromTarArchive() throws Exception {
2321
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
2322
		
2323
		//create the source for testing first
2324
		createTarSourceForOpen();
2325
		
2326
		String tarTargetFileName = tarSourceForOpenTest;
2327
		IRemoteFile targetTarFile = (IRemoteFile)getChildFromFolder(tempDir, tarTargetFileName);
2328
		assertNotNull(targetTarFile);
2329
		
2330
		//Now get the contents of the virtual file we want to download:
2331
		String fileContentToVerifyName1 = "MANIFEST.MF";
2332
		
2333
		//Get its parent first.
2334
		IRemoteFile itsParentFolder = (IRemoteFile)getChildFromFolder(tempDir,tarSourceForOpenFolderName1);
2335
		assertNotNull(itsParentFolder);
2336
		
2337
		//Then get this file:
2338
		IRemoteFile thisVirtualFile = (IRemoteFile)getChildFromFolder(itsParentFolder, fileContentToVerifyName1);
2339
		assertNotNull(thisVirtualFile);
2340
		
2341
		//Now, we want to download the content of this file
2342
		//We could just construct a dummy localpath for it.
2343
		String tempPath = getWorkspace().getRoot().getLocation().append("temp").toString();
2344
		IFileStore temp = createDir(tempPath, true);
2345
		String localPath = tempPath + "\\" + fileContentToVerifyName1;
2346
		fss.download(thisVirtualFile, localPath, thisVirtualFile.getEncoding(), mon);
2347
		
2348
		//now, verify the content of the local file
2349
		IFileStore localFile = temp.getChild(fileContentToVerifyName1);
2350
		//Check the content of the download file:
2351
		boolean sameContent = compareContent(getContents(fileContentString1), localFile.openInputStream(EFS.NONE, null));
2352
		assertTrue(sameContent);
2353
		
2354
		
2355
		//now, we got the contents of another virtual file we want to download:
2356
		String fileContentToVerifyName2 = "Activator.java";
2357
		itsParentFolder = (IRemoteFile)getChildFromFolder(tempDir,tarSourceForOpenFolderName2);
2358
		assertNotNull(itsParentFolder);
2359
		itsParentFolder = (IRemoteFile)getChildFromFolder(itsParentFolder,"eclipse");
2360
		assertNotNull(itsParentFolder);
2361
		itsParentFolder = (IRemoteFile)getChildFromFolder(itsParentFolder,"dstore");
2362
		assertNotNull(itsParentFolder);
2363
		itsParentFolder = (IRemoteFile)getChildFromFolder(itsParentFolder,"core");
2364
		assertNotNull(itsParentFolder);
2365
		thisVirtualFile = (IRemoteFile)getChildFromFolder(itsParentFolder, fileContentToVerifyName2);
2366
		assertNotNull(thisVirtualFile);
2367
		localPath = tempPath + "\\" + fileContentToVerifyName2;
2368
		fss.download(thisVirtualFile, localPath, thisVirtualFile.getEncoding(), mon);
2369
		
2370
		//now, verify the content of the local file
2371
		localFile = temp.getChild(fileContentToVerifyName2);
2372
		//Check the content of the download file:
2373
		sameContent = compareContent(getContents(fileContentString1), localFile.openInputStream(EFS.NONE, null));
2374
		assertTrue(sameContent);
2375
	}
2376
	
2377
2378
2379
1494
2380
}
1495
}
(-)src/org/eclipse/rse/tests/subsystems/files/FileServiceArchiveBaseTest.java (+938 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Wind River Systems, Inc. and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * 
8
 * Contributors: 
9
 * Xuan Chen (IBM)               - initial API and implementation
10
 * Johnson Ma       (Wind River) - [195402] Add tar.gz archive support
11
 *******************************************************************************/
12
package org.eclipse.rse.tests.subsystems.files;
13
14
import java.io.File;
15
16
import org.eclipse.core.filesystem.EFS;
17
import org.eclipse.core.filesystem.IFileStore;
18
import org.eclipse.core.resources.IWorkspace;
19
import org.eclipse.core.resources.ResourcesPlugin;
20
import org.eclipse.core.runtime.IAdaptable;
21
import org.eclipse.rse.core.model.ISystemResourceSet;
22
import org.eclipse.rse.core.model.SystemRemoteResourceSet;
23
import org.eclipse.rse.core.model.SystemWorkspaceResourceSet;
24
import org.eclipse.rse.core.subsystems.ISystemDragDropAdapter;
25
import org.eclipse.rse.files.ui.resources.UniversalFileTransferUtility;
26
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
27
import org.eclipse.rse.tests.RSETestsPlugin;
28
29
public abstract class FileServiceArchiveBaseTest extends FileServiceBaseTest {
30
31
	protected String folderToCopyName1 = "RemoteSystemsConnections";
32
	protected String folderToCopyName2 = "6YLT5Xa";
33
	protected String folderToCopyName3 = "folderToCopy";
34
	
35
	protected String tarSourceFileName1;
36
	protected String tarSourceFileName2;
37
	
38
	protected String tarSourceFolderName1 = "META-INF";
39
	protected String tarSourceFolderName2 = "org";
40
	
41
	protected String tarSourceForOpenTest;
42
	protected String tarSourceForOpenFolderName1 = "META-INF";
43
	protected String tarSourceForOpenFolderName2 = "org";
44
	
45
	protected String testName;
46
	
47
	protected String fileContentString1 = "this is just some dummy content \n to a remote file \n to test an open operation";
48
	
49
	public static IWorkspace getWorkspace() {
50
		return ResourcesPlugin.getWorkspace();
51
	}
52
	
53
	public void createSourceFolders() throws Exception
54
	{
55
		String tempPath = getWorkspace().getRoot().getLocation().append("temp").toString();
56
		IFileStore temp = createDir(tempPath, true);
57
		String content = getRandomString();
58
		
59
		// create the source folder used for copy or move
60
		IFileStore folderToCopy = temp.getChild(folderToCopyName3);
61
		createDir(folderToCopy, true);
62
		//Now, populate the contents in the folderToCopy.
63
		IFileStore aaaaaaaa = folderToCopy.getChild("aaaaaaaa");
64
		createDir(aaaaaaaa, true);
65
		//create file inside the aaaaaaaa folder.
66
		IFileStore adsf = aaaaaaaa.getChild("adsf");
67
		content = getRandomString();
68
		createFile(adsf, content);
69
		IFileStore eclipse_SDK_3_3M6_win32_zip = aaaaaaaa.getChild("eclipse-SDK-3.3M6-win32.zip");
70
		createFile(eclipse_SDK_3_3M6_win32_zip, "");
71
		IFileStore epdcdump01_hex12 = aaaaaaaa.getChild("epdcdump01.hex12");
72
		content = getRandomString();
73
		createFile(epdcdump01_hex12, content);
74
		IFileStore epdcdump01_hex12aaaa = aaaaaaaa.getChild("epdcdump01.hex12aaaa");
75
		content = getRandomString();
76
		createFile(epdcdump01_hex12aaaa, content);
77
		
78
		IFileStore aaaab = folderToCopy.getChild("aaaab");
79
		createDir(aaaab, true);
80
		IFileStore features = aaaab.getChild("features");
81
		createDir(features, true);
82
		IFileStore dummyFile = features.getChild("dummy.txt");
83
		content = getRandomString();
84
		createFile(dummyFile, content);
85
		//create file inside the aaaab folder.
86
		content = "this is just a simple content \n to a simple file \n to test a 'simple' copy";
87
		IFileStore epdcdump01_hex12a = aaaab.getChild("epdcdump01.hex12a");
88
		content = getRandomString();
89
		createFile(epdcdump01_hex12a, content);
90
		
91
		IFileStore epdcdump01_hex12a1 = folderToCopy.getChild("epdcdump01.hex12a");
92
		content = getRandomString();
93
		createFile(epdcdump01_hex12a1, content);
94
		
95
		IFileStore RSE_SDK_2_0RC1_zip = folderToCopy.getChild("RSE-SDK-2.0RC1.zip");
96
		content = getRandomString();
97
		createFile(RSE_SDK_2_0RC1_zip, content);
98
		
99
		//now, copy folderToCopy into the folder in the remote system
100
		IRemoteFile sourceFolderToCopy3 = localFss.getRemoteFileObject(tempPath + '\\' + folderToCopyName3, mon);
101
		ISystemDragDropAdapter srcAdapter3 = (ISystemDragDropAdapter) ((IAdaptable) sourceFolderToCopy3).getAdapter(ISystemDragDropAdapter.class);
102
		SystemRemoteResourceSet fromSet3 = new SystemRemoteResourceSet(localFss, srcAdapter3);
103
		fromSet3.addResource(sourceFolderToCopy3);
104
		ISystemResourceSet tempObjects3 = srcAdapter3.doDrag(fromSet3, mon);
105
		UniversalFileTransferUtility.uploadResourcesFromWorkspace((SystemWorkspaceResourceSet)tempObjects3, tempDir, mon, true);
106
		
107
		//Then, we need to retrieve children of the tempDir to cache their information.
108
		fss.resolveFilterString(tempDir, null, mon);
109
		
110
		//Then, delete the temp folder in the junit workspace.
111
		temp.delete(EFS.NONE, mon);
112
	}
113
	
114
115
	protected void createSuperTransferFolder(IFileStore temp) throws Exception 
116
	{
117
		
118
		String content = getRandomString();
119
		
120
		// create the source folder used for copy or move
121
		IFileStore folderToCopy = temp.getChild(folderToCopyName3);
122
		createDir(folderToCopy, true);
123
		//Now, populate the contents in the folderToCopy.
124
		IFileStore aaaaaaaa = folderToCopy.getChild("aaaaaaaa");
125
		createDir(aaaaaaaa, true);
126
		//create file inside the aaaaaaaa folder.
127
		IFileStore adsf = aaaaaaaa.getChild("adsf");
128
		content = getRandomString();
129
		createFile(adsf, content);
130
		IFileStore eclipse_SDK_3_3M6_win32_zip = aaaaaaaa.getChild("eclipse-SDK-3.3M6-win32.zip");
131
		createFile(eclipse_SDK_3_3M6_win32_zip, "");
132
		IFileStore epdcdump01_hex12 = aaaaaaaa.getChild("epdcdump01.hex12");
133
		content = getRandomString();
134
		createFile(epdcdump01_hex12, content);
135
		IFileStore epdcdump01_hex12aaaa = aaaaaaaa.getChild("epdcdump01.hex12aaaa");
136
		content = getRandomString();
137
		createFile(epdcdump01_hex12aaaa, content);
138
		
139
		IFileStore aaaab = folderToCopy.getChild("aaaab");
140
		createDir(aaaab, true);
141
		IFileStore features = aaaab.getChild("features");
142
		createDir(features, true);
143
		IFileStore dummyFile = features.getChild("dummy.txt");
144
		content = getRandomString();
145
		createFile(dummyFile, content);
146
		//create file inside the aaaab folder.
147
		content = "this is just a simple content \n to a simple file \n to test a 'simple' copy";
148
		IFileStore epdcdump01_hex12a = aaaab.getChild("epdcdump01.hex12a");
149
		content = getRandomString();
150
		createFile(epdcdump01_hex12a, content);
151
		
152
		IFileStore epdcdump01_hex12a1 = folderToCopy.getChild("epdcdump01.hex12a");
153
		content = getRandomString();
154
		createFile(epdcdump01_hex12a1, content);
155
		
156
		IFileStore RSE_SDK_2_0RC1_zip = folderToCopy.getChild("RSE-SDK-2.0RC1.zip");
157
		content = getRandomString();
158
		createFile(RSE_SDK_2_0RC1_zip, content);
159
		
160
		return;
161
162
	}
163
	
164
	public void createTarSourceForOpen() throws Exception
165
	{
166
		String tempPath = getWorkspace().getRoot().getLocation().append("temp").toString();
167
		IFileStore temp = createDir(tempPath, true);
168
		String content = getRandomString();
169
		
170
		//Now, we need to construct a "source.tar" archive file
171
		//We will construct the content of the tar file in folders "META-INF" and "org"
172
		//Then we copy this folder into a tar file by RSE API.
173
		IFileStore META_INF = temp.getChild(tarSourceForOpenFolderName1);
174
		createDir(META_INF, true);
175
		//Now, populate the contents in the folder.
176
		IFileStore MANIFEST_MF = META_INF.getChild("MANIFEST.MF");
177
		content = fileContentString1;
178
		createFile(MANIFEST_MF, content);
179
		
180
		//create folder "org"
181
		IFileStore org = temp.getChild("org");
182
		createDir(org, true);
183
		IFileStore eclipse = org.getChild("eclipse");
184
		createDir(eclipse, true);
185
		//create "dstore" folder inside "org"
186
		IFileStore dstore = eclipse.getChild("dstore");
187
		createDir(dstore, true);
188
		//Now, create a few folders inside the dstore folder.
189
		IFileStore core = dstore.getChild("core");
190
		createDir(core, true);
191
		IFileStore internal = dstore.getChild("internal");
192
		createDir(internal, true);
193
		
194
		//now create directory inside "core":
195
		IFileStore client = core.getChild("client");
196
		createDir(client, true);
197
		IFileStore java = core.getChild("java");
198
		createDir(java, true);
199
		IFileStore miners = core.getChild("miners");
200
		createDir(miners, true);
201
		IFileStore model = core.getChild("model");
202
		createDir(model, true);
203
		IFileStore server = core.getChild("server");
204
		createDir(server, true);
205
		IFileStore util = core.getChild("util");
206
		createDir(util, true);
207
		IFileStore Activator_java = core.getChild("Activator.java");
208
		content = fileContentString1;
209
		createFile(Activator_java, content);
210
		
211
		//now, some contents on client folder
212
		IFileStore ClientConnection_java = client.getChild("ClientConnection.java");
213
		content = getRandomString();
214
		createFile(ClientConnection_java, content);
215
		IFileStore ConnectionStatus_java = client.getChild("ConnectionStatus.java");
216
		content = fileContentString1;
217
		createFile(ConnectionStatus_java, content);
218
		
219
		//now, some contents in java folder
220
		IFileStore ClassByteStreamHandler$ReceiveClassInstanceThread_java = java.getChild("ClassByteStreamHandler$ReceiveClassInstanceThread.java");
221
		content = getRandomString();
222
		createFile(ClassByteStreamHandler$ReceiveClassInstanceThread_java, content);
223
		
224
		//now, some contents in miners folder
225
		IFileStore Miner_java = miners.getChild("Miner.java");
226
		content = getRandomString();
227
		createFile(Miner_java, content);
228
		IFileStore MinerThread_java = miners.getChild("MinerThread.java");
229
		content = getRandomString();
230
		createFile(MinerThread_java, content);
231
		
232
		//now, some contents in model folder
233
		IFileStore ByteStreamHandler_java = model.getChild("ByteStreamHandler.java");
234
		content = getRandomString();
235
		createFile(ByteStreamHandler_java, content);
236
		IFileStore DE_java = model.getChild("DE.java");
237
		content = getRandomString();
238
		createFile(DE_java, content);
239
		IFileStore Handler_java = model.getChild("Handler.java");
240
		content = getRandomString();
241
		createFile(Handler_java, content);
242
		
243
		//now, some contents in server folder
244
		IFileStore Server_java = server.getChild("Server.java");
245
		content = getRandomString();
246
		createFile(Server_java, content);
247
		
248
		//now, some contents in util folder
249
		IFileStore StringCompare_java = util.getChild("StringCompare.java");
250
		content = fileContentString1;
251
		createFile(StringCompare_java, content);
252
		
253
		//now, create the contents in "internal" folder
254
		IFileStore core1 = internal.getChild("core");
255
		createDir(core1, true);
256
		
257
		//then create some folder in this "core" folder
258
		IFileStore client1 = core1.getChild("client");
259
		createDir(client1, true);
260
		IFileStore model1 = core1.getChild("model");
261
		createDir(model1, true);
262
		IFileStore server1 = core1.getChild("server");
263
		createDir(server1, true);
264
		IFileStore util1 = core1.getChild("util");
265
		createDir(util1, true);
266
		
267
		//now, some contents on client folder
268
		IFileStore ClientConnection_java1 = client1.getChild("ClientConnection.java");
269
		content = getRandomString();
270
		createFile(ClientConnection_java1, content);
271
		IFileStore ConnectionStatus_java1 = client1.getChild("ConnectionStatus.java");
272
		content = getRandomString();
273
		createFile(ConnectionStatus_java1, content);
274
		
275
		
276
		//now, some contents in model folder
277
		IFileStore ByteStreamHandler_java1 = model1.getChild("ByteStreamHandler.java");
278
		content = getRandomString();
279
		createFile(ByteStreamHandler_java1, content);
280
		IFileStore DE_java1 = model1.getChild("DE.java");
281
		content = getRandomString();
282
		createFile(DE_java1, content);
283
		IFileStore Handler_java1 = model1.getChild("Handler.java");
284
		content = getRandomString();
285
		createFile(Handler_java1, content);
286
		
287
		//now, some contents in server folder
288
		IFileStore Server_java1 = server1.getChild("Server.java");
289
		content = getRandomString();
290
		createFile(Server_java1, content);
291
		
292
		//now, some contents in util folder
293
		IFileStore StringCompare_java1 = util1.getChild("StringCompare.java");
294
		content = getRandomString();
295
		createFile(StringCompare_java1, content);
296
		
297
		//now, copy META_INF into the folder in the remote system
298
		IRemoteFile META_INF_folder = localFss.getRemoteFileObject(tempPath + '\\' + tarSourceForOpenFolderName1, mon);
299
		assertNotNull(META_INF_folder);
300
		ISystemDragDropAdapter srcAdapter1 = (ISystemDragDropAdapter) ((IAdaptable) META_INF_folder).getAdapter(ISystemDragDropAdapter.class);
301
		SystemRemoteResourceSet fromSet = new SystemRemoteResourceSet(localFss, srcAdapter1);
302
		fromSet.addResource(META_INF_folder);
303
		ISystemResourceSet tempObjects1 = srcAdapter1.doDrag(fromSet, mon);
304
		UniversalFileTransferUtility.uploadResourcesFromWorkspace((SystemWorkspaceResourceSet)tempObjects1, tempDir, mon, true);
305
		
306
		//now, copy org into the folder in the remote system
307
		IRemoteFile org_folder = localFss.getRemoteFileObject(tempPath + '\\' + tarSourceForOpenFolderName2, mon);
308
		assertNotNull(org_folder);
309
		ISystemDragDropAdapter srcAdapter2 = (ISystemDragDropAdapter) ((IAdaptable) org_folder).getAdapter(ISystemDragDropAdapter.class);
310
		SystemRemoteResourceSet fromSet2 = new SystemRemoteResourceSet(localFss, srcAdapter2);
311
		fromSet2.addResource(org_folder);
312
		ISystemResourceSet tempObjects2 = srcAdapter2.doDrag(fromSet2, mon);
313
		UniversalFileTransferUtility.uploadResourcesFromWorkspace((SystemWorkspaceResourceSet)tempObjects2, tempDir, mon, true);
314
		
315
		//now, create tar file in the host
316
		IRemoteFile tarSource = createFileOrFolder(tempDir.getAbsolutePath(), tarSourceForOpenTest, false);
317
		assertNotNull(tarSource);
318
		IRemoteFile tarSourceFolder1 = (IRemoteFile)getChildFromFolder(tempDir, tarSourceForOpenFolderName1); 
319
		assertNotNull(tarSourceFolder1);
320
		IRemoteFile tarSourceFolder2 = (IRemoteFile)getChildFromFolder(tempDir, tarSourceForOpenFolderName2);
321
		fss.copy(tarSourceFolder1, tarSource, tarSourceForOpenFolderName1, mon);
322
		fss.copy(tarSourceFolder2, tarSource, tarSourceForOpenFolderName2, mon);
323
		
324
		//Then, we need to retrieve children of the tempDir to cache their information.
325
		fss.resolveFilterString(tempDir, null, mon);
326
		
327
		//Then, delete the temp folder in the junit workspace.
328
		temp.delete(EFS.NONE, mon);
329
	}
330
	
331
	
332
	
333
	public void createSourceTarFiles() throws Exception
334
	{
335
		String tempPath = getWorkspace().getRoot().getLocation().append("temp").toString();
336
		IFileStore temp = createDir(tempPath, true);
337
		String content = getRandomString();
338
		
339
		//Now, we need to construct a "source.tar" archive file
340
		//We will construct the content of the tar file in folders "META-INF" and "org"
341
		//Then we copy this folder into a tar file by RSE API.
342
		IFileStore META_INF = temp.getChild(tarSourceFolderName1);
343
		createDir(META_INF, true);
344
		//Now, populate the contents in the folder.
345
		IFileStore MANIFEST_MF = META_INF.getChild("MANIFEST.MF");
346
		content = getRandomString();
347
		createFile(MANIFEST_MF, content);
348
		//create folder "org"
349
		IFileStore org = temp.getChild(tarSourceFolderName2);
350
		createDir(org, true);
351
		IFileStore eclipse = org.getChild("eclipse");
352
		createDir(eclipse, true);
353
		//create "dstore" folder inside "org"
354
		IFileStore dstore = eclipse.getChild("dstore");
355
		createDir(dstore, true);
356
		//Now, create a few folders inside the dstore folder.
357
		IFileStore core = dstore.getChild("core");
358
		createDir(core, true);
359
		IFileStore internal = dstore.getChild("internal");
360
		createDir(internal, true);
361
		
362
		//now create directory inside "core":
363
		IFileStore client = core.getChild("client");
364
		createDir(client, true);
365
		IFileStore java = core.getChild("java");
366
		createDir(java, true);
367
		IFileStore miners = core.getChild("miners");
368
		createDir(miners, true);
369
		IFileStore model = core.getChild("model");
370
		createDir(model, true);
371
		IFileStore server = core.getChild("server");
372
		createDir(server, true);
373
		IFileStore util = core.getChild("util");
374
		createDir(util, true);
375
		IFileStore Activator_java = core.getChild("Activator.java");
376
		content = getRandomString();
377
		createFile(Activator_java, content);
378
		
379
		//now, some contents on client folder
380
		IFileStore ClientConnection_java = client.getChild("ClientConnection.java");
381
		content = getRandomString();
382
		createFile(ClientConnection_java, content);
383
		IFileStore ConnectionStatus_java = client.getChild("ConnectionStatus.java");
384
		content = getRandomString();
385
		createFile(ConnectionStatus_java, content);
386
		
387
		//now, some contents in java folder
388
		IFileStore ClassByteStreamHandler$ReceiveClassInstanceThread_java = java.getChild("ClassByteStreamHandler$ReceiveClassInstanceThread.java");
389
		content = getRandomString();
390
		createFile(ClassByteStreamHandler$ReceiveClassInstanceThread_java, content);
391
		
392
		//now, some contents in miners folder
393
		IFileStore Miner_java = miners.getChild("Miner.java");
394
		content = getRandomString();
395
		createFile(Miner_java, content);
396
		IFileStore MinerThread_java = miners.getChild("MinerThread.java");
397
		content = getRandomString();
398
		createFile(MinerThread_java, content);
399
		
400
		//now, some contents in model folder
401
		IFileStore ByteStreamHandler_java = model.getChild("ByteStreamHandler.java");
402
		content = getRandomString();
403
		createFile(ByteStreamHandler_java, content);
404
		IFileStore DE_java = model.getChild("DE.java");
405
		content = getRandomString();
406
		createFile(DE_java, content);
407
		IFileStore Handler_java = model.getChild("Handler.java");
408
		content = getRandomString();
409
		createFile(Handler_java, content);
410
		
411
		//now, some contents in server folder
412
		IFileStore Server_java = server.getChild("Server.java");
413
		content = getRandomString();
414
		createFile(Server_java, content);
415
		
416
		//now, some contents in util folder
417
		IFileStore StringCompare_java = util.getChild("StringCompare.java");
418
		content = getRandomString();
419
		createFile(StringCompare_java, content);
420
		
421
		//now, create the contents in "internal" folder
422
		IFileStore core1 = internal.getChild("core");
423
		createDir(core1, true);
424
		
425
		//then create some folder in this "core" folder
426
		IFileStore client1 = core1.getChild("client");
427
		createDir(client1, true);
428
		IFileStore model1 = core1.getChild("model");
429
		createDir(model1, true);
430
		IFileStore server1 = core1.getChild("server");
431
		createDir(server1, true);
432
		IFileStore util1 = core1.getChild("util");
433
		createDir(util1, true);
434
		
435
		//now, some contents on client folder
436
		IFileStore ClientConnection_java1 = client1.getChild("ClientConnection.java");
437
		content = getRandomString();
438
		createFile(ClientConnection_java1, content);
439
		IFileStore ConnectionStatus_java1 = client1.getChild("ConnectionStatus.java");
440
		content = getRandomString();
441
		createFile(ConnectionStatus_java1, content);
442
		
443
		
444
		//now, some contents in model folder
445
		IFileStore ByteStreamHandler_java1 = model1.getChild("ByteStreamHandler.java");
446
		content = getRandomString();
447
		createFile(ByteStreamHandler_java1, content);
448
		IFileStore DE_java1 = model1.getChild("DE.java");
449
		content = getRandomString();
450
		createFile(DE_java1, content);
451
		IFileStore Handler_java1 = model1.getChild("Handler.java");
452
		content = getRandomString();
453
		createFile(Handler_java1, content);
454
		
455
		//now, some contents in server folder
456
		IFileStore Server_java1 = server1.getChild("Server.java");
457
		content = getRandomString();
458
		createFile(Server_java1, content);
459
		
460
		//now, some contents in util folder
461
		IFileStore StringCompare_java1 = util1.getChild("StringCompare.java");
462
		content = getRandomString();
463
		createFile(StringCompare_java1, content);
464
		
465
		//now, copy META_INF into the folder in the remote system
466
		IRemoteFile META_INF_folder = localFss.getRemoteFileObject(tempPath + '\\' + tarSourceFolderName1, mon);
467
		assertNotNull(META_INF_folder);
468
		ISystemDragDropAdapter srcAdapter1 = (ISystemDragDropAdapter) ((IAdaptable) META_INF_folder).getAdapter(ISystemDragDropAdapter.class);
469
		SystemRemoteResourceSet fromSet = new SystemRemoteResourceSet(localFss, srcAdapter1);
470
		fromSet.addResource(META_INF_folder);
471
		ISystemResourceSet tempObjects1 = srcAdapter1.doDrag(fromSet, mon);
472
		UniversalFileTransferUtility.uploadResourcesFromWorkspace((SystemWorkspaceResourceSet)tempObjects1, tempDir, mon, true);
473
		
474
		//now, copy org into the folder in the remote system
475
		IRemoteFile org_folder = localFss.getRemoteFileObject(tempPath + '\\' + tarSourceFolderName2, mon);
476
		assertNotNull(org_folder);
477
		ISystemDragDropAdapter srcAdapter2 = (ISystemDragDropAdapter) ((IAdaptable) org_folder).getAdapter(ISystemDragDropAdapter.class);
478
		SystemRemoteResourceSet fromSet2 = new SystemRemoteResourceSet(localFss, srcAdapter2);
479
		fromSet2.addResource(org_folder);
480
		ISystemResourceSet tempObjects2 = srcAdapter2.doDrag(fromSet2, mon);
481
		UniversalFileTransferUtility.uploadResourcesFromWorkspace((SystemWorkspaceResourceSet)tempObjects2, tempDir, mon, true);
482
		
483
		//now, create tar file in the host
484
		IRemoteFile tarSource = createFileOrFolder(tempDir.getAbsolutePath(), tarSourceFileName1, false);
485
		assertNotNull(tarSource);
486
		IRemoteFile tarSourceFolder1 = (IRemoteFile)getChildFromFolder(tempDir, tarSourceFolderName1); 
487
		assertNotNull(tarSourceFolder1);
488
		IRemoteFile tarSourceFolder2 = (IRemoteFile)getChildFromFolder(tempDir, tarSourceFolderName2);
489
		fss.copy(tarSourceFolder1, tarSource, tarSourceFolderName1, mon);
490
		fss.copy(tarSourceFolder2, tarSource, tarSourceFolderName2, mon);
491
	}
492
	
493
	public void testCreateTarFile() throws Exception {
494
		//-test-author-:XuanChen
495
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
496
		
497
		//Create the zip file first.
498
		IRemoteFile newArchiveFile = createFileOrFolder(tempDirPath, testName, false);
499
		assertNotNull(newArchiveFile);
500
		assertTrue(newArchiveFile.exists());
501
		assertTrue(newArchiveFile.canRead());
502
		assertTrue(newArchiveFile.canWrite());
503
		assertEquals(newArchiveFile.getName(), testName);
504
		assertEquals(newArchiveFile.getParentPath(), tempDirPath);
505
		
506
		//fss.resolveFilterString(filterString, monitor)
507
		
508
		//Now, we want to create a text file inside.
509
		String childName = "aaa.txt";
510
		IRemoteFile file1 = createFileOrFolder(newArchiveFile.getAbsolutePath(), childName, false);
511
		assertNotNull(file1);
512
		
513
		childName = "bbb.txt";
514
		IRemoteFile file2 = createFileOrFolder(newArchiveFile.getAbsolutePath(), childName, false);
515
		assertNotNull(file2);
516
		
517
		//Create a folder
518
		childName = "folder1";
519
		IRemoteFile folder1 = createFileOrFolder(newArchiveFile.getAbsolutePath(), childName, true);
520
		assertNotNull(folder1);
521
		
522
		//Now, check the contents
523
		String[] namesToCheck = {"aaa.txt", "bbb.txt", "folder1"};
524
		int[] typesToCheck = {TYPE_FILE, TYPE_FILE, TYPE_FOLDER};
525
		checkFolderContents(newArchiveFile, namesToCheck, typesToCheck);
526
		
527
		//Now, create some files inside the folder.
528
		String secondLevelChildName = "ccc.exe";
529
		IRemoteFile levelTwoChild1 = createFileOrFolder(folder1.getAbsolutePath(), secondLevelChildName, false);
530
		assertNotNull(levelTwoChild1);
531
		
532
		secondLevelChildName = "ddd.bat";
533
		IRemoteFile levelTwoChild2 = createFileOrFolder(folder1.getAbsolutePath(), secondLevelChildName, false);
534
		assertNotNull(levelTwoChild2);
535
		
536
		secondLevelChildName = "another Folder"; //folder with space
537
		IRemoteFile levelTwoChild3 = createFileOrFolder(folder1.getAbsolutePath(), secondLevelChildName, true);
538
		assertNotNull(levelTwoChild3);
539
		
540
		//Now, check the contents
541
		String[] namesToCheck1 = {"ccc.exe", "ddd.bat", "another Folder"};
542
		int[] typesToCheck1 = {TYPE_FILE, TYPE_FILE, TYPE_FOLDER};
543
		checkFolderContents(folder1, namesToCheck1, typesToCheck1);
544
	}
545
	
546
	public void testCopyToTarArchiveFile() throws Exception {
547
		//-test-author-:XuanChen
548
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
549
		
550
		//create the source for testing first
551
		createSourceTarFiles();
552
		createSourceFolders();
553
		
554
		String tarTargetFileName = tarSourceFileName1;
555
		IRemoteFile targetTarFile = (IRemoteFile)getChildFromFolder(tempDir, tarTargetFileName);
556
		assertNotNull(targetTarFile);
557
		
558
		String sourceFolderName = folderToCopyName3;
559
		IRemoteFile sourceFolder = (IRemoteFile)getChildFromFolder(tempDir, sourceFolderName);
560
		assertNotNull(sourceFolder);
561
		
562
		//Now, copy one of the folder from the sourceFolder into copiedTargetZipFile
563
		fss.copy(sourceFolder, targetTarFile, sourceFolder.getName(), mon);
564
		
565
		Object theCopiedChild = getChildFromFolder(targetTarFile, sourceFolderName);
566
		
567
		assertNotNull(theCopiedChild);
568
		
569
		//Also make sure the copied child has the right contents.
570
		String[] childrenToCheck = {"aaaaaaaa", "aaaab", "epdcdump01.hex12a", "RSE-SDK-2.0RC1.zip"};
571
		
572
		int[] typesToCheck = {TYPE_FOLDER, TYPE_FOLDER, TYPE_FILE, TYPE_FILE};
573
		checkFolderContents((IRemoteFile)theCopiedChild, childrenToCheck, typesToCheck);
574
	}
575
576
577
578
	public void testCopyTarVirtualFile() throws Exception {
579
		//-test-author-:XuanChen
580
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
581
		
582
		//create the source for testing first
583
		createSourceTarFiles();
584
		
585
		String sourceFileName = tarSourceFileName1;
586
		IRemoteFile sourceTarFile = (IRemoteFile)getChildFromFolder(tempDir, sourceFileName);
587
		assertNotNull(sourceTarFile);
588
		
589
		//then, create a folder inside the tempDir
590
		String folderName = "folder1";
591
		IRemoteFile folder1 = createFileOrFolder(tempDirPath, folderName, true);
592
		assertNotNull(folder1);
593
		
594
		//Get one of its fourth level children, and copy the folder to there.
595
		IRemoteFile firstLevelChild = (IRemoteFile)getChildFromFolder(sourceTarFile, tarSourceFolderName1);
596
		assertNotNull(firstLevelChild);
597
		
598
		fss.copy(firstLevelChild, folder1, tarSourceFolderName1, mon);
599
		
600
		Object copiedVirtualFolder = getChildFromFolder(folder1, tarSourceFolderName1);
601
		assertNotNull(copiedVirtualFolder);
602
		
603
		String[] contents = {"MANIFEST.MF"};
604
		int[] typesToCheck = {TYPE_FILE};
605
		checkFolderContents((IRemoteFile)copiedVirtualFolder, contents, typesToCheck);
606
	}
607
608
609
	public void testMoveToTarArchiveFile() throws Exception {
610
		//-test-author-:XuanChen
611
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
612
		
613
		//create the source for testing first
614
		createSourceTarFiles();
615
		createSourceFolders();
616
		
617
		String tarTargetFileName = tarSourceFileName1;
618
		IRemoteFile targetTarFile = (IRemoteFile)getChildFromFolder(tempDir, tarTargetFileName);
619
		assertNotNull(targetTarFile);
620
		
621
		String sourceFolderName = folderToCopyName3;
622
		IRemoteFile sourceFolder = (IRemoteFile)getChildFromFolder(tempDir, sourceFolderName);
623
		assertNotNull(sourceFolder);
624
		
625
		fss.move(sourceFolder, targetTarFile, sourceFolder.getName(), mon);
626
		
627
		Object theMovedChild = getChildFromFolder(targetTarFile, sourceFolderName);
628
		
629
		assertNotNull(theMovedChild);
630
		
631
		//Also make sure the copied child has the right contents.
632
		String[] childrenToCheck = {"aaaaaaaa", "aaaab", "epdcdump01.hex12a", "RSE-SDK-2.0RC1.zip"};
633
		
634
		int[] typesToCheck = {TYPE_FOLDER, TYPE_FOLDER, TYPE_FILE, TYPE_FILE};
635
		checkFolderContents((IRemoteFile)theMovedChild, childrenToCheck, typesToCheck);
636
		
637
		//make sure the original folder is gone.
638
		Object originalSource = getChildFromFolder(tempDir, sourceFolderName);
639
		assertNull(originalSource);
640
	}
641
642
643
644
	public void testMoveTarVirtualFile() throws Exception {
645
		//-test-author-:XuanChen
646
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
647
		
648
		//create the source for testing first
649
		createSourceTarFiles();
650
		
651
		String sourceFileName = tarSourceFileName1;
652
		IRemoteFile sourceTarFile = (IRemoteFile)getChildFromFolder(tempDir, sourceFileName);
653
		assertNotNull(sourceTarFile);
654
		
655
		//then, create a folder inside the tempDir
656
		//then, create a folder inside the tempDir
657
		String folderName = "folder1";
658
		IRemoteFile folder1 = createFileOrFolder(tempDirPath, folderName, true);
659
		assertNotNull(folder1);
660
		
661
		//Now, copy one of the folder from the zip file into folder1
662
		String movedFolderName = tarSourceFolderName1;
663
		IRemoteFile firstLevelChild = (IRemoteFile)getChildFromFolder(sourceTarFile, tarSourceFolderName1);
664
		assertNotNull(firstLevelChild);
665
		fss.move(firstLevelChild, folder1, movedFolderName, mon);
666
		
667
		Object movedVirtualFolder = getChildFromFolder(folder1, movedFolderName);
668
		
669
		assertNotNull(movedVirtualFolder);
670
		
671
		String[] contents = {"MANIFEST.MF"};
672
		int[] typesToCheck = {TYPE_FILE};
673
		checkFolderContents((IRemoteFile)movedVirtualFolder, contents, typesToCheck);
674
		
675
		//Now, make sure the moved virtual folder is gone from its original zip file
676
		IRemoteFile tmp = (IRemoteFile)getChildFromFolder(sourceTarFile, tarSourceFolderName1);
677
		assertNull(tmp);
678
	}
679
680
681
	public void testRenameTarVirtualFile() throws Exception {
682
		//-test-author-:XuanChen
683
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
684
		
685
		//Create the zip file first.
686
		IRemoteFile newArchiveFile = createFileOrFolder(tempDirPath, testName, false);
687
		
688
		//Now, we want to create a text file inside.
689
		String childName = "aaa.txt";
690
		IRemoteFile file1 = createFileOrFolder(newArchiveFile.getAbsolutePath(), childName, false);
691
		assertNotNull(file1);
692
		
693
		childName = "bbb.txt";
694
		IRemoteFile file2 = createFileOrFolder(newArchiveFile.getAbsolutePath(), childName, false);
695
		assertNotNull(file2);
696
		
697
		//Create a folder
698
		childName = "folder1";
699
		IRemoteFile folder1 = createFileOrFolder(newArchiveFile.getAbsolutePath(), childName, true);
700
		assertNotNull(folder1);
701
		
702
		//Now, check the contents
703
		String[] levelOneNamesToCheck = {"aaa.txt", "bbb.txt", "folder1"};
704
		int[] levalOneTypesToCheck = {TYPE_FILE, TYPE_FILE, TYPE_FOLDER};
705
		checkFolderContents(newArchiveFile, levelOneNamesToCheck, levalOneTypesToCheck);
706
		
707
		//Now, create some files inside the folder.
708
		String secondLevelChildName = "ccc.exe";
709
		IRemoteFile levelTwoChild1 = createFileOrFolder(folder1.getAbsolutePath(), secondLevelChildName, false);
710
		assertNotNull(levelTwoChild1);
711
		
712
		secondLevelChildName = "ddd.bat";
713
		IRemoteFile levelTwoChild2 = createFileOrFolder(folder1.getAbsolutePath(), secondLevelChildName, false);
714
		assertNotNull(levelTwoChild2);
715
		
716
		secondLevelChildName = "another Folder"; //folder with space
717
		IRemoteFile levelTwoChild3 = createFileOrFolder(folder1.getAbsolutePath(), secondLevelChildName, true);
718
		assertNotNull(levelTwoChild3);
719
		
720
		//Now, check the contents
721
		String[] levelTwoNamesToCheck = {"ccc.exe", "ddd.bat", "another Folder"};
722
		int[] levalTwoTypesToCheck = {TYPE_FILE, TYPE_FILE, TYPE_FOLDER};
723
		checkFolderContents(folder1, levelTwoNamesToCheck, levalTwoTypesToCheck);
724
		
725
		//Now rename one of the text file in the first level:
726
		IRemoteFile childToRename = (IRemoteFile)getChildFromFolder(newArchiveFile, "aaa.txt");
727
		fss.rename(childToRename, "aaa1.txt", mon);
728
		//Now rename one of the folder in the first level
729
		childToRename = (IRemoteFile)getChildFromFolder(newArchiveFile, "folder1");
730
		fss.rename(childToRename, "folder2", mon);
731
		
732
		//Check the result of rename
733
		String[] newLevelOneNamesToCheck = {"aaa1.txt", "bbb.txt", "folder2"};
734
		checkFolderContents(newArchiveFile, newLevelOneNamesToCheck, levalOneTypesToCheck);
735
		
736
		//Now rename one of the text file in the second level:
737
		IRemoteFile thisFolder = (IRemoteFile)getChildFromFolder(newArchiveFile, "folder2");
738
		childToRename = (IRemoteFile)getChildFromFolder(thisFolder, "ddd.bat");
739
		fss.rename(childToRename, "ddd1.bat", mon);
740
		//Now rename one of the folder in the second level
741
		childToRename = (IRemoteFile)getChildFromFolder(thisFolder, "another Folder");
742
		fss.rename(childToRename, "some folder$", mon);
743
		
744
		//Check the result of rename
745
		String[] newLevelTwoNamesToCheck = {"ccc.exe", "ddd1.bat", "some folder$"};
746
		checkFolderContents(thisFolder, newLevelTwoNamesToCheck, levalTwoTypesToCheck);
747
	}
748
749
	public void testDeleteTarVirtualFile() throws Exception {
750
		//-test-author-:XuanChen
751
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
752
		
753
		//create the source for testing first
754
		createSourceTarFiles();
755
		
756
		String sourceFileName = tarSourceFileName1;
757
		IRemoteFile sourceTarFile = (IRemoteFile)getChildFromFolder(tempDir, sourceFileName);
758
		assertNotNull(sourceTarFile);
759
		
760
		//delete a file from level 2
761
		String parentForFileToDeleteName ="META-INF";
762
		IRemoteFile parentForFileToDelete = (IRemoteFile)getChildFromFolder(sourceTarFile, parentForFileToDeleteName);
763
		assertNotNull(parentForFileToDelete);
764
		String deleteFileName = "MANIFEST.MF";
765
		IRemoteFile fileToToDelete = (IRemoteFile)getChildFromFolder(parentForFileToDelete, deleteFileName);
766
		assertNotNull(fileToToDelete);
767
		//Now, delete this file
768
		fss.delete(fileToToDelete, mon);
769
		fileToToDelete = (IRemoteFile)getChildFromFolder(parentForFileToDelete, deleteFileName);
770
		assertNull(fileToToDelete);
771
		
772
		//then, get directory "java" under org/eclipse/dstore/core
773
		String parentForDirectoryToDeleteName ="org";
774
		IRemoteFile parentForDirectoryToDelete = (IRemoteFile)getChildFromFolder(sourceTarFile, parentForDirectoryToDeleteName);
775
		assertNotNull(parentForDirectoryToDelete);
776
		
777
		parentForDirectoryToDeleteName ="eclipse";
778
		parentForDirectoryToDelete = (IRemoteFile)getChildFromFolder(parentForDirectoryToDelete, parentForDirectoryToDeleteName);
779
		assertNotNull(parentForDirectoryToDelete);
780
		
781
		parentForDirectoryToDeleteName ="dstore";
782
		parentForDirectoryToDelete = (IRemoteFile)getChildFromFolder(parentForDirectoryToDelete, parentForDirectoryToDeleteName);
783
		assertNotNull(parentForDirectoryToDelete);
784
		
785
		parentForDirectoryToDeleteName ="core";
786
		parentForDirectoryToDelete = (IRemoteFile)getChildFromFolder(parentForDirectoryToDelete, parentForDirectoryToDeleteName);
787
		assertNotNull(parentForDirectoryToDelete);
788
		
789
		String directoryToDeleteName = "java";
790
		IRemoteFile directoryToDelete = (IRemoteFile)getChildFromFolder(parentForDirectoryToDelete, directoryToDeleteName);
791
		//Now, delete this directory
792
		fss.delete(directoryToDelete, mon);
793
		directoryToDelete = (IRemoteFile)getChildFromFolder(parentForDirectoryToDelete, directoryToDeleteName);
794
		
795
		//check result of this operation
796
		String[] contents = {"client", "miners", "model", "server", "util", "Activator.java"};
797
		int[] typesToCheck = {TYPE_FOLDER, TYPE_FOLDER, TYPE_FOLDER, TYPE_FOLDER, TYPE_FOLDER, TYPE_FILE};
798
		checkFolderContents(parentForDirectoryToDelete, contents, typesToCheck);
799
		
800
		//And check this directory is not there any more.
801
		directoryToDelete = (IRemoteFile)getChildFromFolder(parentForDirectoryToDelete, directoryToDeleteName);
802
		assertNull(directoryToDelete);
803
		
804
		//Now, delete some files and folder inside the a virtual folder.
805
		parentForFileToDelete = (IRemoteFile)getChildFromFolder(parentForDirectoryToDelete, "model");
806
		deleteFileName = "DE.java";
807
		fileToToDelete = (IRemoteFile)getChildFromFolder(parentForFileToDelete, deleteFileName);
808
		assertNotNull(fileToToDelete);
809
		
810
		fss.delete(fileToToDelete, mon);
811
		
812
		//check the result
813
		fileToToDelete = (IRemoteFile)getChildFromFolder(parentForFileToDelete, deleteFileName);
814
		
815
		assertNull(fileToToDelete);
816
	}
817
818
819
820
	public void testCopyBatchToTarArchiveFile() throws Exception {
821
		//-test-author-:XuanChen
822
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
823
		
824
		createSourceTarFiles();
825
		createSourceFolders();
826
		
827
		String tarTargetFileName = tarSourceFileName1;
828
		IRemoteFile targetTarFile = (IRemoteFile)getChildFromFolder(tempDir, tarTargetFileName);
829
		assertNotNull(targetTarFile);
830
		
831
		//Now, copy the source folder.
832
		String sourceFolderName = folderToCopyName3;
833
		IRemoteFile sourceFolder = (IRemoteFile)getChildFromFolder(tempDir,sourceFolderName);
834
		assertNotNull(sourceFolder);
835
		
836
		//Now, copy one of the folder from the sourceFolder into copiedTargetZipFile
837
		IRemoteFile[] sourceFiles = new IRemoteFile[3];
838
		//Also add some of its children into the batch.
839
		String childToCopyName1 = "aaaaaaaa";
840
		sourceFiles[0] = (IRemoteFile)getChildFromFolder(sourceFolder, childToCopyName1);
841
		String childToCopyName2 = "aaaab";
842
		sourceFiles[1] = (IRemoteFile)getChildFromFolder(sourceFolder, childToCopyName2);
843
		String childToCopyName3 = "epdcdump01.hex12a";
844
		sourceFiles[2] = (IRemoteFile)getChildFromFolder(sourceFolder, childToCopyName3);
845
		fss.copyBatch(sourceFiles, targetTarFile, mon);
846
		
847
		//Checking the first copied folder
848
		Object theCopiedChild = getChildFromFolder(targetTarFile, childToCopyName1);
849
		
850
		assertNotNull(theCopiedChild);
851
		
852
		//Also make sure the copied child has the right contents.
853
		String[] childrenToCheck1 = {"adsf", "eclipse-SDK-3.3M6-win32.zip", "epdcdump01.hex12", "epdcdump01.hex12aaaa"};
854
		
855
		int[] typesToCheck1 = {TYPE_FILE, TYPE_FILE, TYPE_FILE, TYPE_FILE};
856
		checkFolderContents((IRemoteFile)theCopiedChild, childrenToCheck1, typesToCheck1);
857
		
858
		//Checking the second copied folder
859
		theCopiedChild = getChildFromFolder(targetTarFile, childToCopyName2);
860
		
861
		assertNotNull(theCopiedChild);
862
		
863
		//Also make sure the copied child has the right contents.
864
		String[] childrenToCheck2 = {"features"};
865
		
866
		int[] typesToCheck2 = {TYPE_FOLDER};
867
		checkFolderContents((IRemoteFile)theCopiedChild, childrenToCheck2, typesToCheck2);
868
		
869
		//Checking the third copied file
870
		theCopiedChild = getChildFromFolder(targetTarFile, childToCopyName3);
871
		assertNotNull(theCopiedChild);
872
		assertTrue(((IRemoteFile)theCopiedChild).isDirectory() != true);
873
	}
874
875
876
877
878
	public void testOpenFileFromTarArchive() throws Exception {
879
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
880
		
881
		//create the source for testing first
882
		createTarSourceForOpen();
883
		
884
		String tarTargetFileName = tarSourceForOpenTest;
885
		IRemoteFile targetTarFile = (IRemoteFile)getChildFromFolder(tempDir, tarTargetFileName);
886
		assertNotNull(targetTarFile);
887
		
888
		//Now get the contents of the virtual file we want to download:
889
		String fileContentToVerifyName1 = "MANIFEST.MF";
890
		
891
		//Get its parent first.
892
		IRemoteFile itsParentFolder = (IRemoteFile)getChildFromFolder(tempDir,tarSourceForOpenFolderName1);
893
		assertNotNull(itsParentFolder);
894
		
895
		//Then get this file:
896
		IRemoteFile thisVirtualFile = (IRemoteFile)getChildFromFolder(itsParentFolder, fileContentToVerifyName1);
897
		assertNotNull(thisVirtualFile);
898
		
899
		//Now, we want to download the content of this file
900
		//We could just construct a dummy localpath for it.
901
		String tempPath = getWorkspace().getRoot().getLocation().append("temp").toString();
902
		IFileStore temp = createDir(tempPath, true);
903
		String localPath = tempPath + File.separator + fileContentToVerifyName1;
904
		fss.download(thisVirtualFile, localPath, thisVirtualFile.getEncoding(), mon);
905
		
906
		//now, verify the content of the local file
907
		IFileStore localFile = temp.getChild(fileContentToVerifyName1);
908
		//Check the content of the download file:
909
		boolean sameContent = compareContent(getContents(fileContentString1), localFile.openInputStream(EFS.NONE, null));
910
		assertTrue(sameContent);
911
		
912
		
913
		//now, we got the contents of another virtual file we want to download:
914
		String fileContentToVerifyName2 = "Activator.java";
915
		itsParentFolder = (IRemoteFile)getChildFromFolder(tempDir,tarSourceForOpenFolderName2);
916
		assertNotNull(itsParentFolder);
917
		itsParentFolder = (IRemoteFile)getChildFromFolder(itsParentFolder,"eclipse");
918
		assertNotNull(itsParentFolder);
919
		itsParentFolder = (IRemoteFile)getChildFromFolder(itsParentFolder,"dstore");
920
		assertNotNull(itsParentFolder);
921
		itsParentFolder = (IRemoteFile)getChildFromFolder(itsParentFolder,"core");
922
		assertNotNull(itsParentFolder);
923
		thisVirtualFile = (IRemoteFile)getChildFromFolder(itsParentFolder, fileContentToVerifyName2);
924
		assertNotNull(thisVirtualFile);
925
		localPath = tempPath + File.separator + fileContentToVerifyName2;
926
		fss.download(thisVirtualFile, localPath, thisVirtualFile.getEncoding(), mon);
927
		
928
		//now, verify the content of the local file
929
		localFile = temp.getChild(fileContentToVerifyName2);
930
		//Check the content of the download file:
931
		sameContent = compareContent(getContents(fileContentString1), localFile.openInputStream(EFS.NONE, null));
932
		assertTrue(sameContent);
933
	}
934
	
935
936
937
938
}
(-)src/org/eclipse/rse/tests/subsystems/files/FileServiceTgzArchiveTest.java (+25 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Wind River Systems, Inc. and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * 
8
 * Contributors: 
9
 * Johnson Ma (Wind River) - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.rse.tests.subsystems.files;
12
13
/**
14
 * this class is used to test tgz and .tar.gz archive function
15
 */
16
public class FileServiceTgzArchiveTest extends FileServiceArchiveBaseTest {
17
18
	public FileServiceTgzArchiveTest() {
19
		tarSourceFileName1 = "source.tar.gz";
20
		tarSourceFileName2 = "mynewtar.tar.gz";
21
		tarSourceForOpenTest = "tarSourceForOpen.tar.gz";
22
		testName = "dummy.tar.gz";
23
	}
24
25
}
(-)plugin.xml (-1 / +13 lines)
Lines 17-23 Link Here
17
Martin Oberhuber (Wind River) - [186748] Move ISubSystemConfigurationAdapter from UI/rse.core.subsystems.util
17
Martin Oberhuber (Wind River) - [186748] Move ISubSystemConfigurationAdapter from UI/rse.core.subsystems.util
18
David McKnight   (IBM)        - [187711] Link with Editor action for System View
18
David McKnight   (IBM)        - [187711] Link with Editor action for System View
19
David McKnight   (IBM)        - [209593] [api] add support for "file permissions" and "owner" properties for unix files
19
David McKnight   (IBM)        - [209593] [api] add support for "file permissions" and "owner" properties for unix files
20
20
Johnson Ma       (Wind River) - [195402] Add tar.gz archive support
21
-->
21
-->
22
<?eclipse version="3.0"?>
22
<?eclipse version="3.0"?>
23
<plugin>
23
<plugin>
Lines 309-314 Link Here
309
            id="org.eclipse.rse.services.clientserver.archiveutils.systemjarhandler">
309
            id="org.eclipse.rse.services.clientserver.archiveutils.systemjarhandler">
310
      </archivehandler>
310
      </archivehandler>
311
      <archivehandler
311
      <archivehandler
312
            fileNameExtension="tar.gz"
313
            name="SystemTargzHandler"
314
            class="org.eclipse.rse.internal.services.clientserver.archiveutils.SystemTgzHandler"
315
            id="org.eclipse.rse.services.clientserver.archiveutils.systemtargzhandler">
316
      </archivehandler>
317
      <archivehandler
318
            fileNameExtension="tgz"
319
            name="SystemTgzHandler"
320
            class="org.eclipse.rse.internal.services.clientserver.archiveutils.SystemTgzHandler"
321
            id="org.eclipse.rse.services.clientserver.archiveutils.systemtgzhandler">
322
      </archivehandler>
323
      <archivehandler
312
            fileNameExtension="tar"
324
            fileNameExtension="tar"
313
            name="SystemTarHandler"
325
            name="SystemTarHandler"
314
            class="org.eclipse.rse.services.clientserver.archiveutils.SystemTarHandler"
326
            class="org.eclipse.rse.services.clientserver.archiveutils.SystemTarHandler"
(-)miners/org/eclipse/rse/dstore/universal/miners/UniversalFileSystemMiner.java (+4 lines)
Lines 29-34 Link Here
29
 * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations
29
 * Xuan Chen (IBM) - [209827] Update DStore command implementation to enable cancelation of archive operations
30
 * Xuan Chen (IBM) - [194481] [dstore][Archive] Save Conflict After Renaming a File that is Open
30
 * Xuan Chen (IBM) - [194481] [dstore][Archive] Save Conflict After Renaming a File that is Open
31
 * David McKnight   (IBM)        - [209593] [api] add support for "file permissions" and "owner" properties for unix files
31
 * David McKnight   (IBM)        - [209593] [api] add support for "file permissions" and "owner" properties for unix files
32
 * Johnson Ma (Wind River) - [195402] Add tar.gz archive support
32
 *******************************************************************************/
33
 *******************************************************************************/
33
34
34
package org.eclipse.rse.dstore.universal.miners;
35
package org.eclipse.rse.dstore.universal.miners;
Lines 59-64 Link Here
59
import org.eclipse.rse.internal.dstore.universal.miners.filesystem.RenameThread;
60
import org.eclipse.rse.internal.dstore.universal.miners.filesystem.RenameThread;
60
import org.eclipse.rse.internal.dstore.universal.miners.filesystem.UniversalDownloadHandler;
61
import org.eclipse.rse.internal.dstore.universal.miners.filesystem.UniversalDownloadHandler;
61
import org.eclipse.rse.internal.dstore.universal.miners.filesystem.UniversalSearchHandler;
62
import org.eclipse.rse.internal.dstore.universal.miners.filesystem.UniversalSearchHandler;
63
import org.eclipse.rse.internal.services.clientserver.archiveutils.SystemTgzHandler;
62
import org.eclipse.rse.services.clientserver.IClientServerConstants;
64
import org.eclipse.rse.services.clientserver.IClientServerConstants;
63
import org.eclipse.rse.services.clientserver.IServiceConstants;
65
import org.eclipse.rse.services.clientserver.IServiceConstants;
64
import org.eclipse.rse.services.clientserver.PathUtility;
66
import org.eclipse.rse.services.clientserver.PathUtility;
Lines 98-103 Link Here
98
		_archiveHandlerManager = ArchiveHandlerManager.getInstance();
100
		_archiveHandlerManager = ArchiveHandlerManager.getInstance();
99
		_archiveHandlerManager.setRegisteredHandler("zip", SystemZipHandler.class); //$NON-NLS-1$
101
		_archiveHandlerManager.setRegisteredHandler("zip", SystemZipHandler.class); //$NON-NLS-1$
100
		_archiveHandlerManager.setRegisteredHandler("jar", SystemJarHandler.class); //$NON-NLS-1$
102
		_archiveHandlerManager.setRegisteredHandler("jar", SystemJarHandler.class); //$NON-NLS-1$
103
		_archiveHandlerManager.setRegisteredHandler("tar.gz", SystemTgzHandler.class); //$NON-NLS-1$
104
		_archiveHandlerManager.setRegisteredHandler("tgz", SystemTgzHandler.class); //$NON-NLS-1$
101
		_archiveHandlerManager.setRegisteredHandler("tar", SystemTarHandler.class); //$NON-NLS-1$
105
		_archiveHandlerManager.setRegisteredHandler("tar", SystemTarHandler.class); //$NON-NLS-1$
102
	}
106
	}
103
107
(-)clientserver/org/eclipse/rse/services/clientserver/archiveutils/ArchiveHandlerManager.java (-11 / +44 lines)
Lines 17-22 Link Here
17
 * Xuan Chen (IBM)        - [202949] [archives] copy a folder from one connection to an archive file in a different connection does not work
17
 * Xuan Chen (IBM)        - [202949] [archives] copy a folder from one connection to an archive file in a different connection does not work
18
 * Xuan Chen (IBM)        - [160775] [api] rename (at least within a zip) blocks UI thread
18
 * Xuan Chen (IBM)        - [160775] [api] rename (at least within a zip) blocks UI thread
19
 * Xuan Chen (IBM)        - [218491] ArchiveHandlerManager#cleanUpVirtualPath is messing up the file separators (with updated fix)
19
 * Xuan Chen (IBM)        - [218491] ArchiveHandlerManager#cleanUpVirtualPath is messing up the file separators (with updated fix)
20
 * Johnson Ma (Wind River) - [195402] [api] add tar.gz archive support
20
 *******************************************************************************/
21
 *******************************************************************************/
21
22
22
package org.eclipse.rse.services.clientserver.archiveutils;
23
package org.eclipse.rse.services.clientserver.archiveutils;
Lines 25-30 Link Here
25
import java.lang.reflect.Constructor;
26
import java.lang.reflect.Constructor;
26
import java.lang.reflect.InvocationTargetException;
27
import java.lang.reflect.InvocationTargetException;
27
import java.util.HashMap;
28
import java.util.HashMap;
29
import java.util.Iterator;
28
30
29
/**
31
/**
30
 * This class manages all the Archive Handlers that correspond to the archive file that the system
32
 * This class manages all the Archive Handlers that correspond to the archive file that the system
Lines 40-45 Link Here
40
	public static final String VIRTUAL_SEPARATOR = "#virtual#/"; //$NON-NLS-1$
42
	public static final String VIRTUAL_SEPARATOR = "#virtual#/"; //$NON-NLS-1$
41
	public static final String VIRTUAL_CANONICAL_SEPARATOR = "#virtual#"; //$NON-NLS-1$
43
	public static final String VIRTUAL_CANONICAL_SEPARATOR = "#virtual#"; //$NON-NLS-1$
42
	public static final String VIRTUAL_FOLDER_SEPARATOR = "/"; //$NON-NLS-1$
44
	public static final String VIRTUAL_FOLDER_SEPARATOR = "/"; //$NON-NLS-1$
45
	public static final String EXTENSION_SEPARATOR = "."; //$NON-NLS-1$
43
	
46
	
44
	//	the singleton instance
47
	//	the singleton instance
45
	protected static ArchiveHandlerManager _instance = new ArchiveHandlerManager(); 
48
	protected static ArchiveHandlerManager _instance = new ArchiveHandlerManager(); 
Lines 116-122 Link Here
116
		}
119
		}
117
		else
120
		else
118
		{
121
		{
119
			if (_handlerTypes.containsKey(getExtension(file)))
122
			if (getRegisteredExtension(file)!=null)
120
			{
123
			{
121
				return true;
124
				return true;
122
			}
125
			}
Lines 136-155 Link Here
136
	 */
139
	 */
137
	public boolean isRegisteredArchive(String filename)
140
	public boolean isRegisteredArchive(String filename)
138
	{
141
	{
139
		if (_handlerTypes.containsKey(getExtension(filename)))
142
		return getRegisteredExtension(filename) == null?false:true;
140
		{
143
	}	
141
			return true;
144
	
142
		}
145
	/**
143
		else
146
	 * check if the file extension is registered archive type. 
147
	 * notice here, the getExtension method does't work for name like fool.tar.gz
148
	 * @param file the file to check
149
	 * @return registered extension or null
150
	 * @since 3.0
151
	 */
152
	protected String getRegisteredExtension(File file) 
153
	{
154
		String fileName = file.getName();
155
		return getRegisteredExtension(fileName);
156
	}
157
	
158
	/**
159
	 * check if the file extension is registered archive type. 
160
	 * @param fileName the file name to check
161
	 * @return registered extension or null
162
	 * @since 3.0
163
	 */
164
	protected String getRegisteredExtension(String fileName) 
165
	{
166
		Iterator itor = _handlerTypes.keySet().iterator();
167
		while(itor.hasNext()) 
144
		{
168
		{
145
			return false;
169
			String ext = ((String)itor.next()).toLowerCase();
170
			if (fileName.endsWith(EXTENSION_SEPARATOR + ext))
171
			{
172
				return ext;
173
			} 
174
				
146
		}
175
		}
147
	}	
176
		return null;
177
	}
178
	
148
	/** 
179
	/** 
149
	 * @param file the file whose extension we are computing.
180
	 * @param file the file whose extension we are computing.
150
	 * @return the extension of <code>file</code>. "Extension" is
181
	 * @return the extension of <code>file</code>. "Extension" is
151
	 * defined as any letters in the filename after the last ".". 
182
	 * defined as any letters in the filename after the last ".". 
152
	 * Returns "" if there is no extension.
183
	 * Returns "" if there is no extension.
184
	 * @deprecated Use {@link #getRegisteredExtension(File)} instead
153
	 */
185
	 */
154
	protected String getExtension(File file)
186
	protected String getExtension(File file)
155
	{
187
	{
Lines 159-169 Link Here
159
		return filename.substring(i+1).toLowerCase();
191
		return filename.substring(i+1).toLowerCase();
160
	}
192
	}
161
	
193
	
194
	
162
	/** 
195
	/** 
163
	 * @param filename the name of the file whose extension we are computing.
196
	 * @param filename the name of the file whose extension we are computing.
164
	 * @return the extension of <code>filename</code>. "Extension" is
197
	 * @return the extension of <code>filename</code>. "Extension" is
165
	 * defined as any letters in the filename after the last ".". 
198
	 * defined as any letters in the filename after the last ".". 
166
	 * Returns "" if there is no extension.
199
	 * Returns "" if there is no extension.
200
	 * * @deprecated Use {@link #getRegisteredExtension(String)} instead
167
	 */
201
	 */
168
	protected String getExtension(String filename)
202
	protected String getExtension(String filename)
169
	{
203
	{
Lines 212-221 Link Here
212
		}
246
		}
213
		else {
247
		else {
214
			// find registered handler based on file's extension
248
			// find registered handler based on file's extension
215
			String ext = getExtension(file);
249
			String ext = getRegisteredExtension(file);
216
			if (!_handlerTypes.containsKey(ext))
250
			if (ext == null)
217
			{
251
			{
218
				//System.out.println("Unknown archive file type: " + ext);
219
				return null;
252
				return null;
220
			}
253
			}
221
			else
254
			else
(-)clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemTarHandler.java (-6 / +21 lines)
Lines 22-27 Link Here
22
 * Xuan Chen        (IBM)        - [214251] [archive] "Last Modified Time" changed for all virtual files/folders if rename/paste/delete of one virtual file.
22
 * Xuan Chen        (IBM)        - [214251] [archive] "Last Modified Time" changed for all virtual files/folders if rename/paste/delete of one virtual file.
23
 * Xuan Chen        (IBM)        - [191370] [dstore] Supertransfer zip not deleted when cancelling copy
23
 * Xuan Chen        (IBM)        - [191370] [dstore] Supertransfer zip not deleted when cancelling copy
24
 * Xuan Chen        (IBM)        - [api] SystemTarHandler has inconsistent API
24
 * Xuan Chen        (IBM)        - [api] SystemTarHandler has inconsistent API
25
 * Johnson Ma       (Wind River) - [195402][api] Add tar.gz archive support
25
 *******************************************************************************/
26
 *******************************************************************************/
26
27
27
package org.eclipse.rse.services.clientserver.archiveutils;
28
package org.eclipse.rse.services.clientserver.archiveutils;
Lines 30-35 Link Here
30
import java.io.BufferedReader;
31
import java.io.BufferedReader;
31
import java.io.File;
32
import java.io.File;
32
import java.io.FileInputStream;
33
import java.io.FileInputStream;
34
import java.io.FileNotFoundException;
33
import java.io.FileOutputStream;
35
import java.io.FileOutputStream;
34
import java.io.FilePermission;
36
import java.io.FilePermission;
35
import java.io.IOException;
37
import java.io.IOException;
Lines 1228-1234 Link Here
1228
			
1230
			
1229
					// open a new temp file which will be our destination for the new tar file
1231
					// open a new temp file which will be our destination for the new tar file
1230
					outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$
1232
					outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$
1231
					outStream = new TarOutputStream(new FileOutputStream(outputTempFile));
1233
					outStream = getTarOutputStream(outputTempFile);
1232
		
1234
		
1233
					// get all the entries in the current tar				  
1235
					// get all the entries in the current tar				  
1234
					VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor);
1236
					VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor);
Lines 1669-1675 Link Here
1669
			// open a new temp file which will be our destination for the new tar file
1671
			// open a new temp file which will be our destination for the new tar file
1670
			File outputTempFile = new File(getArchive().getAbsolutePath() + "temp"); //$NON-NLS-1$
1672
			File outputTempFile = new File(getArchive().getAbsolutePath() + "temp"); //$NON-NLS-1$
1671
			
1673
			
1672
			TarOutputStream outStream = new TarOutputStream(new FileOutputStream(outputTempFile));
1674
			TarOutputStream outStream = getTarOutputStream(outputTempFile);
1673
			
1675
			
1674
			// get all the entries
1676
			// get all the entries
1675
			VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor);
1677
			VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor);
Lines 1778-1784 Link Here
1778
		
1780
		
1779
				// open a new temp file which will be our destination for the new tar file
1781
				// open a new temp file which will be our destination for the new tar file
1780
				outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$
1782
				outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$
1781
				TarOutputStream outStream = new TarOutputStream(new FileOutputStream(outputTempFile));
1783
				TarOutputStream outStream = getTarOutputStream(outputTempFile);
1782
			
1784
			
1783
				// get all the entries in the current tar				  
1785
				// get all the entries in the current tar				  
1784
				VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor);
1786
				VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor);
Lines 1905-1911 Link Here
1905
			
1907
			
1906
				// open a new temp file which will be our destination for the new tar file
1908
				// open a new temp file which will be our destination for the new tar file
1907
				outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$
1909
				outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$
1908
				TarOutputStream outStream = new TarOutputStream(new FileOutputStream(outputTempFile));
1910
				TarOutputStream outStream = getTarOutputStream(outputTempFile);
1909
				
1911
				
1910
				// get all the entries
1912
				// get all the entries
1911
				VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor);
1913
				VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor);
Lines 2192-2198 Link Here
2192
				
2194
				
2193
				// open a new temp file which will be our destination for the new tar file
2195
				// open a new temp file which will be our destination for the new tar file
2194
				outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$
2196
				outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$
2195
				outStream = new TarOutputStream(new FileOutputStream(outputTempFile));
2197
				outStream = getTarOutputStream(outputTempFile);
2196
				
2198
				
2197
				// get all the entries
2199
				// get all the entries
2198
				VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor);
2200
				VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor);
Lines 2343-2349 Link Here
2343
		try {
2345
		try {
2344
2346
2345
			// create output stream
2347
			// create output stream
2346
			TarOutputStream outStream = new TarOutputStream(new FileOutputStream(file));
2348
			TarOutputStream outStream = getTarOutputStream(file);
2347
			
2349
			
2348
			// close output stream, so we have an empty tar file
2350
			// close output stream, so we have an empty tar file
2349
			outStream.close();
2351
			outStream.close();
Lines 2609-2612 Link Here
2609
			archiveOperationMonitor.setDone(true);
2611
			archiveOperationMonitor.setDone(true);
2610
		}
2612
		}
2611
	}
2613
	}
2614
	
2615
	/**
2616
	 * get the tar output stream from file, 
2617
	 * this method can be override by subclass to return compressed output steam if needed 
2618
	 * @param outputFile the output file to create stream
2619
	 * @return OutputStream the output stream to write 
2620
	 * @throws FileNotFoundException when the output file doesn't exists
2621
     * @since 3.0
2622
	 */
2623
	protected TarOutputStream getTarOutputStream(File outputFile) throws FileNotFoundException {
2624
		TarOutputStream outStream = new TarOutputStream(new FileOutputStream(outputFile));
2625
		return outStream;
2626
	}
2612
}
2627
}
(-)clientserver/org/eclipse/rse/services/clientserver/archiveutils/TarFile.java (-1 / +3 lines)
Lines 14-19 Link Here
14
 * Contributors:
14
 * Contributors:
15
 * {Name} (company) - description of contribution.
15
 * {Name} (company) - description of contribution.
16
 * Xuan Chen (IBM) - [api] SystemTarHandler has inconsistent API
16
 * Xuan Chen (IBM) - [api] SystemTarHandler has inconsistent API
17
 * Johnson Ma (Wind River) - [195402] Add tar.gz archive support
17
 *******************************************************************************/
18
 *******************************************************************************/
18
19
19
package org.eclipse.rse.services.clientserver.archiveutils;
20
package org.eclipse.rse.services.clientserver.archiveutils;
Lines 197-204 Link Here
197
	 * Gets the input stream for the tar file.
198
	 * Gets the input stream for the tar file.
198
	 * @return the input stream for the tar file.
199
	 * @return the input stream for the tar file.
199
	 * @throws FileNotFoundException if the file does not exist.
200
	 * @throws FileNotFoundException if the file does not exist.
201
	 * @since 3.0
200
	 */
202
	 */
201
	private InputStream getInputStream() throws FileNotFoundException {
203
	protected InputStream getInputStream() throws FileNotFoundException {
202
		FileInputStream stream = new FileInputStream(file);
204
		FileInputStream stream = new FileInputStream(file);
203
		return stream;
205
		return stream;
204
	}
206
	}
(-)clientserver/org/eclipse/rse/internal/services/clientserver/archiveutils/TgzFile.java (+65 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Wind River Systems, Inc. and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * 
8
 * Contributors: 
9
 * Johnson Ma (Wind River) - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.rse.internal.services.clientserver.archiveutils;
12
13
import java.io.File;
14
import java.io.FileNotFoundException;
15
import java.io.IOException;
16
import java.io.InputStream;
17
import java.util.zip.GZIPInputStream;
18
19
import org.eclipse.rse.services.clientserver.archiveutils.TarFile;
20
21
/**
22
 * This class is used to read entries from tar.gz file
23
 * It read compressed data from GZIPInputStream
24
 */
25
public class TgzFile extends TarFile {
26
27
	/**
28
	 * Opens a tar.gz file for reading given the specified File object.
29
	 * @param file the tar.gz file to be opened for reading.
30
	 * @throws FileNotFoundException if the file does not exist.
31
	 * @throws IOException if an I/O error occurs.
32
	 */
33
	public TgzFile(File file) throws FileNotFoundException, IOException {
34
		super(file);
35
	}
36
	
37
	/**
38
	 * Opens a tar.gz file for reading given the file name.
39
	 * @param name the name of the tar file to be opened for reading.
40
	 * @throws FileNotFoundException if the file with the given name does not exist.
41
	 * @throws IOException if an I/O error occurs.
42
	 */
43
	public TgzFile(String name) throws FileNotFoundException, IOException {
44
		super(name);
45
	}
46
	
47
	/**
48
	 * Gets the input stream for the tar.gz file.
49
	 * Get file input steam from superclass, wrap it using GZipInputSteam
50
	 * @return the input stream for the tar file.
51
	 * @throws FileNotFoundException if the file does not exist.
52
	 */
53
	protected InputStream getInputStream() throws FileNotFoundException {
54
		InputStream fileInputStream = super.getInputStream();
55
		GZIPInputStream zipInputStream = null;
56
		try{
57
		    zipInputStream = new GZIPInputStream(fileInputStream);
58
		} catch (IOException ioe) {
59
			//in that case, the file doesn't exists yet. return the file input stream from base class
60
            return fileInputStream;
61
		}
62
		return zipInputStream;
63
	}
64
65
}
(-)clientserver/org/eclipse/rse/internal/services/clientserver/archiveutils/SystemTgzHandler.java (+63 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Wind River Systems, Inc. and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * 
8
 * Contributors: 
9
 * Johnson Ma (Wind River) - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.rse.internal.services.clientserver.archiveutils;
12
13
import java.io.File;
14
import java.io.FileNotFoundException;
15
import java.io.FileOutputStream;
16
import java.io.IOException;
17
import java.util.zip.GZIPOutputStream;
18
19
import org.eclipse.rse.services.clientserver.archiveutils.SystemTarHandler;
20
import org.eclipse.rse.services.clientserver.archiveutils.TarFile;
21
22
/**
23
 * handler class for .tar.gz and .tgz files
24
 */
25
public class SystemTgzHandler extends SystemTarHandler {
26
27
	/**
28
	 * constructor for the tgz handler
29
	 * @param file the .tar.gz or .tgz file
30
	 */
31
	public SystemTgzHandler(File file) throws IOException {
32
	    super(file);
33
	}
34
	
35
	/**
36
	 * Gets a tar.gz file from the underlying file.
37
	 * @return the tar file, or <code>null</code> if the tar file does not exist.
38
	 */
39
	protected TarFile getTarFile() {
40
		
41
		TarFile tarFile = null;
42
		
43
		try {
44
			tarFile = new TgzFile(file);
45
		}
46
		catch (IOException e) {
47
			// TODO: log error
48
		}
49
		
50
		return tarFile;
51
	}
52
	
53
	protected TarOutputStream getTarOutputStream(File outputFile) throws FileNotFoundException {
54
		GZIPOutputStream zipOutputStream = null;
55
		try{
56
		    zipOutputStream = new GZIPOutputStream(new FileOutputStream(outputFile));
57
		} catch (IOException ioe) {
58
			throw new FileNotFoundException(ioe.getMessage());
59
		}
60
		TarOutputStream outStream = new TarOutputStream(zipOutputStream);
61
		return outStream;
62
	}
63
}

Return to bug 195402