Fix importing an archive containing colons (:) in the names on Windows
authorMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Mon, 19 Sep 2016 02:57:19 +0000 (22:57 -0400)
committerMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Sat, 1 Oct 2016 21:31:21 +0000 (17:31 -0400)
Bug: 501664
Change-Id: I676f2533c140b52369328e1ef8e922f730b5e6e2
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/81302
Reviewed-by: Hudson CI
ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/META-INF/MANIFEST.MF
ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/build.properties
ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ctf/ui/swtbot/tests/Activator.java [new file with mode: 0644]
ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ctf/ui/swtbot/tests/StandardImportAndReadSmokeTest.java
ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/testfiles/testcolon.zip [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/ArchiveUtil.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/GzipLeveledStructureProvider.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/SafePathZipLeveledStructureProvider.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/TarLeveledStructureProvider.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/TraceFileSystemElement.java

index f4a16e3c39f6aab19d834af0c7a966d7d8ffd7ff..1fb54b8fea1fc5e3a886703c48a53529052f405c 100644 (file)
@@ -34,3 +34,4 @@ Import-Package: org.apache.log4j,
  org.eclipse.swtbot.swt.finder.waits,
  org.eclipse.swtbot.swt.finder.widgets,
  org.eclipse.tracecompass.testtraces.ctf;version="1.0.0"
+Bundle-Activator: org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests.Activator
index 1a4decb3955d2958eedbc4818bf274cfdeb69409..0fe2e3f812648888ee7d5224e6961dc2000e3cf7 100644 (file)
@@ -15,7 +15,8 @@ output.. = bin/
 bin.includes = META-INF/,\
                .,\
                plugin.properties,\
-               about.html
+               about.html,\
+               testfiles/
 src.includes = about.html
 additional.bundles = org.eclipse.jdt.annotation
 jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation
diff --git a/ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ctf/ui/swtbot/tests/Activator.java b/ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ctf/ui/swtbot/tests/Activator.java
new file mode 100644 (file)
index 0000000..6e2ded3
--- /dev/null
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests;
+
+import java.io.IOException;
+import java.net.URL;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends Plugin {
+
+    /**
+     * The plug-in ID
+     */
+    public static final String PLUGIN_ID = "org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests"; //$NON-NLS-1$
+
+    // The shared instance
+    private static Activator plugin;
+
+    /**
+     * The constructor
+     */
+    public Activator() {
+    }
+
+    @Override
+    public void start(BundleContext context) throws Exception {
+        super.start(context);
+        plugin = this;
+    }
+
+    @Override
+    public void stop(BundleContext context) throws Exception {
+        plugin = null;
+        super.stop(context);
+    }
+
+    /**
+     * Returns the shared instance
+     *
+     * @return the shared instance
+     */
+    public static Activator getDefault() {
+        return plugin;
+    }
+
+    /**
+     * Gets the absolute path from a path relative to this plugin's root
+     *
+     * @param relativePath
+     *            The path relative to this plugin
+     * @return The absolute path corresponding to this relative path
+     */
+    public static IPath getAbsolutePath(Path relativePath) {
+        Activator plugin2 = getDefault();
+        if (plugin2 == null) {
+            /*
+             * Shouldn't happen but at least throw something to get the test to
+             * fail early
+             */
+            return null;
+        }
+        URL location = FileLocator.find(plugin2.getBundle(), relativePath, null);
+        try {
+            IPath path = new Path(FileLocator.toFileURL(location).getPath());
+            return path;
+        } catch (IOException e) {
+            return null;
+        }
+    }
+
+}
\ No newline at end of file
index 29129f7c29339318ebd726ac65075d61f5c550e7..77916f0d606aef5744f3de869ba0a183f42d9cc0 100644 (file)
@@ -437,6 +437,34 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
         Files.delete(Paths.get(testArchivePath));
     }
 
