import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
ModalContext.checkCanceled(monitor);
IResource res = supplFile.getResource();
res.refreshLocal(0, new SubProgressMonitor(monitor, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
- createExportResource(traceSuppFilesFolder, res);
+ IResource link = createExportResource(traceSuppFilesFolder, res);
Element suppFileElement = doc.createElement(ITracePackageConstants.SUPPLEMENTARY_FILE_ELEMENT);
- suppFileElement.setAttribute(ITracePackageConstants.SUPPLEMENTARY_FILE_NAME_ATTRIB, res.getName());
+
+ // project/.traceExport/.tracing/kernel/statistics.ht -> .tracing/kernel/statistics.ht
+ IPath archiveRelativePath = link.getFullPath().makeRelativeTo(fExportFolder.getFullPath());
+
+ suppFileElement.setAttribute(ITracePackageConstants.SUPPLEMENTARY_FILE_NAME_ATTRIB, archiveRelativePath.toString());
traceNode.appendChild(suppFileElement);
}
folder.create(IResource.FORCE, true, new SubProgressMonitor(monitor, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
}
- createExportResource(folder, resource);
+ IResource link = createExportResource(folder, resource);
Element fileElement = doc.createElement(ITracePackageConstants.TRACE_FILE_ELEMENT);
- fileElement.setAttribute(ITracePackageConstants.TRACE_FILE_NAME_ATTRIB, resource.getName());
+ // project/.traceExport/Traces/kernel -> Traces/kernel
+ IPath archiveRelativePath = link.getFullPath().makeRelativeTo(fExportFolder.getFullPath());
+ fileElement.setAttribute(ITracePackageConstants.TRACE_FILE_NAME_ATTRIB, archiveRelativePath.toString());
traceNode.appendChild(fileElement);
fResources.add(folder);
}
* @param exportFolder the folder that will contain the linked resource
* @param res the resource to export
* @throws CoreException when createLink fails
+ * @return the created linked resource
*/
- private static void createExportResource(IFolder exportFolder, IResource res) throws CoreException {
+ private static IResource createExportResource(IFolder exportFolder, IResource res) throws CoreException {
+ IResource ret = null;
// Note: The resources cannot be HIDDEN or else they are ignored by ArchiveFileExportOperation
if (res instanceof IFolder) {
IFolder folder = exportFolder.getFolder(res.getName());
folder.createLink(res.getLocationURI(), IResource.NONE, null);
+ ret = folder;
} else if (res instanceof IFile) {
IFile file = exportFolder.getFile(res.getName());
file.createLink(res.getLocationURI(), IResource.NONE, null);
+ ret = file;
}
+ return ret;
}
private static void exportBookmarks(IProgressMonitor monitor, Node traceNode, TracePackageBookmarkElement element) throws CoreException, InterruptedException {
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilderFactory;
setStatus(Status.OK_STATUS);
}
else {
- setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format(Messages.TracePackageExtractManifestOperation_ErrorManifestNotFound, ITracePackageConstants.MANIFEST_FILENAME)));
+ elements = generateElementsFromArchive();
+ if (elements.length > 0) {
+ setStatus(Status.OK_STATUS);
+ } else {
+ setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format(Messages.TracePackageExtractManifestOperation_ErrorManifestNotFound, ITracePackageConstants.MANIFEST_FILENAME)));
+ }
}
fResultElements = elements;
}
}
+ private TracePackageElement[] generateElementsFromArchive() {
+ ArchiveFile archiveFile = getSpecifiedArchiveFile();
+ Enumeration<?> entries = archiveFile.entries();
+ Set<String> traceFileNames = new HashSet<String>();
+ while (entries.hasMoreElements()) {
+ ArchiveEntry entry = (ArchiveEntry) entries.nextElement();
+ String entryName = entry.getName();
+ IPath fullArchivePath = new Path(entryName);
+ if (!fullArchivePath.hasTrailingSeparator() && fullArchivePath.segmentCount() > 0) {
+ traceFileNames.add(fullArchivePath.segment(0));
+ }
+ }
+
+ List<TracePackageElement> packageElements = new ArrayList<TracePackageElement>();
+ for (String traceFileName : traceFileNames) {
+ TracePackageTraceElement traceElement = new TracePackageTraceElement(null, traceFileName, null);
+ traceElement.setChildren(new TracePackageElement[] { new TracePackageFilesElement(traceElement, traceFileName) });
+ packageElements.add(traceElement);
+ }
+
+ return packageElements.toArray(new TracePackageElement[] {});
+ }
+
/**
* Get the resulting element from extracting the manifest from the archive
*
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jface.operation.ModalContext;
import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.internal.tmf.ui.project.model.TmfTraceImportException;
import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.AbstractTracePackageOperation;
import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement;
import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement;
import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement;
import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement;
import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement;
-import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor;
import org.eclipse.linuxtools.tmf.ui.project.model.TmfNavigatorContentProvider;
import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
return;
}
- TraceTypeHelper traceType = TmfTraceType.getInstance().getTraceType(traceElement.getTraceType());
- if (traceType == null) {
- setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format(Messages.ImportTracePackageWizardPage_ErrorSettingTraceType, traceElement.getTraceType(), traceName)));
- return;
+ TraceTypeHelper traceType = null;
+ String traceTypeStr = traceElement.getTraceType();
+ if (traceTypeStr != null) {
+ traceType = TmfTraceType.getInstance().getTraceType(traceTypeStr);
+ if (traceType == null) {
+ setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format(Messages.ImportTracePackageWizardPage_ErrorSettingTraceType, traceElement.getTraceType(), traceName)));
+ return;
+ }
+ } else {
+ try {
+ progressMonitor.subTask(MessageFormat.format(Messages.TracePackageImportOperation_DetectingTraceType, traceName));
+ traceType = TmfTraceType.getInstance().selectTraceType(traceRes.getLocation().toOSString(), null, null);
+ } catch (TmfTraceImportException e) {
+ // Could not figure out the type
+ }
}
- try {
- TmfTraceType.setTraceType(traceRes.getFullPath(), traceType);
- } catch (CoreException e) {
- setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format(Messages.ImportTracePackageWizardPage_ErrorSettingTraceType, traceElement.getTraceType(), traceName), e));
+ if (traceType != null) {
+ try {
+ TmfTraceType.setTraceType(traceRes.getFullPath(), traceType);
+ } catch (CoreException e) {
+ setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format(Messages.ImportTracePackageWizardPage_ErrorSettingTraceType, traceElement.getTraceType(), traceName), e));
+ }
}
importBookmarks(traceRes, traceElement, progressMonitor);
private IStatus importTraceFiles(TracePackageFilesElement traceFilesElement, IProgressMonitor monitor) {
List<String> fileNames = new ArrayList<String>();
- IPath prefix = new Path(TmfTraceFolder.TRACE_FOLDER_NAME);
fileNames.add(traceFilesElement.getFileName());
IPath containerPath = fTmfTraceFolder.getPath();
- IStatus status = importFiles(getSpecifiedArchiveFile(), fileNames, prefix, containerPath, monitor);
+ IStatus status = importFiles(getSpecifiedArchiveFile(), fileNames, containerPath, monitor);
if (status.isOK()) {
new TmfNavigatorContentProvider().getChildren(fTmfTraceFolder);
}
String traceName = tmfTraceElement.getResource().getName();
// Project/.tracing/tracename
IPath destinationContainerPath = tmfTraceElement.getTraceSupplementaryFolder(traceName).getFullPath();
- // .tracing/tracename
- IPath pathInArchive = new Path(TmfCommonConstants.TRACE_SUPPLEMENATARY_FOLDER_NAME).append(traceName);
- return importFiles(archiveFile, fileNames, pathInArchive, destinationContainerPath, monitor);
+ return importFiles(archiveFile, fileNames, destinationContainerPath, monitor);
}
}
return Status.OK_STATUS;
}
- private IStatus importFiles(ArchiveFile archiveFile, List<String> fileNames, IPath pathInArchive, IPath destinationContainerPath, IProgressMonitor monitor) {
+ private IStatus importFiles(ArchiveFile archiveFile, List<String> fileNames, IPath destinationContainerPath, IProgressMonitor monitor) {
List<ArchiveProviderElement> objects = new ArrayList<ArchiveProviderElement>();
Enumeration<?> entries = archiveFile.entries();
while (entries.hasMoreElements()) {
}
for (String fileName : fileNames) {
+
+ // Examples: Traces/kernel/ .tracing/testtexttrace.txt/statistics.ht
+ IPath searchedArchivePath = new Path(fileName);
+
// Check if this archive entry matches the searched file name at this archive location
- IPath searchedArchivePath = pathInArchive.append(fileName);
if (fileNameMatches(searchedArchivePath.toString(), entryName)) {
- // Traces/kernel/metadata
- // kernel/metadata, the ImportOperation will take care of creating the kernel folder
- IPath destinationPath = fullArchivePath.removeFirstSegments(pathInArchive.segmentCount());
- // metadata
+ // Traces/ .tracing/testtexttrace.txt/
+ IPath searchedArchivePathContainer = searchedArchivePath.removeLastSegments(1);
+
+ // Traces/kernel/metadata -> kernel/metadata .tracing/testtexttrace.txt/statistics.ht -> statistics.ht
+ // Note: The ImportOperation will take care of creating the kernel folder
+ IPath destinationPath = fullArchivePath.makeRelativeTo(searchedArchivePathContainer);
+ // metadata statistics.ht
String resourceLabel = fullArchivePath.lastSegment();
ArchiveProviderElement pe = new ArchiveProviderElement(destinationPath.toString(), resourceLabel, archiveFile, entry);