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/ArchiveFileExportOperation.java (-11 / +36 lines)
Lines 37-43 Link Here
37
 *  @since 3.1
37
 *  @since 3.1
38
 */
38
 */
39
public class ArchiveFileExportOperation implements IRunnableWithProgress {
39
public class ArchiveFileExportOperation implements IRunnableWithProgress {
40
    private IFileExporter exporter;
40
    private static final String ZIP_DIR_CHAR = "/"; //$NON-NLS-1$
41
42
	private IFileExporter exporter;
41
43
42
    private String destinationFilename;
44
    private String destinationFilename;
43
45
Lines 162-167 Link Here
162
            throws InterruptedException {
164
            throws InterruptedException {
163
        exportResource(exportResource, 1);
165
        exportResource(exportResource, 1);
164
    }
166
    }
167
    
168
    /**
169
     * Creates and returns the string that should be used as the name of the entry in the archive.
170
     * 
171
     * @param exportResource the resource to export
172
     * @param leadupDepth the number of resource levels to be included in the path including the resourse itself.
173
     * @since 3.6
174
     */
175
    private String createDestinationName(int leadupDepth, IResource exportResource) {
176
        IPath fullPath = exportResource.getFullPath();
177
        if (createLeadupStructure) {
178
        	return fullPath.makeRelative().toString();
179
        }
180
		return fullPath.removeFirstSegments(
181
                fullPath.segmentCount() - leadupDepth).toString();
182
    }
165
183
166
    /**
184
    /**
167
     *  Export the passed resource to the destination .zip
185
     *  Export the passed resource to the destination .zip
Lines 177-190 Link Here
177
		}
195
		}
178
196
179
        if (exportResource.getType() == IResource.FILE) {
197
        if (exportResource.getType() == IResource.FILE) {
180
            String destinationName;
198
        	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);
199
            monitor.subTask(destinationName);
189
200
190
            try {
201
            try {
Lines 198-204 Link Here
198
            monitor.worked(1);
209
            monitor.worked(1);
199
            ModalContext.checkCanceled(monitor);
210
            ModalContext.checkCanceled(monitor);
200
        } else {
211
        } else {
201
            IResource[] children = null;
212
        	
213
        	IResource[] children = null;
202
214
203
            try {
215
            try {
204
                children = ((IContainer) exportResource).members();
216
                children = ((IContainer) exportResource).members();
Lines 206-212 Link Here
206
                // this should never happen because an #isAccessible check is done before #members is invoked
218
                // this should never happen because an #isAccessible check is done before #members is invoked
207
                addError(NLS.bind(DataTransferMessages.DataTransfer_errorExporting, exportResource.getFullPath()), e);
219
                addError(NLS.bind(DataTransferMessages.DataTransfer_errorExporting, exportResource.getFullPath()), e);
208
            }
220
            }
209
221
			// create an entry for ourselves, see bug 278402
222
			// Only create entry if no children exist
223
			if (children.length == 0) {
224
				String destinationName = createDestinationName(leadupDepth, exportResource);
225
226
				try {
227
					exporter.write((IContainer) exportResource, destinationName + ZIP_DIR_CHAR);
228
				} catch (IOException e) {
229
					addError(
230
							NLS.bind(DataTransferMessages.DataTransfer_errorExporting, exportResource.getFullPath().makeRelative(),
231
									e.getMessage()), e);
232
				}
233
			}
234
        	
210
            for (int i = 0; i < children.length; i++) {
235
            for (int i = 0; i < children.length; i++) {
211
				exportResource(children[i], leadupDepth + 1);
236
				exportResource(children[i], leadupDepth + 1);
212
			}
237
			}

Return to bug 278402