+    /**
+     * Test importing an archive with colons in the names. Those are invalid
+     * characters in Windows paths so this test makes sure that they are
+     * replaced properly with '_'
+     */
+    @Test
+    public void testArchiveWithColons() {
+        openImportWizard();
+        IPath absolutePath = Activator.getAbsolutePath(new Path("testfiles/testcolon.zip"));
+
+        SWTBotImportWizardUtils.selectImportFromArchive(fBot, absolutePath.toOSString());
+        String subFolderName = IS_WIN32 ? "folder_colon" : "folder:colon";
+        selectFolder(ARCHIVE_ROOT_ELEMENT_NAME, subFolderName);
+        SWTBotImportWizardUtils.setOptions(fBot, 0, "Test trace : XML Trace Stub");
+        importFinish();
+
+        TmfProjectElement tmfProject = TmfProjectRegistry.getProject(getProjectResource(), true);
+        assertNotNull(tmfProject);
+        TmfTraceFolder tracesFolder = tmfProject.getTracesFolder();
+        assertNotNull(tracesFolder);
+        List<TmfTraceElement> traces = tracesFolder.getTraces();
+        assertTrue(traces.size() == 1);
+        String traceName = IS_WIN32 ? "trace_colon.xml" : "trace:colon.xml";
+        assertEquals(traceName, traces.get(0).getName());
+
+        SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
+    }
+
     private static void assertNoTraces() {
         TmfProjectElement tmfProject = TmfProjectRegistry.getProject(getProjectResource(), true);
         assertNotNull(tmfProject);
diff --git a/ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/testfiles/testcolon.zip b/ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/testfiles/testcolon.zip
new file mode 100644 (file)
index 0000000..913c795
Binary files /dev/null and b/ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/testfiles/testcolon.zip differ
index 2a247a60dc1494fded402213b6731bf3ce161fd4..559dad9e968712fac67743a2749ae8be99e5df5b 100644 (file)
@@ -17,10 +17,12 @@ import java.io.IOException;
 import java.util.zip.ZipException;
 import java.util.zip.ZipFile;
 
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
 import org.eclipse.swt.widgets.Shell;
+import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceCoreUtils;
 import org.eclipse.tracecompass.tmf.core.util.Pair;
 import org.eclipse.ui.internal.wizards.datatransfer.ArchiveFileManipulations;
-import org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider;
 import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider;
 
 /**
@@ -171,7 +173,7 @@ public class ArchiveUtil {
                 // We close the file when we dispose the import provider, see
                 // disposeSelectionGroupRoot
                 ZipFile zipFile = getSpecifiedZipSourceFile(archivePath);
-                leveledImportStructureProvider = new FileSystemObjectLeveledImportStructureProvider(new ZipLeveledStructureProvider(zipFile), archivePath);
+                leveledImportStructureProvider = new FileSystemObjectLeveledImportStructureProvider(new SafePathZipLeveledStructureProvider(zipFile), archivePath);
             } else if (ensureGzipSourceIsValid(archivePath)) {
                 // We close the file when we dispose the import provider, see
                 // disposeSelectionGroupRoot
@@ -196,4 +198,27 @@ public class ArchiveUtil {
 
         return new Pair<>(rootElement, importStructureProvider);
     }
+
+    /**
+     * Convert a string path to a path containing valid names. See
+     * {@link TmfTraceCoreUtils#validateName(String)}.
+     *
+     * @param path
+     *            the string path to convert
+     * @return the path contains valid segment names
+     */
+    public static IPath toValidNamesPath(String path) {
+        IPath newSafePath = TmfTraceCoreUtils.newSafePath(path);
+        IPath newFullPath = newSafePath;
+        String[] segments = newSafePath.segments();
+        for (int i = 0; i < segments.length; i++) {
+            String segment = TmfTraceCoreUtils.validateName(TmfTraceCoreUtils.safePathToString(segments[i]));
+            if (i == 0) {
+                newFullPath = new Path(segment);
+            } else {
+                newFullPath = newFullPath.append(segment);
+            }
+        }
+        return newFullPath;
+    }
 }
index 47da8ea65718b09f71c5e841f935b358172e2ec4..4dbc7b480acefe469917a07b6c0fc751b2a7253c 100644 (file)
@@ -61,7 +61,8 @@ public class GzipLeveledStructureProvider implements ILeveledImportStructureProv
 
     @Override
     public String getFullPath(Object element) {
-        return ((GzipEntry) element).getName();
+        String name = ((GzipEntry) element).getName();
+        return ArchiveUtil.toValidNamesPath(name).toOSString();
     }
 
     @Override
