From c2750d24c8e69a556f3e03b4472770650758e80f Mon Sep 17 00:00:00 2001 From: Marc-Andre Laperle Date: Sun, 18 Sep 2016 22:57:19 -0400 Subject: [PATCH] Fix importing an archive containing colons (:) in the names on Windows Bug: 501664 Change-Id: I676f2533c140b52369328e1ef8e922f730b5e6e2 Signed-off-by: Marc-Andre Laperle Reviewed-on: https://git.eclipse.org/r/81302 Reviewed-by: Hudson CI --- .../META-INF/MANIFEST.MF | 1 + .../build.properties | 3 +- .../tmf/ctf/ui/swtbot/tests/Activator.java | 86 ++++ .../tests/StandardImportAndReadSmokeTest.java | 28 ++ .../testfiles/testcolon.zip | Bin 0 -> 534 bytes .../wizards/importtrace/ArchiveUtil.java | 29 +- .../GzipLeveledStructureProvider.java | 10 +- .../SafePathZipLeveledStructureProvider.java | 74 ++++ .../TarLeveledStructureProvider.java | 384 +++++++++--------- .../importtrace/TraceFileSystemElement.java | 2 +- 10 files changed, 420 insertions(+), 197 deletions(-) create mode 100644 ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ctf/ui/swtbot/tests/Activator.java create mode 100644 ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/testfiles/testcolon.zip create mode 100644 tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/SafePathZipLeveledStructureProvider.java diff --git a/ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/META-INF/MANIFEST.MF b/ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/META-INF/MANIFEST.MF index f4a16e3c39..1fb54b8fea 100644 --- a/ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/META-INF/MANIFEST.MF +++ b/ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/META-INF/MANIFEST.MF @@ -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 diff --git a/ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/build.properties b/ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/build.properties index 1a4decb395..0fe2e3f812 100644 --- a/ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/build.properties +++ b/ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/build.properties @@ -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 index 0000000000..6e2ded3d8f --- /dev/null +++ b/ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ctf/ui/swtbot/tests/Activator.java @@ -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 diff --git a/ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ctf/ui/swtbot/tests/StandardImportAndReadSmokeTest.java b/ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ctf/ui/swtbot/tests/StandardImportAndReadSmokeTest.java index 29129f7c29..77916f0d60 100644 --- a/ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ctf/ui/swtbot/tests/StandardImportAndReadSmokeTest.java +++ b/ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ctf/ui/swtbot/tests/StandardImportAndReadSmokeTest.java @@ -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 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 index 0000000000000000000000000000000000000000..913c795ee3cea2b50ebc20812bd5d64b8b5b7345 GIT binary patch literal 534 zcmWIWW@h1H0D+S$jXc2&D8b7h!;qGrlag9wm7JfGpQj%h!pXq=()xb*Cm=4Z;AUWC zdBM!U044%}#)tqlaxnDG>UDRX`_XS5kars>ErV`MNl{{QD#S>=irgHqsovaqVJtQn zrtY15k?W9xh{OHgTp!t&gnil6^lRe7FIFwSDff7P{Z27jnU->)D%c{6ePv`v1TN1^0y|R}3X;r+gCuZY=8!3~Fw9*#8{@)YQV!z1OMe*kAwb$)d zU(vho-E>NStIh1v7>XtZX3XFahCKAngq@jsXC9>#2+Y literal 0 HcmV?d00001 diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/ArchiveUtil.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/ArchiveUtil.java index 2a247a60dc..559dad9e96 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/ArchiveUtil.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/ArchiveUtil.java @@ -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; + } } diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/GzipLeveledStructureProvider.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/GzipLeveledStructureProvider.java index 47da8ea657..4dbc7b480a 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/GzipLeveledStructureProvider.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/GzipLeveledStructureProvider.java @@ -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 index 0000000000..fcb6fe635d --- /dev/null +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/SafePathZipLeveledStructureProvider.java @@ -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; + } +} diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/TarLeveledStructureProvider.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/TarLeveledStructureProvider.java index 137f1aa544..6856578652 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/TarLeveledStructureProvider.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/TarLeveledStructureProvider.java @@ -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> children; + private Map> children; - private Map directoryEntryCache = new HashMap<>(); + private Map directoryEntryCache = new HashMap<>(); - private int stripLevel; + private int stripLevel; - /** - * Creates a TarFileStructureProvider, 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 TarFileStructureProvider, 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 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 childList = new ArrayList<>(); + children.put(newEntry, childList); - List parentChildList = children.get(parent); - NonNullUtils.checkNotNull(parentChildList).add(newEntry); - return newEntry; - } + List 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 childList = children.get(parent); - NonNullUtils.checkNotNull(childList).add(entry); - } + List 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 entries = tarFile.entries(); - while (entries.hasMoreElements()) { - TarEntry entry = entries.nextElement(); - IPath path = new Path(entry.getName()).addTrailingSeparator(); + children.put(root, new ArrayList<>()); + Enumeration 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; + } } diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/TraceFileSystemElement.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/TraceFileSystemElement.java index 294288314b..6b620a385b 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/TraceFileSystemElement.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/wizards/importtrace/TraceFileSystemElement.java @@ -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; } -- 2.34.1