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/CreateFileTestCase.java (-1 / +10 lines)
Lines 11-16 Link Here
11
 * Contributors:
11
 * Contributors:
12
 * Martin Oberhuber (Wind River) - [cleanup] Avoid using SystemStartHere in production code
12
 * Martin Oberhuber (Wind River) - [cleanup] Avoid using SystemStartHere in production code
13
 * Martin Oberhuber (Wind River) - organize, enable and tag test cases
13
 * Martin Oberhuber (Wind River) - organize, enable and tag test cases
14
 * Martin Oberhuber (Wind River) - [195402] Add constructor with test name
14
 ********************************************************************************/
15
 ********************************************************************************/
15
16
16
package org.eclipse.rse.tests.subsystems.files;
17
package org.eclipse.rse.tests.subsystems.files;
Lines 34-40 Link Here
34
	// File Dialog.  This string can be so using this for base test.
35
	// File Dialog.  This string can be so using this for base test.
35
	private String fileName = "a !@#${a}'%^&()_ =[]~+-'`;,.txt"; //$NON-NLS-1$
36
	private String fileName = "a !@#${a}'%^&()_ =[]~+-'`;,.txt"; //$NON-NLS-1$
36
	private IRemoteFile tempDirectory = null;
37
	private IRemoteFile tempDirectory = null;
37
	
38
39
	/**
40
	 * Constructor with specific test name.
41
	 * @param name test to execute
42
	 */
43
	public CreateFileTestCase(String name) {
44
		super(name);
45
	}