@@ -69,7 +70,12 @@ public class GzipLeveledStructureProvider implements ILeveledImportStructureProv
         if (element != root && element != fEntry) {
             throw new IllegalArgumentException();
         }
-        return ((GzipEntry) element).getName();
+        String name = ((GzipEntry) element).getName();
+        if (element.equals(root)) {
+            return name;
+        }
+
+        return ArchiveUtil.toValidNamesPath(name).lastSegment();
     }
 
     /**
diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/SafePathZipLeveledStructureProvider.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/SafePathZipLeveledStructureProvider.java
new file mode 100644 (file)
index 0000000..fcb6fe6
--- /dev/null
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace;
+
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider;
+
+/**
+ * A Zip structure provider that makes sure to return safe paths. For example,
+ * if a Zip entry contains a ':' and is extracted on Windows, it will be changed
+ * to a '_'
+ */
+@SuppressWarnings("restriction")
+public class SafePathZipLeveledStructureProvider extends ZipLeveledStructureProvider {
+
+    /**
+     * Creates a provider which will operate on the passed Zip file.
+     *
+     * @param sourceFile
+     *            The source file to create the provider around
+     */
+    public SafePathZipLeveledStructureProvider(ZipFile sourceFile) {
+        super(sourceFile);
+    }
+
+    @Override
+    public String getFullPath(Object element) {
+        String name = ((ZipEntry) element).getName();
+        return ArchiveUtil.toValidNamesPath(name).toOSString();
+    }
+
+    @Override
+    public String getLabel(Object element) {
+        if (element.equals(getRoot())) {
+            return ((ZipEntry) element).getName();
+        }
+        String name = ((ZipEntry) element).getName();
+        return stripPath(ArchiveUtil.toValidNamesPath(name).lastSegment());
+    }
+
+    /**
+     * Strip the leading directories from the path. Copied from
+     * {@link ZipLeveledStructureProvider}
+     */
+    private String stripPath(String path) {
+        String strippedPath = path;
+        String pathOrig = new String(strippedPath);
+        for (int i = 0; i < getStrip(); i++) {
+            int firstSep = strippedPath.indexOf('/');
+            // If the first character was a separator we must strip to the next
+            // separator as well
+            if (firstSep == 0) {
+                strippedPath = strippedPath.substring(1);
+                firstSep = strippedPath.indexOf('/');
+            }
+            // No separator was present so we're in a higher directory right
+            // now
+            if (firstSep == -1) {
+                return pathOrig;
+            }
+            strippedPath = strippedPath.substring(firstSep);
+        }
+        return strippedPath;
+    }
+}
index 137f1aa544e547e477f58a36a025c3b04efb0cb9..685657865291bffc05283d4f5f6498492636ab38 100644 (file)
@@ -36,223 +36,225 @@ import org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvi
  */
 @SuppressWarnings("restriction")
 public class TarLeveledStructureProvider implements
