Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 278402 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ui/internal/wizards/datatransfer/IFileExporter.java (-1 / +12 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2006 IBM Corporation and others.
2
 * Copyright (c) 2004, 2009 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
Lines 12-17 Link Here
12
12
13
import java.io.IOException;
13
import java.io.IOException;
14
14
15
import org.eclipse.core.resources.IContainer;
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.CoreException;
17
18
Lines 32-37 Link Here
32
	public void finished() throws IOException;
33
	public void finished() throws IOException;
33
	
34
	
34
	/**
35
	/**
36
	 * Write the entry for the folder's name into the current archive.
37
	 * 
38
	 * @param container the container to write
39
	 * @param destinationPath the path that will be used in the archive
40
	 * @throws IOException if an IO error occurs while writing the folder entry
41
	 */
42
    public void write(IContainer container, String destinationPath)
43
    	throws IOException;
44
	
45
	/**
35
	 * Write the passed resource to the current archive
46
	 * Write the passed resource to the current archive
36
	 * 
47
	 * 
37
	 * @param resource
48
	 * @param resource
(-)src/org/eclipse/ui/internal/wizards/datatransfer/ZipFileExporter.java (-1 / +8 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 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
Lines 17-22 Link Here
17
import java.util.zip.ZipEntry;
17
import java.util.zip.ZipEntry;
18
import java.util.zip.ZipOutputStream;
18
import java.util.zip.ZipOutputStream;
19
19
20
import org.eclipse.core.resources.IContainer;
20
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.CoreException;
22
23
Lines 99-104 Link Here
99
        outputStream.closeEntry();
100
        outputStream.closeEntry();
100
    }
101
    }
101
102
103
    public void write(IContainer container, String destinationPath)
104
            throws IOException {
105
        ZipEntry newEntry = new ZipEntry(destinationPath);
106
        outputStream.putNextEntry(newEntry);
107
    }
108
102
    /**
109
    /**
103
     *  Write the passed resource to the current archive.
110
     *  Write the passed resource to the current archive.
104
     *
111
     *
(-)src/org/eclipse/ui/internal/wizards/datatransfer/TarFileExporter.java (-1 / +19 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 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
Lines 19-24 Link Here
19
import java.util.zip.GZIPOutputStream;
19
import java.util.zip.GZIPOutputStream;
20
20
21
import org.eclipse.core.filesystem.EFS;
21
import org.eclipse.core.filesystem.EFS;
22
import org.eclipse.core.resources.IContainer;
22
import org.eclipse.core.resources.IFile;
23
import org.eclipse.core.resources.IFile;
23
import org.eclipse.core.resources.IResource;
24
import org.eclipse.core.resources.IResource;
24
import org.eclipse.core.resources.ResourceAttributes;
25
import org.eclipse.core.resources.ResourceAttributes;
Lines 95-100 Link Here
95
    	outputStream.closeEntry();    	
96
    	outputStream.closeEntry();    	
96
    }
97
    }
97
98
99
    public void write(IContainer container, String destinationPath)
100
            throws IOException {
101
        TarEntry newEntry = new TarEntry(destinationPath);
102
        if(container.getLocalTimeStamp() != IResource.NULL_STAMP) {
103
        	newEntry.setTime(container.getLocalTimeStamp() / 1000);
104
        }
105
        ResourceAttributes attributes = container.getResourceAttributes();
106
        if (attributes != null && attributes.isExecutable()) {
107
        	newEntry.setMode(newEntry.getMode() | 0111);
108
        }
109
        if (attributes != null && attributes.isReadOnly()) {
110
        	newEntry.setMode(newEntry.getMode() & ~0222);
111
        }
112
        newEntry.setFileType(TarEntry.DIRECTORY);
113
        outputStream.putNextEntry(newEntry);
114
    }
115
    
98
    /**
116
    /**
99
     *  Write the passed resource to the current archive.
117
     *  Write the passed resource to the current archive.
100
     *
118
     *
(-)src/org/eclipse/ui/internal/wizards/datatransfer/ArchiveFileExportOperation.java (-9 / +27 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 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
Lines 162-167 Link Here
162
            throws InterruptedException {
162
            throws InterruptedException {
163
        exportResource(exportResource, 1);
163
        exportResource(exportResource, 1);
164
    }
164
    }
165
    
166
    /**
167
     * Creates and returns the string that should be used as the name of the entry in the archive.
168
     * 
169
     * @param exportResource the resource to export
170
     * @param leadupDepth the number of resource levels to be included in the path including the resourse itself.
171
     * @since 3.6
172
     */
173
    private String createDestinationName(int leadupDepth, IResource exportResource) {
174
        IPath fullPath = exportResource.getFullPath();
175
        if (createLeadupStructure) {
176
        	return fullPath.makeRelative().toString();
177
        }
178
		return fullPath.removeFirstSegments(
179
                fullPath.segmentCount() - leadupDepth).toString();
180
    }
165
181
166
    /**
182
    /**
167
     *  Export the passed resource to the destination .zip
183
     *  Export the passed resource to the destination .zip
Lines 177-190 Link Here
177
		}
193
		}
178
194
179
        if (exportResource.getType() == IResource.FILE) {
195
        if (exportResource.getType() == IResource.FILE) {
180
            String destinationName;
196
        	String destinationName = createDestinationName(leadupDepth, exportResource);
181
            IPath fullPath = exportResource.getFullPath();
182
            if (createLeadupStructure) {
183
				destinationName = fullPath.makeRelative().toString();
184
			} else {
185
				destinationName = fullPath.removeFirstSegments(
186
                        fullPath.segmentCount() - leadupDepth).toString();
187
			}
188
            monitor.subTask(destinationName);
197
            monitor.subTask(destinationName);
189
198
190
            try {
199
            try {
Lines 198-203 Link Here
198
            monitor.worked(1);
207
            monitor.worked(1);
199
            ModalContext.checkCanceled(monitor);
208
            ModalContext.checkCanceled(monitor);
200
        } else {
209
        } else {
210
    		// create an entry for ourselves, see bug 278402
211
        	String destinationName = createDestinationName(leadupDepth, exportResource);
212
213
            try {
214
        		exporter.write((IContainer) exportResource, destinationName + java.io.File.separator);
215
            } catch (IOException e) {
216
                addError(NLS.bind(DataTransferMessages.DataTransfer_errorExporting, exportResource.getFullPath().makeRelative(), e.getMessage()), e);
217
            }
218
        	
201
            IResource[] children = null;
219
            IResource[] children = null;
202
220
203
            try {
221
            try {
(-)Eclipse UI Tests/org/eclipse/ui/tests/datatransfer/ExportArchiveFileOperationTest.java (-25 / +35 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2006 IBM Corporation and others.
2
 * Copyright (c) 2005, 2009 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
Lines 47-52 Link Here
47
	private static final String ZIP_FILE_EXT = "zip";
47
	private static final String ZIP_FILE_EXT = "zip";
48
	private static final String TAR_FILE_EXT = "tar";
48
	private static final String TAR_FILE_EXT = "tar";
49
    private static final String[] directoryNames = { "dir1", "dir2" };
49
    private static final String[] directoryNames = { "dir1", "dir2" };
50
    private static final String[] emptyDirectoryNames = { "dir3" };
50
    private static final String[] fileNames = { "file1.txt", "file2.txt" };
51
    private static final String[] fileNames = { "file1.txt", "file2.txt" };
51
    
52
    
52
    private String localDirectory;
53
    private String localDirectory;
Lines 84-92 Link Here
84
85
85
        operation.setUseCompression(false);
86
        operation.setUseCompression(false);
86
        operation.setUseTarFormat(false);
87
        operation.setUseTarFormat(false);
87
        openTestWindow().run(true, true, operation);
88
        operation.run(new NullProgressMonitor());
88
        
89
        
89
        verifyFolders(directoryNames.length, ZIP_FILE_EXT);	
90
        verifyFolders(directoryNames.length + emptyDirectoryNames.length, ZIP_FILE_EXT);	
90
        
91
        
91
	}
92
	}
92
	
93
	
Lines 99-105 Link Here
99
100
100
        operation.setUseCompression(true);
101
        operation.setUseCompression(true);
101
        operation.setUseTarFormat(false);
102
        operation.setUseTarFormat(false);
102
        openTestWindow().run(true, true, operation);		
103
        operation.run(new NullProgressMonitor());	
103
		verifyCompressed(ZIP_FILE_EXT);
104
		verifyCompressed(ZIP_FILE_EXT);
104
	}
105
	}
105
	
106
	
Lines 123-131 Link Here
123
        operation.setCreateLeadupStructure(false);
124
        operation.setCreateLeadupStructure(false);
124
        operation.setUseCompression(false);
125
        operation.setUseCompression(false);
125
        operation.setUseTarFormat(false);
126
        operation.setUseTarFormat(false);
126
        openTestWindow().run(true, true, operation);
127
        operation.run(new NullProgressMonitor());
127
        flattenPaths = true;
128
        flattenPaths = true;
128
		verifyFolders(directoryNames.length, ZIP_FILE_EXT);		
129
		verifyFolders(directoryNames.length + emptyDirectoryNames.length, ZIP_FILE_EXT);		
129
	}
130
	}
130
	
131
	
131
	public void testExportZipCreateSelectedDirectoriesWithFolders() throws Exception {
132
	public void testExportZipCreateSelectedDirectoriesWithFolders() throws Exception {
Lines 142-150 Link Here
142
        operation.setCreateLeadupStructure(false);
143
        operation.setCreateLeadupStructure(false);
143
        operation.setUseCompression(false);
144
        operation.setUseCompression(false);
144
        operation.setUseTarFormat(false);
145
        operation.setUseTarFormat(false);
145
        openTestWindow().run(true, true, operation);
146
        operation.run(new NullProgressMonitor());
146
        excludeProjectPath = true;
147
        excludeProjectPath = true;
147
		verifyFolders(directoryNames.length, ZIP_FILE_EXT);				
148
		verifyFolders(directoryNames.length + emptyDirectoryNames.length, ZIP_FILE_EXT);				
148
	}
149
	}
149
	
150
	
150
	public void testExportZipCreateSelectedDirectoriesCompressed() throws Exception {
151
	public void testExportZipCreateSelectedDirectoriesCompressed() throws Exception {
Lines 167-176 Link Here
167
        operation.setCreateLeadupStructure(false);
168
        operation.setCreateLeadupStructure(false);
168
        operation.setUseCompression(true);
169
        operation.setUseCompression(true);
169
        operation.setUseTarFormat(false);
170
        operation.setUseTarFormat(false);
170
        openTestWindow().run(true, true, operation);
171
        operation.run(new NullProgressMonitor());
171
        flattenPaths = true;
172
        flattenPaths = true;
172
		verifyCompressed(ZIP_FILE_EXT);	
173
		verifyCompressed(ZIP_FILE_EXT);	
173
		verifyFolders(directoryNames.length, ZIP_FILE_EXT);
174
		verifyFolders(directoryNames.length + emptyDirectoryNames.length, ZIP_FILE_EXT);
174
	}
175
	}
175
	
176
	
176
	public void testExportTar() throws Exception {
177
	public void testExportTar() throws Exception {
Lines 182-190 Link Here
182
        operation.setUseTarFormat(true);
183
        operation.setUseTarFormat(true);
183
        operation.setUseCompression(false);
184
        operation.setUseCompression(false);
184
185
185
        openTestWindow().run(true, true, operation);
186
        operation.run(new NullProgressMonitor());
186
        
187
        
187
        verifyFolders(directoryNames.length, TAR_FILE_EXT);	
188
        verifyFolders(directoryNames.length + emptyDirectoryNames.length, TAR_FILE_EXT);	
188
	}
189
	}
189
	
190
	
190
	public void testExportTarCompressed() throws Exception {
191
	public void testExportTarCompressed() throws Exception {
Lines 196-202 Link Here
196
197
197
        operation.setUseTarFormat(true);
198
        operation.setUseTarFormat(true);
198
        operation.setUseCompression(true);
199
        operation.setUseCompression(true);
199
        openTestWindow().run(true, true, operation);		
200
        operation.run(new NullProgressMonitor());		
200
		verifyCompressed(TAR_FILE_EXT);		
201
		verifyCompressed(TAR_FILE_EXT);		
201
	}
202
	}
202
	
203
	
Lines 220-228 Link Here
220
        operation.setCreateLeadupStructure(false);
221
        operation.setCreateLeadupStructure(false);
221
        operation.setUseCompression(false);
222
        operation.setUseCompression(false);
222
        operation.setUseTarFormat(true);
223
        operation.setUseTarFormat(true);
223
        openTestWindow().run(true, true, operation);
224
        operation.run(new NullProgressMonitor());
224
        flattenPaths = true;
225
        flattenPaths = true;
225
		verifyFolders(directoryNames.length, TAR_FILE_EXT);			
226
		verifyFolders(directoryNames.length + emptyDirectoryNames.length, TAR_FILE_EXT);			
226
	}
227
	}
227
	
228
	
228
	public void testExportTarCreateSelectedDirectoriesWithFolders() throws Exception {
229
	public void testExportTarCreateSelectedDirectoriesWithFolders() throws Exception {
Lines 239-247 Link Here
239
        operation.setCreateLeadupStructure(false);
240
        operation.setCreateLeadupStructure(false);
240
        operation.setUseCompression(false);
241
        operation.setUseCompression(false);
241
        operation.setUseTarFormat(true);
242
        operation.setUseTarFormat(true);
242
        openTestWindow().run(true, true, operation);
243
        operation.run(new NullProgressMonitor());
243
        excludeProjectPath = true;
244
        excludeProjectPath = true;
244
		verifyFolders(directoryNames.length, TAR_FILE_EXT);				
245
		verifyFolders(directoryNames.length + emptyDirectoryNames.length, TAR_FILE_EXT);				
245
		
246
		
246
	}
247
	}
247
	
248
	
Lines 265-274 Link Here
265
        operation.setCreateLeadupStructure(false);
266
        operation.setCreateLeadupStructure(false);
266
        operation.setUseCompression(true);
267
        operation.setUseCompression(true);
267
        operation.setUseTarFormat(true);
268
        operation.setUseTarFormat(true);
268
        openTestWindow().run(true, true, operation);
269
        operation.run(new NullProgressMonitor());
269
        flattenPaths = true;
270
        flattenPaths = true;
270
		verifyCompressed(TAR_FILE_EXT);	
271
		verifyCompressed(TAR_FILE_EXT);	
271
		verifyFolders(directoryNames.length, TAR_FILE_EXT);
272
		verifyFolders(directoryNames.length + emptyDirectoryNames.length, TAR_FILE_EXT);
272
		
273
		
273
	}
274
	}
274
275
Lines 324-329 Link Here
324
	    				true, new NullProgressMonitor());
325
	    				true, new NullProgressMonitor());
325
	    		}
326
	    		}
326
	    	}
327
	    	}
328
329
	    	// create empty folders to test bug 278402
330
	    	for(int i = 0; i < emptyDirectoryNames.length; i++){
331
	    		IFolder folder = project.getFolder(emptyDirectoryNames[i]);
332
	    		folder.create(false, true, new NullProgressMonitor());
333
	    	}
327
    	}
334
    	}
328
    	catch(Exception e){
335
    	catch(Exception e){
329
    		fail(e.toString());
336
    		fail(e.toString());
Lines 405-411 Link Here
405
			int idx = entryName.lastIndexOf("/");
412
			int idx = entryName.lastIndexOf("/");
406
			String folderPath = entryName.substring(0, idx);
413
			String folderPath = entryName.substring(0, idx);
407
			String fileName = entryName.substring(idx+1, entryName.length());
414
			String fileName = entryName.substring(idx+1, entryName.length());
408
			files.add(fileName);
415
			// we get empty strings for folder entries, don't add them as a file name
416
			if (fileName.length() != 0) {
417
				files.add(fileName);	
418
			}
409
			int idx2 = folderPath.lastIndexOf("/");
419
			int idx2 = folderPath.lastIndexOf("/");
410
			if (idx2 != -1){
420
			if (idx2 != -1){
411
    			String folderName = folderPath.substring(idx2 + 1, folderPath.length());
421
    			String folderName = folderPath.substring(idx2 + 1, folderPath.length());
Lines 461-475 Link Here
461
    		if (directoryNames[i].equals(name))
471
    		if (directoryNames[i].equals(name))
462
    			return true;
472
    			return true;
463
    	}
473
    	}
474
    	for (int i = 0; i < emptyDirectoryNames.length; i++){
475
    		if (emptyDirectoryNames[i].equals(name))
476
    			return true;
477
    	}
464
    	return false;
478
    	return false;
465
    }
479
    }
466
    
480
    
467
	private boolean isDirectory(IResource resource){
481
	private boolean isDirectory(IResource resource){
468
		for (int i = 0; i < directoryNames.length; i++){
482
		return isDirectory(resource.getName());
469
			if (directoryNames[i].equals(resource.getName()))
470
				return true;
471
		}
472
		return false;
473
	}
483
	}
474
	
484
	
475
	private boolean isFile(IResource resource){
485
	private boolean isFile(IResource resource){

Return to bug 278402