46
38
	private IRemoteFileSubSystem getRemoteFileSubSystem(IHost host) {
47
	private IRemoteFileSubSystem getRemoteFileSubSystem(IHost host) {
39
		IRemoteFileSubSystem fss = null;
48
		IRemoteFileSubSystem fss = null;
40
		ISystemRegistry sr = SystemStartHere.getSystemRegistry(); 
49
		ISystemRegistry sr = SystemStartHere.getSystemRegistry(); 
(-)src/org/eclipse/rse/tests/subsystems/files/FileServiceBaseTest.java (-3 / +12 lines)
Lines 1-16 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others. 
2
 * Copyright (c) 2007, 2008 IBM Corporation and others. 
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * 
7
 * 
8
 * Contributors: 
8
 * Contributors: 
9
 * Xuan Chen (IBM)               - initial API and implementation
9
 * Xuan Chen (IBM) - initial API and implementation
10
 *   - <copied code from org.eclipse.core.tests.internal.localstore/LocalStoreTest (Copyright IBM)>
10
 *   - <copied code from org.eclipse.core.tests.internal.localstore/LocalStoreTest (Copyright IBM)>
11
 *   - <copied code from org.eclipse.core.tests.harness/CoreTest (Copyright IBM)>
11
 *   - <copied code from org.eclipse.core.tests.harness/CoreTest (Copyright IBM)>
12
 *   - <copied code from org.eclipse.core.tests.resources/ResourceTest (Copyright IBM)>
12
 *   - <copied code from org.eclipse.core.tests.resources/ResourceTest (Copyright IBM)>
13
 *   - <copied code from org.eclipse.core.tests.harness/CoreTest (Copyright IBM)>
13
 *   - <copied code from org.eclipse.core.tests.harness/CoreTest (Copyright IBM)>
14
 * Martin Oberhuber (Wind River) - [195402] Add constructor with test name
14
 *******************************************************************************/
15
 *******************************************************************************/
15
package org.eclipse.rse.tests.subsystems.files;
16
package org.eclipse.rse.tests.subsystems.files;
16
17
Lines 54-59 Link Here
54
	
55
	
55
	public static int TYPE_FILE = 0;
56
	public static int TYPE_FILE = 0;
56
	public static int TYPE_FOLDER = 1;
57
	public static int TYPE_FOLDER = 1;
58
59
	/**
60
	 * Constructor with specific test name.
61
	 * @param name test to execute
62
	 */
63
	public FileServiceBaseTest(String name) {
64
		super(name);
65
	}
57
	
66
	
58
	public void setUp() throws Exception {
67
	public void setUp() throws Exception {
59
		super.setUp();
68
		super.setUp();
Lines 261-267 Link Here
261
	 * 
270
	 * 
262
	 * @param target the file to create
271
	 * @param target the file to create
263
	 * @param content content of the new file
272
	 * @param content content of the new file
264
	 * @throws CoreException
273
	 * @throws CoreException in case of failure
265
	 */
274
	 */
266
	protected void createFile(IFileStore target, String content) throws CoreException {
275
	protected void createFile(IFileStore target, String content) throws CoreException {
267
		target.delete(EFS.NONE, null);
276
		target.delete(EFS.NONE, null);
(-)src/org/eclipse/rse/tests/subsystems/files/FileOutputStreamTestCase.java (-1 / +10 lines)
Lines 11-16 Link Here
11
 * Contributors:
11
 * Contributors:
12
 * Martin Oberhuber (Wind River) - [cleanup] Avoid using SystemStartHere in production code
12
 * Martin Oberhuber (Wind River) - [cleanup] Avoid using SystemStartHere in production code
13
 * Martin Oberhuber (Wind River) - organize, enable and tag test cases
13
 * Martin Oberhuber (Wind River) - organize, enable and tag test cases
14
 * Martin Oberhuber (Wind River) - [195402] Add constructor with test name
14
 ********************************************************************************/
15
 ********************************************************************************/
15
16
16
package org.eclipse.rse.tests.subsystems.files;
17
package org.eclipse.rse.tests.subsystems.files;
Lines 37-43 Link Here
37
38
38
	private IHost host = null;
39
	private IHost host = null;
39
	private IRemoteFile tempDirectory;
40
	private IRemoteFile tempDirectory;
40
	
41
42
	/**
43
	 * Constructor with specific test name.
44
	 * @param name test to execute
45
	 */
46
	public FileOutputStreamTestCase(String name) {
47
		super(name);
48
	}
49
41
	private IRemoteFileSubSystem getRemoteFileSubSystem(IHost host) {
50
	private IRemoteFileSubSystem getRemoteFileSubSystem(IHost host) {
42
		IRemoteFileSubSystem fss = null;
51
		IRemoteFileSubSystem fss = null;
43
		ISystemRegistry sr = SystemStartHere.getSystemRegistry(); 
52
		ISystemRegistry sr = SystemStartHere.getSystemRegistry(); 
(-)src/org/eclipse/rse/tests/subsystems/files/FileServiceArchiveTestDStoreWindows.java (-1 / +10 lines)
Lines 6-13 Link Here
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
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) - [195402] Add constructor with test name
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.rse.tests.subsystems.files;
13
package org.eclipse.rse.tests.subsystems.files;
13
14
Lines 29-34 Link Here
29
	private boolean fPreference_ALERT_SSL;
30
	private boolean fPreference_ALERT_SSL;
30
	private boolean fPreference_ALERT_NONSSL;
31
	private boolean fPreference_ALERT_NONSSL;
31
32
33
	/**
34
	 * Constructor with specific test name.
35
	 * @param name test to execute
36
	 */
37
	public FileServiceArchiveTestDStoreWindows(String name) {
38
		super(name);
39
	}
40
32
	public static junit.framework.Test suite() {
41
	public static junit.framework.Test suite() {
33
		
42
		
34
		TestSuite suite = new TestSuite("FileServiceArchiveTestDStoreWindows");
43
		TestSuite suite = new TestSuite("FileServiceArchiveTestDStoreWindows");
(-)src/org/eclipse/rse/tests/subsystems/files/FileServiceArchiveTest.java (-894 / +14 lines)
Lines 6-21 Link Here
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
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
	/**
59
		return ResourcesPlugin.getWorkspace();
44
	 * Constructor with specific test name.
60
	}
45
	 * @param name test to execute
61
	
46
	 */
62
	public void createSourceFolders() throws Exception
47
	public FileServiceArchiveTest(String name) {
63
	{
48
		super(name);
64
		String tempPath = getWorkspace().getRoot().getLocation().append("temp").toString();
49
		tarSourceFileName1 = "source.tar";
65
		IFileStore temp = createDir(tempPath, true);
50
		tarSourceFileName2 = "mynewtar.tar";
66
		String content = getRandomString();
51
		tarSourceForOpenTest = "tarSourceForOpen.tar";
67
		
52
		testName = "dummy.tar";
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
	}
53
	}
122
	
54
	
123
	public void createSourceZipFiles() throws Exception
55
	public void createSourceZipFiles() throws Exception
Lines 370-590 Link Here
370
		return targetDir;
302
		return targetDir;
371
	}
303
	}
372
	
304
	
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
	
305
	
589
306
590
	public void testCreateZipFile() throws Exception {
307
	public void testCreateZipFile() throws Exception {
Lines 1406-1654 Link Here
1406
		checkFolderContents((IRemoteFile)theCopiedChild, childrenToCheck, typesToCheck);
1123
		checkFolderContents((IRemoteFile)theCopiedChild, childrenToCheck, typesToCheck);
1407
	}
1124
	}
1408
	
1125
	
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
	
1126
	
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
	
1127
	
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
1128
1653
	public void testCopyToTarVirtualFileLevelOne() throws Exception {
1129
	public void testCopyToTarVirtualFileLevelOne() throws Exception {
1654
		//-test-author-:XuanChen
1130
		//-test-author-:XuanChen
Lines 1721-1755 Link Here
1721
		checkFolderContents((IRemoteFile)theCopiedChild, childrenToCheck, typesToCheck);
1197
		checkFolderContents((IRemoteFile)theCopiedChild, childrenToCheck, typesToCheck);
1722
	}
1198
	}
1723
1199
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
1200
1754
	public void testCopyTarVirtualFileLevelFour() throws Exception {
1201
	public void testCopyTarVirtualFileLevelFour() throws Exception {
1755
		//-test-author-:XuanChen
1202
		//-test-author-:XuanChen
Lines 1799-1836 Link Here
1799
		checkFolderContents((IRemoteFile)copiedVirtualFolder, contents, typesToCheck);
1246
		checkFolderContents((IRemoteFile)copiedVirtualFolder, contents, typesToCheck);
1800
	}
1247
	}
1801
1248
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
1249
1835
	public void testMoveToTarVirtualFileLevelOne() throws Exception {
1250
	public void testMoveToTarVirtualFileLevelOne() throws Exception {
1836
		//-test-author-:XuanChen
1251
		//-test-author-:XuanChen
Lines 1912-1952 Link Here
1912
		assertNull(originalSource);
1327
		assertNull(originalSource);
1913
	}
1328
	}
1914
1329
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
1330
1951
	public void testMoveTarVirtualFileLevelFour() throws Exception {
1331
	public void testMoveTarVirtualFileLevelFour() throws Exception {
1952
		//-test-author-:XuanChen
1332
		//-test-author-:XuanChen
Lines 1992-2192 Link Here
1992
		assertNull(result);  //we should not be able to find it.
1372
		assertNull(result);  //we should not be able to find it.
1993
	}
1373
	}
1994
1374
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
1375
2191
1376
2192
	public void testCopyBatchToTarVirtualFileLevelFour() throws Exception {
1377
	public void testCopyBatchToTarVirtualFileLevelFour() throws Exception {
Lines 2311-2380 Link Here
2311
		Object copiedVirtualFolder3 = getChildFromFolder(folder1, thirdToCopyName);
1496
		Object copiedVirtualFolder3 = getChildFromFolder(folder1, thirdToCopyName);
2312
		assertNotNull(copiedVirtualFolder3);
1497
		assertNotNull(copiedVirtualFolder3);
2313
	}
1498
	}
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
1499
2380
}
1500
}
(-)src/org/eclipse/rse/tests/subsystems/files/FileServiceArchiveTestDStore.java (-1 / +10 lines)
Lines 9-14 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
 * Martin Oberhuber (Wind River) - [195402] Add constructor with test name
12
 *******************************************************************************/
13
 *******************************************************************************/
13
package org.eclipse.rse.tests.subsystems.files;
14
package org.eclipse.rse.tests.subsystems.files;
14
15
Lines 41-47 Link Here
41
	
42
	
42
	private boolean fPreference_ALERT_SSL;
43
	private boolean fPreference_ALERT_SSL;
43
	private boolean fPreference_ALERT_NONSSL;
44
	private boolean fPreference_ALERT_NONSSL;
44
	
45
46
	/**
47
	 * Constructor with specific test name.
48
	 * @param name test to execute
49
	 */
50
	public FileServiceArchiveTestDStore(String name) {
51
		super(name);
52
	}
53
45
	public static junit.framework.Test suite() {
54
	public static junit.framework.Test suite() {
46
		TestSuite suite = new TestSuite("FileServiceArchiveTestDStore");
55
		TestSuite suite = new TestSuite("FileServiceArchiveTestDStore");
47
		
56
		
(-)src/org/eclipse/rse/tests/subsystems/files/FileServiceArchiveBaseTest.java (+945 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2008 IBM Corporation 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) - [195402] Extracted from FileServiceArchiveTest
10
 *******************************************************************************/
11
package org.eclipse.rse.tests.subsystems.files;
12
13
import java.io.File;
14
15
import org.eclipse.core.filesystem.EFS;
16
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;
20
import org.eclipse.rse.core.model.ISystemResourceSet;
21
import org.eclipse.rse.core.model.SystemRemoteResourceSet;
22
import org.eclipse.rse.core.model.SystemWorkspaceResourceSet;
23
import org.eclipse.rse.core.subsystems.ISystemDragDropAdapter;
24
import org.eclipse.rse.files.ui.resources.UniversalFileTransferUtility;
25
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
26
import org.eclipse.rse.tests.RSETestsPlugin;
27
28
public abstract class FileServiceArchiveBaseTest extends FileServiceBaseTest {
29
30
	protected String folderToCopyName1 = "RemoteSystemsConnections";
31
	protected String folderToCopyName2 = "6YLT5Xa";
32
	protected String folderToCopyName3 = "folderToCopy";
33
	
34
	protected String tarSourceFileName1;
35
	protected String tarSourceFileName2;
36
	
37
	protected String tarSourceFolderName1 = "META-INF";
38
	protected String tarSourceFolderName2 = "org";
39
	
40
	protected String tarSourceForOpenTest;
41
	protected String tarSourceForOpenFolderName1 = "META-INF";
42
	protected String tarSourceForOpenFolderName2 = "org";
43
	
44
	protected String testName;
45
	
46
	protected String fileContentString1 = "this is just some dummy content \n to a remote file \n to test an open operation";
47
48
	/**
49
	 * Constructor with specific test name.
50
	 * @param name test to execute
51
	 */
52
	public FileServiceArchiveBaseTest(String name) {
53
		super(name);
54
	}
55
	
56
	public static IWorkspace getWorkspace() {
57
		return ResourcesPlugin.getWorkspace();
58
	}
59
	
60
	public void createSourceFolders() throws Exception
61
	{
62
		String tempPath = getWorkspace().getRoot().getLocation().append("temp").toString();
63
		IFileStore temp = createDir(tempPath, true);
64
		String content = getRandomString();
65
		
66
		// create the source folder used for copy or move
67
		IFileStore folderToCopy = temp.getChild(folderToCopyName3);
68
		createDir(folderToCopy, true);
69
		//Now, populate the contents in the folderToCopy.
70
		IFileStore aaaaaaaa = folderToCopy.getChild("aaaaaaaa");
71
		createDir(aaaaaaaa, true);
72
		//create file inside the aaaaaaaa folder.
73
		IFileStore adsf = aaaaaaaa.getChild("adsf");
74
		content = getRandomString();
75
		createFile(adsf, content);
76
		IFileStore eclipse_SDK_3_3M6_win32_zip = aaaaaaaa.getChild("eclipse-SDK-3.3M6-win32.zip");
77
		createFile(eclipse_SDK_3_3M6_win32_zip, "");
78
		IFileStore epdcdump01_hex12 = aaaaaaaa.getChild("epdcdump01.hex12");
79
		content = getRandomString();
80
		createFile(epdcdump01_hex12, content);
81
		IFileStore epdcdump01_hex12aaaa = aaaaaaaa.getChild("epdcdump01.hex12aaaa");
82
		content = getRandomString();
83
		createFile(epdcdump01_hex12aaaa, content);
84
		
85
		IFileStore aaaab = folderToCopy.getChild("aaaab");
86
		createDir(aaaab, true);
87
		IFileStore features = aaaab.getChild("features");
88
		createDir(features, true);
89
		IFileStore dummyFile = features.getChild("dummy.txt");
90
		content = getRandomString();
91
		createFile(dummyFile, content);
92
		//create file inside the aaaab folder.
93
		content = "this is just a simple content \n to a simple file \n to test a 'simple' copy";
94
		IFileStore epdcdump01_hex12a = aaaab.getChild("epdcdump01.hex12a");
95
		content = getRandomString();
96
		createFile(epdcdump01_hex12a, content);
97
		
98
		IFileStore epdcdump01_hex12a1 = folderToCopy.getChild("epdcdump01.hex12a");
99
		content = getRandomString();
100
		createFile(epdcdump01_hex12a1, content);
101
		
102
		IFileStore RSE_SDK_2_0RC1_zip = folderToCopy.getChild("RSE-SDK-2.0RC1.zip");
103
		content = getRandomString();
104
		createFile(RSE_SDK_2_0RC1_zip, content);
105
		
106
		//now, copy folderToCopy into the folder in the remote system
107
		IRemoteFile sourceFolderToCopy3 = localFss.getRemoteFileObject(tempPath + '\\' + folderToCopyName3, mon);
108
		ISystemDragDropAdapter srcAdapter3 = (ISystemDragDropAdapter) ((IAdaptable) sourceFolderToCopy3).getAdapter(ISystemDragDropAdapter.class);
109
		SystemRemoteResourceSet fromSet3 = new SystemRemoteResourceSet(localFss, srcAdapter3);
110
		fromSet3.addResource(sourceFolderToCopy3);
111
		ISystemResourceSet tempObjects3 = srcAdapter3.doDrag(fromSet3, mon);
112
		UniversalFileTransferUtility.uploadResourcesFromWorkspace((SystemWorkspaceResourceSet)tempObjects3, tempDir, mon, true);
113
		
114
		//Then, we need to retrieve children of the tempDir to cache their information.
115
		fss.resolveFilterString(tempDir, null, mon);
116
		
117
		//Then, delete the temp folder in the junit workspace.
118
		temp.delete(EFS.NONE, mon);
119
	}
120
	
121
122
	protected void createSuperTransferFolder(IFileStore temp) throws Exception 
123
	{
124
		
125
		String content = getRandomString();
126
		
127
		// create the source folder used for copy or move
128
		IFileStore folderToCopy = temp.getChild(folderToCopyName3);
129
		createDir(folderToCopy, true);
130
		//Now, populate the contents in the folderToCopy.
131
		IFileStore aaaaaaaa = folderToCopy.getChild("aaaaaaaa");
132
		createDir(aaaaaaaa, true);
133
		//create file inside the aaaaaaaa folder.
134
		IFileStore adsf = aaaaaaaa.getChild("adsf");
135
		content = getRandomString();
136
		createFile(adsf, content);
137
		IFileStore eclipse_SDK_3_3M6_win32_zip = aaaaaaaa.getChild("eclipse-SDK-3.3M6-win32.zip");
138
		createFile(eclipse_SDK_3_3M6_win32_zip, "");
139
		IFileStore epdcdump01_hex12 = aaaaaaaa.getChild("epdcdump01.hex12");
140
		content = getRandomString();
141
		createFile(epdcdump01_hex12, content);
142
		IFileStore epdcdump01_hex12aaaa = aaaaaaaa.getChild("epdcdump01.hex12aaaa");
143
		content = getRandomString();
144
		createFile(epdcdump01_hex12aaaa, content);
145
		
146
		IFileStore aaaab = folderToCopy.getChild("aaaab");
147
		createDir(aaaab, true);
148
		IFileStore features = aaaab.getChild("features");
149
		createDir(features, true);
150
		IFileStore dummyFile = features.getChild("dummy.txt");
151
		content = getRandomString();
152
		createFile(dummyFile, content);
153
		//create file inside the aaaab folder.
154
		content = "this is just a simple content \n to a simple file \n to test a 'simple' copy";
155
		IFileStore epdcdump01_hex12a = aaaab.getChild("epdcdump01.hex12a");
156
		content = getRandomString();
157
		createFile(epdcdump01_hex12a, content);
158
		
159
		IFileStore epdcdump01_hex12a1 = folderToCopy.getChild("epdcdump01.hex12a");
160
		content = getRandomString();
161
		createFile(epdcdump01_hex12a1, content);
162
		
163
		IFileStore RSE_SDK_2_0RC1_zip = folderToCopy.getChild("RSE-SDK-2.0RC1.zip");
164
		content = getRandomString();
165
		createFile(RSE_SDK_2_0RC1_zip, content);
166
		
167
		return;
168
169
	}
170
	
171
	public void createTarSourceForOpen() throws Exception
172
	{
173
		String tempPath = getWorkspace().getRoot().getLocation().append("temp").toString();
174
		IFileStore temp = createDir(tempPath, true);
175
		String content = getRandomString();
176
		
177
		//Now, we need to construct a "source.tar" archive file
178
		//We will construct the content of the tar file in folders "META-INF" and "org"
179
		//Then we copy this folder into a tar file by RSE API.
180
		IFileStore META_INF = temp.getChild(tarSourceForOpenFolderName1);
181
		createDir(META_INF, true);
182
		//Now, populate the contents in the folder.
183
		IFileStore MANIFEST_MF = META_INF.getChild("MANIFEST.MF");
184
		content = fileContentString1;
185
		createFile(MANIFEST_MF, content);
186
		
187
		//create folder "org"
188
		IFileStore org = temp.getChild("org");
189
		createDir(org, true);
190
		IFileStore eclipse = org.getChild("eclipse");
191
		createDir(eclipse, true);
192
		//create "dstore" folder inside "org"
193
		IFileStore dstore = eclipse.getChild("dstore");
194
		createDir(dstore, true);
195
		//Now, create a few folders inside the dstore folder.
196
		IFileStore core = dstore.getChild("core");
197
		createDir(core, true);
198
		IFileStore internal = dstore.getChild("internal");
199
		createDir(internal, true);
200
		
201
		//now create directory inside "core":
202
		IFileStore client = core.getChild("client");
203
		createDir(client, true);
204
		IFileStore java = core.getChild("java");
205
		createDir(java, true);
206
		IFileStore miners = core.getChild("miners");
207
		createDir(miners, true);
208
		IFileStore model = core.getChild("model");
209
		createDir(model, true);
210
		IFileStore server = core.getChild("server");
211
		createDir(server, true);
212
		IFileStore util = core.getChild("util");
213
		createDir(util, true);
214
		IFileStore Activator_java = core.getChild("Activator.java");
215
		content = fileContentString1;
216
		createFile(Activator_java, content);
217
		
218
		//now, some contents on client folder
219
		IFileStore ClientConnection_java = client.getChild("ClientConnection.java");
220
		content = getRandomString();
221
		createFile(ClientConnection_java, content);
222
		IFileStore ConnectionStatus_java = client.getChild("ConnectionStatus.java");
223
		content = fileContentString1;
224
		createFile(ConnectionStatus_java, content);
225
		
226
		//now, some contents in java folder
227
		IFileStore ClassByteStreamHandler$ReceiveClassInstanceThread_java = java.getChild("ClassByteStreamHandler$ReceiveClassInstanceThread.java");
228
		content = getRandomString();
229
		createFile(ClassByteStreamHandler$ReceiveClassInstanceThread_java, content);
230
		
231
		//now, some contents in miners folder
232
		IFileStore Miner_java = miners.getChild("Miner.java");
233
		content = getRandomString();
234
		createFile(Miner_java, content);
235
		IFileStore MinerThread_java = miners.getChild("MinerThread.java");
236
		content = getRandomString();
237
		createFile(MinerThread_java, content);
238
		
239
		//now, some contents in model folder
240
		IFileStore ByteStreamHandler_java = model.getChild("ByteStreamHandler.java");
241
		content = getRandomString();
242
		createFile(ByteStreamHandler_java, content);
243
		IFileStore DE_java = model.getChild("DE.java");
244
		content = getRandomString();
245
		createFile(DE_java, content);
246
		IFileStore Handler_java = model.getChild("Handler.java");
247
		content = getRandomString();
248
		createFile(Handler_java, content);
249
		
250
		//now, some contents in server folder
251
		IFileStore Server_java = server.getChild("Server.java");
252
		content = getRandomString();
253
		createFile(Server_java, content);
254
		
255
		//now, some contents in util folder
256
		IFileStore StringCompare_java = util.getChild("StringCompare.java");
257
		content = fileContentString1;
258
		createFile(StringCompare_java, content);
259
		
260
		//now, create the contents in "internal" folder
261
		IFileStore core1 = internal.getChild("core");
262
		createDir(core1, true);
263
		
264
		//then create some folder in this "core" folder
265
		IFileStore client1 = core1.getChild("client");
266
		createDir(client1, true);
267
		IFileStore model1 = core1.getChild("model");
268
		createDir(model1, true);
269
		IFileStore server1 = core1.getChild("server");
270
		createDir(server1, true);
271
		IFileStore util1 = core1.getChild("util");
272
		createDir(util1, true);
273
		
274
		//now, some contents on client folder
275
		IFileStore ClientConnection_java1 = client1.getChild("ClientConnection.java");
276
		content = getRandomString();
277
		createFile(ClientConnection_java1, content);
278
		IFileStore ConnectionStatus_java1 = client1.getChild("ConnectionStatus.java");
279
		content = getRandomString();
280
		createFile(ConnectionStatus_java1, content);
281
		
282
		
283
		//now, some contents in model folder
284
		IFileStore ByteStreamHandler_java1 = model1.getChild("ByteStreamHandler.java");
285
		content = getRandomString();
286
		createFile(ByteStreamHandler_java1, content);
287
		IFileStore DE_java1 = model1.getChild("DE.java");
288
		content = getRandomString();
289
		createFile(DE_java1, content);
290
		IFileStore Handler_java1 = model1.getChild("Handler.java");
291
		content = getRandomString();
292
		createFile(Handler_java1, content);
293
		
294
		//now, some contents in server folder
295
		IFileStore Server_java1 = server1.getChild("Server.java");
296
		content = getRandomString();
297
		createFile(Server_java1, content);
298
		
299
		//now, some contents in util folder
300
		IFileStore StringCompare_java1 = util1.getChild("StringCompare.java");
301
		content = getRandomString();
302
		createFile(StringCompare_java1, content);
303
		
304
		//now, copy META_INF into the folder in the remote system
305
		IRemoteFile META_INF_folder = localFss.getRemoteFileObject(tempPath + '\\' + tarSourceForOpenFolderName1, mon);
306
		assertNotNull(META_INF_folder);
307
		ISystemDragDropAdapter srcAdapter1 = (ISystemDragDropAdapter) ((IAdaptable) META_INF_folder).getAdapter(ISystemDragDropAdapter.class);
308
		SystemRemoteResourceSet fromSet = new SystemRemoteResourceSet(localFss, srcAdapter1);
309
		fromSet.addResource(META_INF_folder);
310
		ISystemResourceSet tempObjects1 = srcAdapter1.doDrag(fromSet, mon);
311
		UniversalFileTransferUtility.uploadResourcesFromWorkspace((SystemWorkspaceResourceSet)tempObjects1, tempDir, mon, true);
312
		
313
		//now, copy org into the folder in the remote system
314
		IRemoteFile org_folder = localFss.getRemoteFileObject(tempPath + '\\' + tarSourceForOpenFolderName2, mon);
315
		assertNotNull(org_folder);
316
		ISystemDragDropAdapter srcAdapter2 = (ISystemDragDropAdapter) ((IAdaptable) org_folder).getAdapter(ISystemDragDropAdapter.class);
317
		SystemRemoteResourceSet fromSet2 = new SystemRemoteResourceSet(localFss, srcAdapter2);
318
		fromSet2.addResource(org_folder);
319
		ISystemResourceSet tempObjects2 = srcAdapter2.doDrag(fromSet2, mon);
320
		UniversalFileTransferUtility.uploadResourcesFromWorkspace((SystemWorkspaceResourceSet)tempObjects2, tempDir, mon, true);
321
		
322
		//now, create tar file in the host
323
		IRemoteFile tarSource = createFileOrFolder(tempDir.getAbsolutePath(), tarSourceForOpenTest, false);
324
		assertNotNull(tarSource);
325
		IRemoteFile tarSourceFolder1 = (IRemoteFile)getChildFromFolder(tempDir, tarSourceForOpenFolderName1); 
326
		assertNotNull(tarSourceFolder1);
327
		IRemoteFile tarSourceFolder2 = (IRemoteFile)getChildFromFolder(tempDir, tarSourceForOpenFolderName2);
328
		fss.copy(tarSourceFolder1, tarSource, tarSourceForOpenFolderName1, mon);
329
		fss.copy(tarSourceFolder2, tarSource, tarSourceForOpenFolderName2, mon);
330
		
331
		//Then, we need to retrieve children of the tempDir to cache their information.
332
		fss.resolveFilterString(tempDir, null, mon);
333
		
334
		//Then, delete the temp folder in the junit workspace.
335
		temp.delete(EFS.NONE, mon);
336
	}
337
	
338
	
339
	
340
	public void createSourceTarFiles() throws Exception
341
	{
342
		String tempPath = getWorkspace().getRoot().getLocation().append("temp").toString();
343
		IFileStore temp = createDir(tempPath, true);
344
		String content = getRandomString();
345
		
346
		//Now, we need to construct a "source.tar" archive file
347
		//We will construct the content of the tar file in folders "META-INF" and "org"
348
		//Then we copy this folder into a tar file by RSE API.
349
		IFileStore META_INF = temp.getChild(tarSourceFolderName1);
350
		createDir(META_INF, true);
351
		//Now, populate the contents in the folder.
352
		IFileStore MANIFEST_MF = META_INF.getChild("MANIFEST.MF");
353
		content = getRandomString();
354
		createFile(MANIFEST_MF, content);
355
		//create folder "org"
356
		IFileStore org = temp.getChild(tarSourceFolderName2);
357
		createDir(org, true);
358
		IFileStore eclipse = org.getChild("eclipse");
359
		createDir(eclipse, true);
360
		//create "dstore" folder inside "org"
361
		IFileStore dstore = eclipse.getChild("dstore");
362
		createDir(dstore, true);
363
		//Now, create a few folders inside the dstore folder.
364
		IFileStore core = dstore.getChild("core");
365
		createDir(core, true);
366
		IFileStore internal = dstore.getChild("internal");
367
		createDir(internal, true);
368
		
369
		//now create directory inside "core":
370
		IFileStore client = core.getChild("client");
371
		createDir(client, true);
372
		IFileStore java = core.getChild("java");
373
		createDir(java, true);
374
		IFileStore miners = core.getChild("miners");
375
		createDir(miners, true);
376
		IFileStore model = core.getChild("model");
377
		createDir(model, true);
378
		IFileStore server = core.getChild("server");
379
		createDir(server, true);
380
		IFileStore util = core.getChild("util");
381
		createDir(util, true);
382
		IFileStore Activator_java = core.getChild("Activator.java");
383
		content = getRandomString();
384
		createFile(Activator_java, content);
385
		
386
		//now, some contents on client folder
387
		IFileStore ClientConnection_java = client.getChild("ClientConnection.java");
388
		content = getRandomString();
389
		createFile(ClientConnection_java, content);
390
		IFileStore ConnectionStatus_java = client.getChild("ConnectionStatus.java");
391
		content = getRandomString();
392
		createFile(ConnectionStatus_java, content);
393
		
394
		//now, some contents in java folder
395
		IFileStore ClassByteStreamHandler$ReceiveClassInstanceThread_java = java.getChild("ClassByteStreamHandler$ReceiveClassInstanceThread.java");
396
		content = getRandomString();
397
		createFile(ClassByteStreamHandler$ReceiveClassInstanceThread_java, content);
398
		
399
		//now, some contents in miners folder
400
		IFileStore Miner_java = miners.getChild("Miner.java");
401
		content = getRandomString();
402
		createFile(Miner_java, content);
403
		IFileStore MinerThread_java = miners.getChild("MinerThread.java");
404
		content = getRandomString();
405
		createFile(MinerThread_java, content);
406
		
407
		//now, some contents in model folder
408
		IFileStore ByteStreamHandler_java = model.getChild("ByteStreamHandler.java");
409
		content = getRandomString();
410
		createFile(ByteStreamHandler_java, content);
411
		IFileStore DE_java = model.getChild("DE.java");
412
		content = getRandomString();
413
		createFile(DE_java, content);
414
		IFileStore Handler_java = model.getChild("Handler.java");
415
		content = getRandomString();
416
		createFile(Handler_java, content);
417
		
418
		//now, some contents in server folder
419
		IFileStore Server_java = server.getChild("Server.java");
420
		content = getRandomString();
421
		createFile(Server_java, content);
422
		
423
		//now, some contents in util folder
424
		IFileStore StringCompare_java = util.getChild("StringCompare.java");
425
		content = getRandomString();
426
		createFile(StringCompare_java, content);
427
		
428
		//now, create the contents in "internal" folder
429
		IFileStore core1 = internal.getChild("core");
430
		createDir(core1, true);
431
		
432
		//then create some folder in this "core" folder
433
		IFileStore client1 = core1.getChild("client");
434
		createDir(client1, true);
435
		IFileStore model1 = core1.getChild("model");
436
		createDir(model1, true);
437
		IFileStore server1 = core1.getChild("server");
438
		createDir(server1, true);
439
		IFileStore util1 = core1.getChild("util");
440
		createDir(util1, true);
441
		
442
		//now, some contents on client folder
443
		IFileStore ClientConnection_java1 = client1.getChild("ClientConnection.java");
444
		content = getRandomString();
445
		createFile(ClientConnection_java1, content);
446
		IFileStore ConnectionStatus_java1 = client1.getChild("ConnectionStatus.java");
447
		content = getRandomString();
448
		createFile(ConnectionStatus_java1, content);
449
		
450
		
451
		//now, some contents in model folder
452
		IFileStore ByteStreamHandler_java1 = model1.getChild("ByteStreamHandler.java");
453
		content = getRandomString();
454
		createFile(ByteStreamHandler_java1, content);
455
		IFileStore DE_java1 = model1.getChild("DE.java");
456
		content = getRandomString();
457
		createFile(DE_java1, content);
458
		IFileStore Handler_java1 = model1.getChild("Handler.java");
459
		content = getRandomString();
460
		createFile(Handler_java1, content);
461
		
462
		//now, some contents in server folder
463
		IFileStore Server_java1 = server1.getChild("Server.java");
464
		content = getRandomString();
465
		createFile(Server_java1, content);
466
		
467
		//now, some contents in util folder
468
		IFileStore StringCompare_java1 = util1.getChild("StringCompare.java");
469
		content = getRandomString();
470
		createFile(StringCompare_java1, content);
471
		
472
		//now, copy META_INF into the folder in the remote system
473
		IRemoteFile META_INF_folder = localFss.getRemoteFileObject(tempPath + '\\' + tarSourceFolderName1, mon);
474
		assertNotNull(META_INF_folder);
475
		ISystemDragDropAdapter srcAdapter1 = (ISystemDragDropAdapter) ((IAdaptable) META_INF_folder).getAdapter(ISystemDragDropAdapter.class);
476
		SystemRemoteResourceSet fromSet = new SystemRemoteResourceSet(localFss, srcAdapter1);
477
		fromSet.addResource(META_INF_folder);
478
		ISystemResourceSet tempObjects1 = srcAdapter1.doDrag(fromSet, mon);
479
		UniversalFileTransferUtility.uploadResourcesFromWorkspace((SystemWorkspaceResourceSet)tempObjects1, tempDir, mon, true);
480
		
481
		//now, copy org into the folder in the remote system
482
		IRemoteFile org_folder = localFss.getRemoteFileObject(tempPath + '\\' + tarSourceFolderName2, mon);
483
		assertNotNull(org_folder);
484
		ISystemDragDropAdapter srcAdapter2 = (ISystemDragDropAdapter) ((IAdaptable) org_folder).getAdapter(ISystemDragDropAdapter.class);
485
		SystemRemoteResourceSet fromSet2 = new SystemRemoteResourceSet(localFss, srcAdapter2);
486
		fromSet2.addResource(org_folder);
487
		ISystemResourceSet tempObjects2 = srcAdapter2.doDrag(fromSet2, mon);
488
		UniversalFileTransferUtility.uploadResourcesFromWorkspace((SystemWorkspaceResourceSet)tempObjects2, tempDir, mon, true);
489
		
490
		//now, create tar file in the host
491
		IRemoteFile tarSource = createFileOrFolder(tempDir.getAbsolutePath(), tarSourceFileName1, false);
492
		assertNotNull(tarSource);
493
		IRemoteFile tarSourceFolder1 = (IRemoteFile)getChildFromFolder(tempDir, tarSourceFolderName1); 
494
		assertNotNull(tarSourceFolder1);
495
		IRemoteFile tarSourceFolder2 = (IRemoteFile)getChildFromFolder(tempDir, tarSourceFolderName2);
496
		fss.copy(tarSourceFolder1, tarSource, tarSourceFolderName1, mon);
497
		fss.copy(tarSourceFolder2, tarSource, tarSourceFolderName2, mon);
498
	}
499
	
500
	public void testCreateTarFile() throws Exception {
501
		//-test-author-:XuanChen
502
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
503
		
504
		//Create the zip file first.
505
		IRemoteFile newArchiveFile = createFileOrFolder(tempDirPath, testName, false);
506
		assertNotNull(newArchiveFile);
507
		assertTrue(newArchiveFile.exists());
508
		assertTrue(newArchiveFile.canRead());
509
		assertTrue(newArchiveFile.canWrite());
510
		assertEquals(newArchiveFile.getName(), testName);
511
		assertEquals(newArchiveFile.getParentPath(), tempDirPath);
512
		
513
		//fss.resolveFilterString(filterString, monitor)
514
		
515
		//Now, we want to create a text file inside.
516
		String childName = "aaa.txt";
517
		IRemoteFile file1 = createFileOrFolder(newArchiveFile.getAbsolutePath(), childName, false);
518
		assertNotNull(file1);
519
		
520
		childName = "bbb.txt";
521
		IRemoteFile file2 = createFileOrFolder(newArchiveFile.getAbsolutePath(), childName, false);
522
		assertNotNull(file2);
523
		
524
		//Create a folder
525
		childName = "folder1";
526
		IRemoteFile folder1 = createFileOrFolder(newArchiveFile.getAbsolutePath(), childName, true);
527
		assertNotNull(folder1);
528
		
529
		//Now, check the contents
530
		String[] namesToCheck = {"aaa.txt", "bbb.txt", "folder1"};
531
		int[] typesToCheck = {TYPE_FILE, TYPE_FILE, TYPE_FOLDER};
532
		checkFolderContents(newArchiveFile, namesToCheck, typesToCheck);
533
		
534
		//Now, create some files inside the folder.
535
		String secondLevelChildName = "ccc.exe";
536
		IRemoteFile levelTwoChild1 = createFileOrFolder(folder1.getAbsolutePath(), secondLevelChildName, false);
537
		assertNotNull(levelTwoChild1);
538
		
539
		secondLevelChildName = "ddd.bat";
540
		IRemoteFile levelTwoChild2 = createFileOrFolder(folder1.getAbsolutePath(), secondLevelChildName, false);
541
		assertNotNull(levelTwoChild2);
542
		
543
		secondLevelChildName = "another Folder"; //folder with space
544
		IRemoteFile levelTwoChild3 = createFileOrFolder(folder1.getAbsolutePath(), secondLevelChildName, true);
545
		assertNotNull(levelTwoChild3);
546
		
547
		//Now, check the contents
548
		String[] namesToCheck1 = {"ccc.exe", "ddd.bat", "another Folder"};
549
		int[] typesToCheck1 = {TYPE_FILE, TYPE_FILE, TYPE_FOLDER};
550
		checkFolderContents(folder1, namesToCheck1, typesToCheck1);
551
	}
552
	
553
	public void testCopyToTarArchiveFile() throws Exception {
554
		//-test-author-:XuanChen
555
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
556
		
557
		//create the source for testing first
558
		createSourceTarFiles();
559
		createSourceFolders();
560
		
561
		String tarTargetFileName = tarSourceFileName1;
562
		IRemoteFile targetTarFile = (IRemoteFile)getChildFromFolder(tempDir, tarTargetFileName);
563
		assertNotNull(targetTarFile);
564
		
565
		String sourceFolderName = folderToCopyName3;
566
		IRemoteFile sourceFolder = (IRemoteFile)getChildFromFolder(tempDir, sourceFolderName);
567
		assertNotNull(sourceFolder);
568
		
569
		//Now, copy one of the folder from the sourceFolder into copiedTargetZipFile
570
		fss.copy(sourceFolder, targetTarFile, sourceFolder.getName(), mon);
571
		
572
		Object theCopiedChild = getChildFromFolder(targetTarFile, sourceFolderName);
573
		
574
		assertNotNull(theCopiedChild);
575
		
576
		//Also make sure the copied child has the right contents.
577
		String[] childrenToCheck = {"aaaaaaaa", "aaaab", "epdcdump01.hex12a", "RSE-SDK-2.0RC1.zip"};
578
		
579
		int[] typesToCheck = {TYPE_FOLDER, TYPE_FOLDER, TYPE_FILE, TYPE_FILE};
580
		checkFolderContents((IRemoteFile)theCopiedChild, childrenToCheck, typesToCheck);
581
	}
582
583
584
585
	public void testCopyTarVirtualFile() throws Exception {
586
		//-test-author-:XuanChen
587
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
588
		
589
		//create the source for testing first
590
		createSourceTarFiles();
591
		
592
		String sourceFileName = tarSourceFileName1;
593
		IRemoteFile sourceTarFile = (IRemoteFile)getChildFromFolder(tempDir, sourceFileName);
594
		assertNotNull(sourceTarFile);
595
		
596
		//then, create a folder inside the tempDir
597
		String folderName = "folder1";
598
		IRemoteFile folder1 = createFileOrFolder(tempDirPath, folderName, true);
599
		assertNotNull(folder1);
600
		
601
		//Get one of its fourth level children, and copy the folder to there.
602
		IRemoteFile firstLevelChild = (IRemoteFile)getChildFromFolder(sourceTarFile, tarSourceFolderName1);
603
		assertNotNull(firstLevelChild);
604
		
605
		fss.copy(firstLevelChild, folder1, tarSourceFolderName1, mon);
606
		
607
		Object copiedVirtualFolder = getChildFromFolder(folder1, tarSourceFolderName1);
608
		assertNotNull(copiedVirtualFolder);
609
		
610
		String[] contents = {"MANIFEST.MF"};
611
		int[] typesToCheck = {TYPE_FILE};
612
		checkFolderContents((IRemoteFile)copiedVirtualFolder, contents, typesToCheck);
613
	}
614
615
616
	public void testMoveToTarArchiveFile() throws Exception {
617
		//-test-author-:XuanChen
618
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
619
		
620
		//create the source for testing first
621
		createSourceTarFiles();
622
		createSourceFolders();
623
		
624
		String tarTargetFileName = tarSourceFileName1;
625
		IRemoteFile targetTarFile = (IRemoteFile)getChildFromFolder(tempDir, tarTargetFileName);
626
		assertNotNull(targetTarFile);
627
		
628
		String sourceFolderName = folderToCopyName3;
629
		IRemoteFile sourceFolder = (IRemoteFile)getChildFromFolder(tempDir, sourceFolderName);
630
		assertNotNull(sourceFolder);
631
		
632
		fss.move(sourceFolder, targetTarFile, sourceFolder.getName(), mon);
633
		
634
		Object theMovedChild = getChildFromFolder(targetTarFile, sourceFolderName);
635
		
636
		assertNotNull(theMovedChild);
637
		
638
		//Also make sure the copied child has the right contents.
639
		String[] childrenToCheck = {"aaaaaaaa", "aaaab", "epdcdump01.hex12a", "RSE-SDK-2.0RC1.zip"};
640
		
641
		int[] typesToCheck = {TYPE_FOLDER, TYPE_FOLDER, TYPE_FILE, TYPE_FILE};
642
		checkFolderContents((IRemoteFile)theMovedChild, childrenToCheck, typesToCheck);
643
		
644
		//make sure the original folder is gone.
645
		Object originalSource = getChildFromFolder(tempDir, sourceFolderName);
646
		assertNull(originalSource);
647
	}
648
649
650
651
	public void testMoveTarVirtualFile() throws Exception {
652
		//-test-author-:XuanChen
653
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
654
		
655
		//create the source for testing first
656
		createSourceTarFiles();
657
		
658
		String sourceFileName = tarSourceFileName1;
659
		IRemoteFile sourceTarFile = (IRemoteFile)getChildFromFolder(tempDir, sourceFileName);
660
		assertNotNull(sourceTarFile);
661
		
662
		//then, create a folder inside the tempDir
663
		//then, create a folder inside the tempDir
664
		String folderName = "folder1";
665
		IRemoteFile folder1 = createFileOrFolder(tempDirPath, folderName, true);
666
		assertNotNull(folder1);
667
		
668
		//Now, copy one of the folder from the zip file into folder1
669
		String movedFolderName = tarSourceFolderName1;
670
		IRemoteFile firstLevelChild = (IRemoteFile)getChildFromFolder(sourceTarFile, tarSourceFolderName1);
671
		assertNotNull(firstLevelChild);
672
		fss.move(firstLevelChild, folder1, movedFolderName, mon);
673
		
674
		Object movedVirtualFolder = getChildFromFolder(folder1, movedFolderName);
675
		
676
		assertNotNull(movedVirtualFolder);
677
		
678
		String[] contents = {"MANIFEST.MF"};
679
		int[] typesToCheck = {TYPE_FILE};
680
		checkFolderContents((IRemoteFile)movedVirtualFolder, contents, typesToCheck);
681
		
682
		//Now, make sure the moved virtual folder is gone from its original zip file
683
		IRemoteFile tmp = (IRemoteFile)getChildFromFolder(sourceTarFile, tarSourceFolderName1);
684
		assertNull(tmp);
685
	}
686
687
688
	public void testRenameTarVirtualFile() throws Exception {
689
		//-test-author-:XuanChen
690
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
691
		
692
		//Create the zip file first.
693
		IRemoteFile newArchiveFile = createFileOrFolder(tempDirPath, testName, false);
694
		
695
		//Now, we want to create a text file inside.
696
		String childName = "aaa.txt";
697
		IRemoteFile file1 = createFileOrFolder(newArchiveFile.getAbsolutePath(), childName, false);
698
		assertNotNull(file1);
699
		
700
		childName = "bbb.txt";
701
		IRemoteFile file2 = createFileOrFolder(newArchiveFile.getAbsolutePath(), childName, false);
702
		assertNotNull(file2);
703
		
704
		//Create a folder
705
		childName = "folder1";
706
		IRemoteFile folder1 = createFileOrFolder(newArchiveFile.getAbsolutePath(), childName, true);
707
		assertNotNull(folder1);
708
		
709
		//Now, check the contents
710
		String[] levelOneNamesToCheck = {"aaa.txt", "bbb.txt", "folder1"};
711
		int[] levalOneTypesToCheck = {TYPE_FILE, TYPE_FILE, TYPE_FOLDER};
712
		checkFolderContents(newArchiveFile, levelOneNamesToCheck, levalOneTypesToCheck);
713
		
714
		//Now, create some files inside the folder.
715
		String secondLevelChildName = "ccc.exe";
716
		IRemoteFile levelTwoChild1 = createFileOrFolder(folder1.getAbsolutePath(), secondLevelChildName, false);
717
		assertNotNull(levelTwoChild1);
718
		
719
		secondLevelChildName = "ddd.bat";
720
		IRemoteFile levelTwoChild2 = createFileOrFolder(folder1.getAbsolutePath(), secondLevelChildName, false);
721
		assertNotNull(levelTwoChild2);
722
		
723
		secondLevelChildName = "another Folder"; //folder with space
724
		IRemoteFile levelTwoChild3 = createFileOrFolder(folder1.getAbsolutePath(), secondLevelChildName, true);
725
		assertNotNull(levelTwoChild3);
726
		
727
		//Now, check the contents
728
		String[] levelTwoNamesToCheck = {"ccc.exe", "ddd.bat", "another Folder"};
729
		int[] levalTwoTypesToCheck = {TYPE_FILE, TYPE_FILE, TYPE_FOLDER};
730
		checkFolderContents(folder1, levelTwoNamesToCheck, levalTwoTypesToCheck);
731
		
732
		//Now rename one of the text file in the first level:
733
		IRemoteFile childToRename = (IRemoteFile)getChildFromFolder(newArchiveFile, "aaa.txt");
734
		fss.rename(childToRename, "aaa1.txt", mon);
735
		//Now rename one of the folder in the first level
736
		childToRename = (IRemoteFile)getChildFromFolder(newArchiveFile, "folder1");
737
		fss.rename(childToRename, "folder2", mon);
738
		
739
		//Check the result of rename
740
		String[] newLevelOneNamesToCheck = {"aaa1.txt", "bbb.txt", "folder2"};
741
		checkFolderContents(newArchiveFile, newLevelOneNamesToCheck, levalOneTypesToCheck);
742
		
743
		//Now rename one of the text file in the second level:
744
		IRemoteFile thisFolder = (IRemoteFile)getChildFromFolder(newArchiveFile, "folder2");
745
		childToRename = (IRemoteFile)getChildFromFolder(thisFolder, "ddd.bat");
746
		fss.rename(childToRename, "ddd1.bat", mon);
747
		//Now rename one of the folder in the second level
748
		childToRename = (IRemoteFile)getChildFromFolder(thisFolder, "another Folder");
749
		fss.rename(childToRename, "some folder$", mon);
750
		
751
		//Check the result of rename
752
		String[] newLevelTwoNamesToCheck = {"ccc.exe", "ddd1.bat", "some folder$"};
753
		checkFolderContents(thisFolder, newLevelTwoNamesToCheck, levalTwoTypesToCheck);
754
	}
755
756
	public void testDeleteTarVirtualFile() throws Exception {
757
		//-test-author-:XuanChen
758
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
759
		
760
		//create the source for testing first
761
		createSourceTarFiles();
762
		
763
		String sourceFileName = tarSourceFileName1;
764
		IRemoteFile sourceTarFile = (IRemoteFile)getChildFromFolder(tempDir, sourceFileName);
765
		assertNotNull(sourceTarFile);
766
		
767
		//delete a file from level 2
768
		String parentForFileToDeleteName ="META-INF";
769
		IRemoteFile parentForFileToDelete = (IRemoteFile)getChildFromFolder(sourceTarFile, parentForFileToDeleteName);
770
		assertNotNull(parentForFileToDelete);
771
		String deleteFileName = "MANIFEST.MF";
772
		IRemoteFile fileToToDelete = (IRemoteFile)getChildFromFolder(parentForFileToDelete, deleteFileName);
773
		assertNotNull(fileToToDelete);
774
		//Now, delete this file
775
		fss.delete(fileToToDelete, mon);
776
		fileToToDelete = (IRemoteFile)getChildFromFolder(parentForFileToDelete, deleteFileName);
777
		assertNull(fileToToDelete);
778
		
779
		//then, get directory "java" under org/eclipse/dstore/core
780
		String parentForDirectoryToDeleteName ="org";
781
		IRemoteFile parentForDirectoryToDelete = (IRemoteFile)getChildFromFolder(sourceTarFile, parentForDirectoryToDeleteName);
782
		assertNotNull(parentForDirectoryToDelete);
783
		
784
		parentForDirectoryToDeleteName ="eclipse";
785
		parentForDirectoryToDelete = (IRemoteFile)getChildFromFolder(parentForDirectoryToDelete, parentForDirectoryToDeleteName);
786
		assertNotNull(parentForDirectoryToDelete);
787
		
788
		parentForDirectoryToDeleteName ="dstore";
789
		parentForDirectoryToDelete = (IRemoteFile)getChildFromFolder(parentForDirectoryToDelete, parentForDirectoryToDeleteName);
790
		assertNotNull(parentForDirectoryToDelete);
791
		
792
		parentForDirectoryToDeleteName ="core";
793
		parentForDirectoryToDelete = (IRemoteFile)getChildFromFolder(parentForDirectoryToDelete, parentForDirectoryToDeleteName);
794
		assertNotNull(parentForDirectoryToDelete);
795
		
796
		String directoryToDeleteName = "java";
797
		IRemoteFile directoryToDelete = (IRemoteFile)getChildFromFolder(parentForDirectoryToDelete, directoryToDeleteName);
798
		//Now, delete this directory
799
		fss.delete(directoryToDelete, mon);
800
		directoryToDelete = (IRemoteFile)getChildFromFolder(parentForDirectoryToDelete, directoryToDeleteName);
801
		
802
		//check result of this operation
803
		String[] contents = {"client", "miners", "model", "server", "util", "Activator.java"};
804
		int[] typesToCheck = {TYPE_FOLDER, TYPE_FOLDER, TYPE_FOLDER, TYPE_FOLDER, TYPE_FOLDER, TYPE_FILE};
805
		checkFolderContents(parentForDirectoryToDelete, contents, typesToCheck);
806
		
807
		//And check this directory is not there any more.
808
		directoryToDelete = (IRemoteFile)getChildFromFolder(parentForDirectoryToDelete, directoryToDeleteName);
809
		assertNull(directoryToDelete);
810
		
811
		//Now, delete some files and folder inside the a virtual folder.
812
		parentForFileToDelete = (IRemoteFile)getChildFromFolder(parentForDirectoryToDelete, "model");
813
		deleteFileName = "DE.java";
814
		fileToToDelete = (IRemoteFile)getChildFromFolder(parentForFileToDelete, deleteFileName);
815
		assertNotNull(fileToToDelete);
816
		
817
		fss.delete(fileToToDelete, mon);
818
		
819
		//check the result
820
		fileToToDelete = (IRemoteFile)getChildFromFolder(parentForFileToDelete, deleteFileName);
821
		
822
		assertNull(fileToToDelete);
823
	}
824
825
826
827
	public void testCopyBatchToTarArchiveFile() throws Exception {
828
		//-test-author-:XuanChen
829
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
830
		
831
		createSourceTarFiles();
832
		createSourceFolders();
833
		
834
		String tarTargetFileName = tarSourceFileName1;
835
		IRemoteFile targetTarFile = (IRemoteFile)getChildFromFolder(tempDir, tarTargetFileName);
836
		assertNotNull(targetTarFile);
837
		
838
		//Now, copy the source folder.
839
		String sourceFolderName = folderToCopyName3;
840
		IRemoteFile sourceFolder = (IRemoteFile)getChildFromFolder(tempDir,sourceFolderName);
841
		assertNotNull(sourceFolder);
842
		
843
		//Now, copy one of the folder from the sourceFolder into copiedTargetZipFile
844
		IRemoteFile[] sourceFiles = new IRemoteFile[3];
845
		//Also add some of its children into the batch.
846
		String childToCopyName1 = "aaaaaaaa";
847
		sourceFiles[0] = (IRemoteFile)getChildFromFolder(sourceFolder, childToCopyName1);
848
		String childToCopyName2 = "aaaab";
849
		sourceFiles[1] = (IRemoteFile)getChildFromFolder(sourceFolder, childToCopyName2);
850
		String childToCopyName3 = "epdcdump01.hex12a";
851
		sourceFiles[2] = (IRemoteFile)getChildFromFolder(sourceFolder, childToCopyName3);
852
		fss.copyBatch(sourceFiles, targetTarFile, mon);
853
		
854
		//Checking the first copied folder
855
		Object theCopiedChild = getChildFromFolder(targetTarFile, childToCopyName1);
856
		
857
		assertNotNull(theCopiedChild);
858
		
859
		//Also make sure the copied child has the right contents.
860
		String[] childrenToCheck1 = {"adsf", "eclipse-SDK-3.3M6-win32.zip", "epdcdump01.hex12", "epdcdump01.hex12aaaa"};
861
		
862
		int[] typesToCheck1 = {TYPE_FILE, TYPE_FILE, TYPE_FILE, TYPE_FILE};
863
		checkFolderContents((IRemoteFile)theCopiedChild, childrenToCheck1, typesToCheck1);
864
		
865
		//Checking the second copied folder
866
		theCopiedChild = getChildFromFolder(targetTarFile, childToCopyName2);
867
		
868
		assertNotNull(theCopiedChild);
869
		
870
		//Also make sure the copied child has the right contents.
871
		String[] childrenToCheck2 = {"features"};
872
		
873
		int[] typesToCheck2 = {TYPE_FOLDER};
874
		checkFolderContents((IRemoteFile)theCopiedChild, childrenToCheck2, typesToCheck2);
875
		
876
		//Checking the third copied file
877
		theCopiedChild = getChildFromFolder(targetTarFile, childToCopyName3);
878
		assertNotNull(theCopiedChild);
879
		assertTrue(((IRemoteFile)theCopiedChild).isDirectory() != true);
880
	}
881
882
883
884
885
	public void testOpenFileFromTarArchive() throws Exception {
886
		if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$
887
		
888
		//create the source for testing first
889
		createTarSourceForOpen();
890
		
891
		String tarTargetFileName = tarSourceForOpenTest;
892
		IRemoteFile targetTarFile = (IRemoteFile)getChildFromFolder(tempDir, tarTargetFileName);
893
		assertNotNull(targetTarFile);
894
		
895
		//Now get the contents of the virtual file we want to download:
896
		String fileContentToVerifyName1 = "MANIFEST.MF";
897
		
898
		//Get its parent first.
899
		IRemoteFile itsParentFolder = (IRemoteFile)getChildFromFolder(tempDir,tarSourceForOpenFolderName1);
900
		assertNotNull(itsParentFolder);
901
		
902
		//Then get this file:
903
		IRemoteFile thisVirtualFile = (IRemoteFile)getChildFromFolder(itsParentFolder, fileContentToVerifyName1);
904
		assertNotNull(thisVirtualFile);
905
		
906
		//Now, we want to download the content of this file
907
		//We could just construct a dummy localpath for it.
908
		String tempPath = getWorkspace().getRoot().getLocation().append("temp").toString();
909
		IFileStore temp = createDir(tempPath, true);
910
		String localPath = tempPath + File.separator + fileContentToVerifyName1;
911
		fss.download(thisVirtualFile, localPath, thisVirtualFile.getEncoding(), mon);
912
		
913
		//now, verify the content of the local file
914
		IFileStore localFile = temp.getChild(fileContentToVerifyName1);
915
		//Check the content of the download file:
916
		boolean sameContent = compareContent(getContents(fileContentString1), localFile.openInputStream(EFS.NONE, null));
917
		assertTrue(sameContent);
918
		
919
		
920
		//now, we got the contents of another virtual file we want to download:
921
		String fileContentToVerifyName2 = "Activator.java";
922
		itsParentFolder = (IRemoteFile)getChildFromFolder(tempDir,tarSourceForOpenFolderName2);
923
		assertNotNull(itsParentFolder);
924
		itsParentFolder = (IRemoteFile)getChildFromFolder(itsParentFolder,"eclipse");
925
		assertNotNull(itsParentFolder);
926
		itsParentFolder = (IRemoteFile)getChildFromFolder(itsParentFolder,"dstore");
927
		assertNotNull(itsParentFolder);
928
		itsParentFolder = (IRemoteFile)getChildFromFolder(itsParentFolder,"core");
929
		assertNotNull(itsParentFolder);
930
		thisVirtualFile = (IRemoteFile)getChildFromFolder(itsParentFolder, fileContentToVerifyName2);
931
		assertNotNull(thisVirtualFile);
932
		localPath = tempPath + File.separator + fileContentToVerifyName2;
933
		fss.download(thisVirtualFile, localPath, thisVirtualFile.getEncoding(), mon);
934
		
935
		//now, verify the content of the local file
936
		localFile = temp.getChild(fileContentToVerifyName2);
937
		//Check the content of the download file:
938
		sameContent = compareContent(getContents(fileContentString1), localFile.openInputStream(EFS.NONE, null));
939
		assertTrue(sameContent);
940
	}
941
	
942
943
944
945
}
(-)src/org/eclipse/rse/tests/subsystems/files/FileServiceTgzArchiveTest.java (+26 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(String name) {
19
		super(name);
20
		tarSourceFileName1 = "source.tar.gz";
21
		tarSourceFileName2 = "mynewtar.tgz";
22
		tarSourceForOpenTest = "tarSourceForOpen.TAR.gz";
23
		testName = "dummy.tGz";
24
	}
25
26
}
(-)miners/org/eclipse/rse/dstore/universal/miners/UniversalFileSystemMiner.java (-7 / +11 lines)
Lines 15-34 Link Here
15
 * Martin Oberhuber (Wind River) - Fix 154874 - handle files with space or $ in the name 
15
 * Martin Oberhuber (Wind River) - Fix 154874 - handle files with space or $ in the name 
16
 * Xuan Chen (IBM) - Fix 160768 - [refresh][dstore] Refresh on renamed node within a zip does not work; 
16
 * Xuan Chen (IBM) - Fix 160768 - [refresh][dstore] Refresh on renamed node within a zip does not work; 
17
 * Xuan Chen (IBM) - Fix 189487 - copy and paste a folder did not work - workbench hang
17
 * Xuan Chen (IBM) - Fix 189487 - copy and paste a folder did not work - workbench hang
18
 * Xuan Chen (IBM)        - [189681] [dstore][linux] Refresh Folder in My Home messes up Refresh in Root
18
 * Xuan Chen (IBM) - [189681] [dstore][linux] Refresh Folder in My Home messes up Refresh in Root
19
 * Xuan Chen (IBM)        - [191280] [dstore] Expand fails for folder "/folk" with 3361 children
19
 * Xuan Chen (IBM) - [191280] [dstore] Expand fails for folder "/folk" with 3361 children
20
 * Kevin Doyle (IBM) - [195709] Windows Copying doesn't work when path contains space
20
 * Kevin Doyle (IBM) - [195709] Windows Copying doesn't work when path contains space
21
 * Kevin Doyle (IBM) - [196211] DStore Move tries rename if that fails copy/delete
21
 * Kevin Doyle (IBM) - [196211] DStore Move tries rename if that fails copy/delete
22
 * Xuan Chen (IBM)        - [198046] [dstore] Cannot copy a folder into an archive file
22
 * Xuan Chen (IBM) - [198046] [dstore] Cannot copy a folder into an archive file
23
 * Xuan Chen (IBM)        - [191367] with supertransfer on, Drag & Drop Folder from DStore to DStore doesn't work
23
 * Xuan Chen (IBM) - [191367] with supertransfer on, Drag & Drop Folder from DStore to DStore doesn't work
24
 * Martin Oberhuber (Wind River) - [199548] Avoid touching files on setReadOnly() if unnecessary
24
 * Martin Oberhuber (Wind River) - [199548] Avoid touching files on setReadOnly() if unnecessary
25
 * Kevin Doyle (IBM) - [191548]  Deleting Read-Only directory removes it from view and displays no error
25
 * Kevin Doyle (IBM) - [191548]  Deleting Read-Only directory removes it from view and displays no error
26
 * Xuan Chen (IBM)        - [202949] [archives] copy a folder from one connection to an archive file in a different connection does not work
26
 * Xuan Chen (IBM) - [202949] [archives] copy a folder from one connection to an archive file in a different connection does not work
27
 * Xuan Chen (IBM) - [160775] [api] rename (at least within a zip) blocks UI thread
27
 * Xuan Chen (IBM) - [160775] [api] rename (at least within a zip) blocks UI thread
28
 * David McKnight   (IBM)        - [196624] dstore miner IDs should be String constants rather than dynamic lookup
28
 * David McKnight (IBM) - [196624] dstore miner IDs should be String constants rather than dynamic lookup
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 69-74 Link Here
69
import org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler;
70
import org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler;
70
import org.eclipse.rse.services.clientserver.archiveutils.SystemJarHandler;
71
import org.eclipse.rse.services.clientserver.archiveutils.SystemJarHandler;
71
import org.eclipse.rse.services.clientserver.archiveutils.SystemTarHandler;
72
import org.eclipse.rse.services.clientserver.archiveutils.SystemTarHandler;
73
import org.eclipse.rse.services.clientserver.archiveutils.SystemTgzHandler;
72
import org.eclipse.rse.services.clientserver.archiveutils.SystemZipHandler;
74
import org.eclipse.rse.services.clientserver.archiveutils.SystemZipHandler;
73
import org.eclipse.rse.services.clientserver.archiveutils.VirtualChild;
75
import org.eclipse.rse.services.clientserver.archiveutils.VirtualChild;
74
import org.eclipse.rse.services.clientserver.java.ClassFileUtil;
76
import org.eclipse.rse.services.clientserver.java.ClassFileUtil;
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
(-)plugin.xml (-4 / +16 lines)
Lines 1-6 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
2
<!--
3
Copyright (c) 2006, 2007 IBM Corporation and others. All rights reserved.
3
Copyright (c) 2006, 2008 IBM Corporation and others. All rights reserved.
4
This program and the accompanying materials are made available under the terms
4
This program and the accompanying materials are made available under the terms
5
of the Eclipse Public License v1.0 which accompanies this distribution, and is 
5
of the Eclipse Public License v1.0 which accompanies this distribution, and is 
6
available at http://www.eclipse.org/legal/epl-v10.html
6
available at http://www.eclipse.org/legal/epl-v10.html
Lines 15-23 Link Here
15
Martin Oberhuber (Wind River) - [180519] declaratively register adapter factories
15
Martin Oberhuber (Wind River) - [180519] declaratively register adapter factories
16
Martin Oberhuber (Wind River) - [168975] Move RSE Events API to Core
16
Martin Oberhuber (Wind River) - [168975] Move RSE Events API to Core
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.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.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"
(-)clientserver/org/eclipse/rse/services/clientserver/archiveutils/ArchiveHandlerManager.java (-17 / +50 lines)
Lines 12-22 Link Here
12
 * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
12
 * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
13
 * 
13
 * 
14
 * Contributors:
14
 * Contributors:
15
 * {Name} (company) - description of contribution.
15
 * Xuan Chen (IBM) - [194293] [Local][Archives] Saving file second time in an Archive Errors
16
 * Xuan Chen        (IBM)        - [194293] [Local][Archives] Saving file second time in an Archive Errors
16
 * 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
17
 * 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
18
 * 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)
19
 * Johnson Ma (Wind River) - [195402] [api] add tar.gz archive support
20
 *******************************************************************************/
20
 *******************************************************************************/
21
21
22
package org.eclipse.rse.services.clientserver.archiveutils;
22
package org.eclipse.rse.services.clientserver.archiveutils;
Lines 25-30 Link Here
25
import java.lang.reflect.Constructor;
25
import java.lang.reflect.Constructor;
26
import java.lang.reflect.InvocationTargetException;
26
import java.lang.reflect.InvocationTargetException;
27
import java.util.HashMap;
27
import java.util.HashMap;
28
import java.util.Iterator;
28
29
29
/**
30
/**
30
 * This class manages all the Archive Handlers that correspond to the archive file that the system
31
 * 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$
41
	public static final String VIRTUAL_SEPARATOR = "#virtual#/"; //$NON-NLS-1$
41
	public static final String VIRTUAL_CANONICAL_SEPARATOR = "#virtual#"; //$NON-NLS-1$
42
	public static final String VIRTUAL_CANONICAL_SEPARATOR = "#virtual#"; //$NON-NLS-1$
42
	public static final String VIRTUAL_FOLDER_SEPARATOR = "/"; //$NON-NLS-1$
43
	public static final String VIRTUAL_FOLDER_SEPARATOR = "/"; //$NON-NLS-1$
44
	public static final String EXTENSION_SEPARATOR = "."; //$NON-NLS-1$
43
	
45
	
44
	//	the singleton instance
46
	//	the singleton instance
45
	protected static ArchiveHandlerManager _instance = new ArchiveHandlerManager(); 
47
	protected static ArchiveHandlerManager _instance = new ArchiveHandlerManager(); 
Lines 116-122 Link Here
116
		}
118
		}
117
		else
119
		else
118
		{
120
		{
119
			if (_handlerTypes.containsKey(getExtension(file)))
121
			if (getRegisteredExtension(file)!=null)
120
			{
122
			{
121
				return true;
123
				return true;
122
			}
124
			}
Lines 136-155 Link Here
136
	 */
138
	 */
137
	public boolean isRegisteredArchive(String filename)
139
	public boolean isRegisteredArchive(String filename)
138
	{
140
	{
139
		if (_handlerTypes.containsKey(getExtension(filename)))
141
		return getRegisteredExtension(filename) == null?false:true;
140
		{
142
	}	
141
			return true;
143
	
142
		}
144
	/**
143
		else
145
	 * check if the file extension is registered archive type. 
146
	 * notice here, the getExtension method does't work for name like fool.tar.gz
147
	 * @param file the file to check
148
	 * @return registered extension or null
149
	 * @since 3.0
150
	 */
151
	protected String getRegisteredExtension(File file) 
152
	{
153
		String fileName = file.getName();
154
		return getRegisteredExtension(fileName);
155
	}
156
	
157
	/**
158
	 * check if the file extension is registered archive type. 
159
	 * @param fileName the file name to check
160
	 * @return registered extension or null
161
	 * @since 3.0
162
	 */
163
	protected String getRegisteredExtension(String fileName) 
164
	{
165
		fileName = fileName.toLowerCase();
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
Lines 375-381 Link Here
375
			//need to process it.
408
			//need to process it.
376
			//But virtual path should neither start with "\", nor contains
409
			//But virtual path should neither start with "\", nor contains
377
			//":".  So for those two cases, we could just return the fullVirtualName
410
			//":".  So for those two cases, we could just return the fullVirtualName
378
			if (fullVirtualName.indexOf(":") != -1 || fullVirtualName.trim().startsWith("\\"))
411
			if (fullVirtualName.indexOf(":") != -1 || fullVirtualName.trim().startsWith("\\")) //$NON-NLS-1$ //$NON-NLS-2$
379
			{
412
			{
380
				return fullVirtualName; 
413
				return fullVirtualName; 
381
			}
414
			}
(-)clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemTarHandler.java (-16 / +31 lines)
Lines 12-27 Link Here
12
 * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
12
 * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
13
 * 
13
 * 
14
 * Contributors:
14
 * Contributors:
15
 * Xuan Chen        (IBM)        - [194293] [Local][Archives] Saving file second time in an Archive Errors
15
 * Xuan Chen (IBM) - [194293] [Local][Archives] Saving file second time in an Archive Errors
16
 * Xuan Chen        (IBM)        - [199132] [Archives-TAR][Local-Windows] Can't open files in tar archives
16
 * Xuan Chen (IBM) - [199132] [Archives-TAR][Local-Windows] Can't open files in tar archives
17
 * Xuan Chen        (IBM)        - [160775] [api] rename (at least within a zip) blocks UI thread
17
 * Xuan Chen (IBM) - [160775] [api] rename (at least within a zip) blocks UI thread
18
 * Xuan Chen        (IBM)        - [209828] Need to move the Create operation to a job.
18
 * Xuan Chen (IBM) - [209828] Need to move the Create operation to a job.
19
 * Xuan Chen        (IBM)        - [209825] Update SystemTarHandler so that archive operations could be cancelable.
19
 * Xuan Chen (IBM) - [209825] Update SystemTarHandler so that archive operations could be cancelable.
20
 * Xuan Chen        (IBM)        - [211551] NPE when moving multiple folders from one tar file to another tar file
20
 * Xuan Chen (IBM) - [211551] NPE when moving multiple folders from one tar file to another tar file
21
 * Xuan Chen        (IBM)        - [211653] Copy virtual directory with nested directory of tar file did not work
21
 * Xuan Chen (IBM) - [211653] Copy virtual directory with nested directory of tar file did not work
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 for a given file. 
2617
	 * This method can be overridden 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 (-2 / +3 lines)
Lines 12-19 Link Here
12
 * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
12
 * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
13
 * 
13
 * 
14
 * Contributors:
14
 * Contributors:
15
 * {Name} (company) - description of contribution.
16
 * Xuan Chen (IBM) - [api] SystemTarHandler has inconsistent API
15
 * Xuan Chen (IBM) - [api] SystemTarHandler has inconsistent API
16
 * Johnson Ma (Wind River) - [195402] Add tar.gz archive support
17
 *******************************************************************************/
17
 *******************************************************************************/
18
18
19
package org.eclipse.rse.services.clientserver.archiveutils;
19
package org.eclipse.rse.services.clientserver.archiveutils;
Lines 197-204 Link Here
197
	 * Gets the input stream for the tar file.
197
	 * Gets the input stream for the tar file.
198
	 * @return the input stream for the tar file.
198
	 * @return the input stream for the tar file.
199
	 * @throws FileNotFoundException if the file does not exist.
199
	 * @throws FileNotFoundException if the file does not exist.
200
	 * @since 3.0
200
	 */
201
	 */
201
	private InputStream getInputStream() throws FileNotFoundException {
202
	protected InputStream getInputStream() throws FileNotFoundException {
202
		FileInputStream stream = new FileInputStream(file);
203
		FileInputStream stream = new FileInputStream(file);
203
		return stream;
204
		return stream;
204
	}
205
	}
(-)clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemZipHandler.java (-5 / +6 lines)
Lines 1389-1396 Link Here
1389
	 * @param dest The ZipOutputStream representing the zip file where the
1389
	 * @param dest The ZipOutputStream representing the zip file where the
1390
	 * children are to be recreated
1390
	 * children are to be recreated
1391
	 * @param omitChildren The set of names of children to omit when creating
1391
	 * @param omitChildren The set of names of children to omit when creating
1392
	 * the zipfile. Null or empty set if there are no ommisions.
1392
	 * the zipfile. Null or empty set if there are no omissions.
1393
	 * @throws IOException
1393
	 * @throws IOException in case of a file I/O error
1394
	 */
1394
	 */
1395
	protected boolean recreateZipDeleteEntries(VirtualChild[] vcList, ZipOutputStream dest, HashSet omitChildren, ISystemOperationMonitor archiveOperationMonitor) throws IOException
1395
	protected boolean recreateZipDeleteEntries(VirtualChild[] vcList, ZipOutputStream dest, HashSet omitChildren, ISystemOperationMonitor archiveOperationMonitor) throws IOException
1396
	{
1396
	{
Lines 2563-2570 Link Here
2563
		return ""; //$NON-NLS-1$
2563
		return ""; //$NON-NLS-1$
2564
	}
2564
	}
2565
2565
2566
	/**
2566
	/*
2567
	 * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#isExecutable(java.lang.String)
2567
	 * (non-Javadoc)
2568
	 * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getClassification(java.lang.String)
2568
	 */
2569
	 */
2569
	public String getClassification(String fullVirtualName) {
2570
	public String getClassification(String fullVirtualName) {
2570
		return getClassification(fullVirtualName, true);
2571
		return getClassification(fullVirtualName, true);
Lines 2573-2579 Link Here
2573
	/**
2574
	/**
2574
	 * Same as getClassification(String), but you can choose whether to leave the zip file
2575
	 * Same as getClassification(String), but you can choose whether to leave the zip file
2575
	 * open after the method is closed.
2576
	 * open after the method is closed.
2576
	 * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#isExecutable(java.lang.String)
2577
	 * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getClassification(java.lang.String)
2577
	 */
2578
	 */
2578
	public String getClassification(String fullVirtualName, boolean closeZipFile) {
2579
	public String getClassification(String fullVirtualName, boolean closeZipFile) {
2579
		
2580
		
(-)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/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.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.internal.services.clientserver.archiveutils.TarOutputStream;
20
import org.eclipse.rse.internal.services.clientserver.archiveutils.TgzFile;
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