-               ILeveledImportStructureProvider {
-       private TarFile tarFile;
+        ILeveledImportStructureProvider {
+    private TarFile tarFile;
 
-       private TarEntry root = new TarEntry("/");//$NON-NLS-1$
+    private TarEntry root = new TarEntry("/");//$NON-NLS-1$
 
-       private Map<TarEntry, List<TarEntry>> children;
+    private Map<TarEntry, List<TarEntry>> children;
 
-       private Map<IPath, TarEntry> directoryEntryCache = new HashMap<>();
+    private Map<IPath, TarEntry> directoryEntryCache = new HashMap<>();
 
-       private int stripLevel;
+    private int stripLevel;
 
-       /**
-        * Creates a <code>TarFileStructureProvider</code>, which will operate on
-        * the passed tar file.
-        *
-        * @param sourceFile
-        *            the source TarFile
-        */
-       public TarLeveledStructureProvider(TarFile sourceFile) {
-               super();
-               tarFile = sourceFile;
-               root.setFileType(TarEntry.DIRECTORY);
-       }
+    /**
+     * Creates a <code>TarFileStructureProvider</code>, which will operate on
+     * the passed tar file.
+     *
+     * @param sourceFile
+     *            the source TarFile
+     */
+    public TarLeveledStructureProvider(TarFile sourceFile) {
+        super();
+        tarFile = sourceFile;
+        root.setFileType(TarEntry.DIRECTORY);
+    }
 
-       /**
-        * Creates a new container tar entry with the specified name, iff it has
-        * not already been created. If the parent of the given element does not
-        * already exist it will be recursively created as well.
-        * @param pathname The path representing the container
-        * @return The element represented by this pathname (it may have already existed)
-        */
-       protected TarEntry createContainer(IPath pathname) {
-               TarEntry existingEntry = directoryEntryCache.get(pathname);
-               if (existingEntry != null) {
-                       return existingEntry;
-               }
+    /**
+     * Creates a new container tar entry with the specified name, iff it has
+     * not already been created. If the parent of the given element does not
+     * already exist it will be recursively created as well.
+     * @param pathname The path representing the container
+     * @return The element represented by this pathname (it may have already existed)
+     */
+    protected TarEntry createContainer(IPath pathname) {
+        TarEntry existingEntry = directoryEntryCache.get(pathname);
+        if (existingEntry != null) {
+            return existingEntry;
+        }
 
-               TarEntry parent;
-               if (pathname.segmentCount() == 1) {
-                       parent = root;
-               } else {
-                       parent = createContainer(pathname.removeLastSegments(1));
-               }
-               TarEntry newEntry = new TarEntry(pathname.toString());
-               newEntry.setFileType(TarEntry.DIRECTORY);
-               directoryEntryCache.put(pathname, newEntry);
-               List<TarEntry> childList = new ArrayList<>();
-               children.put(newEntry, childList);
+        TarEntry parent;
+        if (pathname.segmentCount() == 1) {
+            parent = root;
+        } else {
+            parent = createContainer(pathname.removeLastSegments(1));
+        }
+        TarEntry newEntry = new TarEntry(pathname.toString());
+        newEntry.setFileType(TarEntry.DIRECTORY);
+        directoryEntryCache.put(pathname, newEntry);
+        List<TarEntry> childList = new ArrayList<>();
+        children.put(newEntry, childList);
 
-               List<TarEntry> parentChildList = children.get(parent);
-               NonNullUtils.checkNotNull(parentChildList).add(newEntry);
-               return newEntry;
-       }
+        List<TarEntry> parentChildList = children.get(parent);
+        NonNullUtils.checkNotNull(parentChildList).add(newEntry);
+        return newEntry;
+    }
 
-       /**
-        * Creates a new tar file entry with the specified name.
-        * @param entry the entry to create the file for
-        */
-       protected void createFile(TarEntry entry) {
-               IPath pathname = new Path(entry.getName());
-               TarEntry parent;
-               if (pathname.segmentCount() == 1) {
-                       parent = root;
-               } else {
-                       parent = directoryEntryCache.get(pathname
-                                       .removeLastSegments(1));
-               }
+    /**
+     * Creates a new tar file entry with the specified name.
+     * @param entry the entry to create the file for
+     */
+    protected void createFile(TarEntry entry) {
+        IPath pathname = new Path(entry.getName());
+        TarEntry parent;
+        if (pathname.segmentCount() == 1) {
+            parent = root;
+        } else {
+            parent = directoryEntryCache.get(pathname
+                    .removeLastSegments(1));
+        }
 
-               List<TarEntry> childList = children.get(parent);
-               NonNullUtils.checkNotNull(childList).add(entry);
-       }
+        List<TarEntry> childList = children.get(parent);
+        NonNullUtils.checkNotNull(childList).add(entry);
+    }
 
-       @Override
-       public List getChildren(Object element) {
-               if (children == null) {
-                       initialize();
-               }
+    @Override
+    public List getChildren(Object element) {
+        if (children == null) {
+            initialize();
+        }
 
-               return (children.get(element));
-       }
+        return (children.get(element));
+    }
 
     @Override
-       public InputStream getContents(Object element) {
-               try {
-                       return tarFile.getInputStream((TarEntry) element);
-               } catch (TarException e) {
-                       IDEWorkbenchPlugin.log(e.getLocalizedMessage(), e);
-                       return null;
-               } catch (IOException e) {
-                       IDEWorkbenchPlugin.log(e.getLocalizedMessage(), e);
-                       return null;
-               }
-       }
+    public InputStream getContents(Object element) {
+        try {
+            return tarFile.getInputStream((TarEntry) element);
+        } catch (TarException e) {
+            IDEWorkbenchPlugin.log(e.getLocalizedMessage(), e);
+            return null;
+        } catch (IOException e) {
+            IDEWorkbenchPlugin.log(e.getLocalizedMessage(), e);
+            return null;
+        }
+    }
 
-       /**
-        * Returns the resource attributes for this file.
-        *
-        * @param element the element to get the attributes from
-        * @return the attributes of the file
-        */
-       public ResourceAttributes getResourceAttributes(Object element) {
-               ResourceAttributes attributes = new ResourceAttributes();
-               TarEntry entry = (TarEntry) element;
-               attributes.setExecutable((entry.getMode() & 0100) != 0);
-               attributes.setReadOnly((entry.getMode() & 0200) == 0);
-               return attributes;
-       }
+    /**
+     * Returns the resource attributes for this file.
+     *
+     * @param element the element to get the attributes from
+     * @return the attributes of the file
+     */
+    public ResourceAttributes getResourceAttributes(Object element) {
+        ResourceAttributes attributes = new ResourceAttributes();
+        TarEntry entry = (TarEntry) element;
+        attributes.setExecutable((entry.getMode() & 0100) != 0);
+        attributes.setReadOnly((entry.getMode() & 0200) == 0);
+        return attributes;
+    }
 
-       @Override
-       public String getFullPath(Object element) {
-               return stripPath(((TarEntry) element).getName());
-       }
+    @Override
+    public String getFullPath(Object element) {
+        String name = stripPath(((TarEntry) element).getName());
+        return ArchiveUtil.toValidNamesPath(name).toOSString();
+    }
 
-       @Override
-       public String getLabel(Object element) {
-               if (element.equals(root)) {
-                       return ((TarEntry) element).getName();
-               }
+    @Override
+    public String getLabel(Object element) {
+        if (element.equals(root)) {
+            return ((TarEntry) element).getName();
+        }
 
-               return stripPath(new Path(((TarEntry) element).getName()).lastSegment());
-       }
+        String name = ((TarEntry) element).getName();
+        return stripPath(ArchiveUtil.toValidNamesPath(name).lastSegment());
+    }
 
-       /**
-        * Returns the entry that this importer uses as the root sentinel.
-        *
-        * @return TarEntry entry
-        */
-       @Override
-       public Object getRoot() {
-               return root;
-       }
+    /**
+     * Returns the entry that this importer uses as the root sentinel.
+     *
+     * @return TarEntry entry
+     */
+    @Override
+    public Object getRoot() {
+        return root;
+    }
 
-       /**
-        * Returns the tar file that this provider provides structure for.
-        *
-        * @return TarFile file
-        */
-       public TarFile getTarFile() {
-               return tarFile;
-       }
+    /**
+     * Returns the tar file that this provider provides structure for.
+     *
+     * @return TarFile file
+     */
+    public TarFile getTarFile() {
+        return tarFile;
+    }
 
-       @Override
-       public boolean closeArchive(){
-               try {
-                       getTarFile().close();
-               } catch (IOException e) {
-                       IDEWorkbenchPlugin.log(DataTransferMessages.ZipImport_couldNotClose
-                                       + getTarFile().getName(), e);
-                       return false;
-               }
-               return true;
-       }
+    @Override
+    public boolean closeArchive(){
+        try {
+            getTarFile().close();
+        } catch (IOException e) {
+            IDEWorkbenchPlugin.log(DataTransferMessages.ZipImport_couldNotClose
+                    + getTarFile().getName(), e);
+            return false;
+        }
+        return true;
+    }
 
-       /**
-        * Initializes this object's children table based on the contents of the
-        * specified source file.
-        */
-       protected void initialize() {
-               children = new HashMap<>(1000);
+    /**
+     * Initializes this object's children table based on the contents of the
+     * specified source file.
+     */
+    protected void initialize() {
+        children = new HashMap<>(1000);
 
-               children.put(root, new ArrayList<>());
-               Enumeration<TarEntry> entries = tarFile.entries();
-               while (entries.hasMoreElements()) {
-                       TarEntry entry = entries.nextElement();
-                       IPath path = new Path(entry.getName()).addTrailingSeparator();
+        children.put(root, new ArrayList<>());
+        Enumeration<TarEntry> entries = tarFile.entries();
+        while (entries.hasMoreElements()) {
+            TarEntry entry = entries.nextElement();
+            IPath path = new Path(entry.getName()).addTrailingSeparator();
 
-                       if (entry.getFileType() == TarEntry.DIRECTORY) {
-                               createContainer(path);
-                       } else
-                       {
-                               // Ensure the container structure for all levels above this is initialized
-                               // Once we hit a higher-level container that's already added we need go no further
-                               int pathSegmentCount = path.segmentCount();
-                               if (pathSegmentCount > 1) {
-                                       createContainer(path.uptoSegment(pathSegmentCount - 1));
-                               }
-                               createFile(entry);
-                       }
-               }
-       }
+            if (entry.getFileType() == TarEntry.DIRECTORY) {
+                createContainer(path);
+            } else
+            {
+                // Ensure the container structure for all levels above this is initialized
+                // Once we hit a higher-level container that's already added we need go no further
+                int pathSegmentCount = path.segmentCount();
+                if (pathSegmentCount > 1) {
+                    createContainer(path.uptoSegment(pathSegmentCount - 1));
+                }
+                createFile(entry);
+            }
+        }
+    }
 
-       @Override
-       public boolean isFolder(Object element) {
-               return (((TarEntry) element).getFileType() == TarEntry.DIRECTORY);
-       }
+    @Override
+    public boolean isFolder(Object element) {
+        return (((TarEntry) element).getFileType() == TarEntry.DIRECTORY);
+    }
 
-       /*
-        * Strip the leading directories from the path
-        */
-       private String stripPath(String path) {
-           String strippedPath = path;
-               String pathOrig = strippedPath;
-               for (int i = 0; i < stripLevel; i++) {
-                       int firstSep = strippedPath.indexOf('/');
-                       // If the first character was a seperator we must strip to the next
-                       // seperator as well
-                       if (firstSep == 0) {
-                           strippedPath = strippedPath.substring(1);
-                               firstSep = strippedPath.indexOf('/');
-                       }
-                       // No seperator wasw present so we're in a higher directory right
-                       // now
-                       if (firstSep == -1) {
-                               return pathOrig;
-                       }
-                       strippedPath = strippedPath.substring(firstSep);
-               }
-               return strippedPath;
-       }
+    /*
+     * Strip the leading directories from the path
+     */
+    private String stripPath(String path) {
+        String strippedPath = path;
+        String pathOrig = strippedPath;
+        for (int i = 0; i < stripLevel; i++) {
+            int firstSep = strippedPath.indexOf('/');
+            // If the first character was a seperator we must strip to the next
+            // seperator as well
+            if (firstSep == 0) {
+                strippedPath = strippedPath.substring(1);
+                firstSep = strippedPath.indexOf('/');
+            }
+            // No seperator wasw present so we're in a higher directory right
+            // now
+            if (firstSep == -1) {
+                return pathOrig;
+            }
+            strippedPath = strippedPath.substring(firstSep);
+        }
+        return strippedPath;
+    }
 
-       @Override
-       public void setStrip(int level) {
-               stripLevel = level;
-       }
+    @Override
+    public void setStrip(int level) {
+        stripLevel = level;
+    }
 
-       @Override
-       public int getStrip() {
-               return stripLevel;
-       }
+    @Override
+    public int getStrip() {
+        return stripLevel;
+    }
 }
index 294288314b49d38325bc36fb164d29fb1568dd47..6b620a385be50d6409b01a4ad06b920262b57f6a 100644 (file)
@@ -103,7 +103,7 @@ public class TraceFileSystemElement extends FileSystemElement {
      */
     public String getLabel() {
         if (fLabel == null) {
-            return getFileSystemObject().getName();
+            return getProvider().getLabel(this.getFileSystemObject());
         }
         return fLabel;
     }
This page took 0.039173 seconds and 5 git commands to generate.