* IImportStructureProvider to ILeveledImportStructureProvider
* Mickael Istria (Red Hat Inc.) - Bug 486901
* Marc-Andre Laperle <marc-andre.laperle@ericsson.com> - Copied to Trace Compass to work around bug 501379
+ * Marc-Andre Laperle <marc-andre.laperle@ericsson.com> - Adapted to use Apache Common Compress
*******************************************************************************/
package org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace;
import java.util.List;
import java.util.Map;
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.eclipse.core.resources.ResourceAttributes;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
ILeveledImportStructureProvider {
private TarFile tarFile;
- private TarEntry root = new TarEntry("/");//$NON-NLS-1$
+ private TarArchiveEntry root = new TarArchiveEntry("/", true);//$NON-NLS-1$
- private Map<TarEntry, List<TarEntry>> children;
+ private Map<TarArchiveEntry, List<TarArchiveEntry>> children;
- private Map<IPath, TarEntry> directoryEntryCache = new HashMap<>();
+ private Map<IPath, TarArchiveEntry> directoryEntryCache = new HashMap<>();
private int stripLevel;
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
+ * @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);
+ protected TarArchiveEntry createContainer(IPath pathName) {
+ IPath newPathName = pathName;
+ TarArchiveEntry existingEntry = directoryEntryCache.get(newPathName);
if (existingEntry != null) {
return existingEntry;
}
- TarEntry parent;
- if (pathname.segmentCount() == 1) {
+ TarArchiveEntry parent;
+ if (newPathName.segmentCount() == 1) {
parent = root;
} else {
- parent = createContainer(pathname.removeLastSegments(1));
+ parent = createContainer(newPathName.removeLastSegments(1));
}
- TarEntry newEntry = new TarEntry(pathname.toString());
- newEntry.setFileType(TarEntry.DIRECTORY);
- directoryEntryCache.put(pathname, newEntry);
- List<TarEntry> childList = new ArrayList<>();
+ // Add trailing / so that the entry knows it's a folder
+ newPathName = newPathName.addTrailingSeparator();
+ TarArchiveEntry newEntry = new TarArchiveEntry(newPathName.toString());
+ directoryEntryCache.put(newPathName, newEntry);
+ List<TarArchiveEntry> childList = new ArrayList<>();
children.put(newEntry, childList);
- List<TarEntry> parentChildList = children.get(parent);
+ List<TarArchiveEntry> 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) {
+ protected void createFile(TarArchiveEntry entry) {
IPath pathname = new Path(entry.getName());
- TarEntry parent;
+ TarArchiveEntry parent;
if (pathname.segmentCount() == 1) {
parent = root;
} else {
.removeLastSegments(1));
}
- List<TarEntry> childList = children.get(parent);
+ List<TarArchiveEntry> childList = children.get(parent);
NonNullUtils.checkNotNull(childList).add(entry);
}
@Override
public InputStream getContents(Object element) {
try {
- return tarFile.getInputStream((TarEntry) element);
- } catch (TarException e) {
- IDEWorkbenchPlugin.log(e.getLocalizedMessage(), e);
- return null;
+ return tarFile.getInputStream((TarArchiveEntry) element);
} catch (IOException e) {
IDEWorkbenchPlugin.log(e.getLocalizedMessage(), e);
return null;
*/
public ResourceAttributes getResourceAttributes(Object element) {
ResourceAttributes attributes = new ResourceAttributes();
- TarEntry entry = (TarEntry) element;
+ TarArchiveEntry entry = (TarArchiveEntry) element;
attributes.setExecutable((entry.getMode() & 0100) != 0);
attributes.setReadOnly((entry.getMode() & 0200) == 0);
return attributes;
@Override
public String getFullPath(Object element) {
- String name = stripPath(((TarEntry) element).getName());
+ String name = stripPath(((TarArchiveEntry) element).getName());
return ArchiveUtil.toValidNamesPath(name).toOSString();
}
@Override
public String getLabel(Object element) {
if (element.equals(root)) {
- return ((TarEntry) element).getName();
+ return ((TarArchiveEntry) element).getName();
}
- String name = ((TarEntry) element).getName();
+ String name = ((TarArchiveEntry) element).getName();
return stripPath(ArchiveUtil.toValidNamesPath(name).lastSegment());
}
/**
* Returns the entry that this importer uses as the root sentinel.
*
- * @return TarEntry entry
+ * @return TarArchiveEntry entry
*/
@Override
public Object getRoot() {
children = new HashMap<>(1000);
children.put(root, new ArrayList<>());
- Enumeration<TarEntry> entries = tarFile.entries();
+ Enumeration<TarArchiveEntry> entries = tarFile.entries();
while (entries.hasMoreElements()) {
- TarEntry entry = entries.nextElement();
+ TarArchiveEntry entry = entries.nextElement();
IPath path = new Path(entry.getName()).addTrailingSeparator();
- if (entry.getFileType() == TarEntry.DIRECTORY) {
+ if (entry.isDirectory()) {
createContainer(path);
} else
{
@Override
public boolean isFolder(Object element) {
- return (((TarEntry) element).getFileType() == TarEntry.DIRECTORY);
+ return (((TarArchiveEntry) element).isDirectory());
}
/*