From: Marc-Andre Laperle Date: Tue, 19 Nov 2013 01:23:49 +0000 (-0500) Subject: tmf: Import trace package without manifest X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=f7885d6d6ec6ba45f7ef1ffb57cea40574015484;p=deliverable%2Ftracecompass.git tmf: Import trace package without manifest Change-Id: I4e97dcc25734b6a5a91ffb35bfa38a94246b4b85 Signed-off-by: Marc-Andre Laperle Reviewed-on: https://git.eclipse.org/r/18591 --- diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/Messages.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/Messages.java index 051423a5dd..f8a6f0bf4e 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/Messages.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/Messages.java @@ -187,6 +187,11 @@ public class Messages extends NLS { */ public static String TracePackageImportOperation_ErrorCreatingBookmark; + /** + * Text for the detecting trace type job + */ + public static String TracePackageImportOperation_DetectingTraceType; + /** * Text when error occurs creating a bookmark file */ diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageExportOperation.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageExportOperation.java index f9168ae212..23f053e789 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageExportOperation.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageExportOperation.java @@ -31,6 +31,7 @@ import org.eclipse.core.resources.IFolder; 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; @@ -195,9 +196,13 @@ public class TracePackageExportOperation extends AbstractTracePackageOperation { 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); } @@ -213,9 +218,11 @@ public class TracePackageExportOperation extends AbstractTracePackageOperation { 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); } @@ -226,16 +233,21 @@ public class TracePackageExportOperation extends AbstractTracePackageOperation { * @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 { diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageExtractManifestOperation.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageExtractManifestOperation.java index 1d67e1dc0e..d4648cef3e 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageExtractManifestOperation.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageExtractManifestOperation.java @@ -19,8 +19,10 @@ import java.text.MessageFormat; 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; @@ -125,7 +127,12 @@ public class TracePackageExtractManifestOperation extends AbstractTracePackageOp 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; @@ -137,6 +144,29 @@ public class TracePackageExtractManifestOperation extends AbstractTracePackageOp } } + private TracePackageElement[] generateElementsFromArchive() { + ArchiveFile archiveFile = getSpecifiedArchiveFile(); + Enumeration entries = archiveFile.entries(); + Set traceFileNames = new HashSet(); + 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 packageElements = new ArrayList(); + 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 * diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageImportOperation.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageImportOperation.java index 871b7a3cc9..ec3710b641 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageImportOperation.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageImportOperation.java @@ -33,6 +33,7 @@ import org.eclipse.core.runtime.Status; 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; @@ -40,7 +41,6 @@ import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePack 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; @@ -209,16 +209,29 @@ public class TracePackageImportOperation extends AbstractTracePackageOperation i 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); @@ -330,10 +343,9 @@ public class TracePackageImportOperation extends AbstractTracePackageOperation i private IStatus importTraceFiles(TracePackageFilesElement traceFilesElement, IProgressMonitor monitor) { List fileNames = new ArrayList(); - 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); } @@ -363,16 +375,14 @@ public class TracePackageImportOperation extends AbstractTracePackageOperation i 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 fileNames, IPath pathInArchive, IPath destinationContainerPath, IProgressMonitor monitor) { + private IStatus importFiles(ArchiveFile archiveFile, List fileNames, IPath destinationContainerPath, IProgressMonitor monitor) { List objects = new ArrayList(); Enumeration entries = archiveFile.entries(); while (entries.hasMoreElements()) { @@ -385,13 +395,19 @@ public class TracePackageImportOperation extends AbstractTracePackageOperation i } 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); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/messages.properties b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/messages.properties index 09d6b18e72..a5fc3ed167 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/messages.properties +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/messages.properties @@ -50,3 +50,4 @@ TracePackageExtractManifestOperation_SchemaFileNotFound=The schema file {0} coul TracePackageImportOperation_ErrorCreatingBookmark=Error creating bookmark for the trace {0} TracePackageImportOperation_ErrorCreatingBookmarkFile=Error creating bookmark file for the trace {0} TracePackageImportOperation_ImportingPackage=Importing package +TracePackageImportOperation_DetectingTraceType=Detecting trace type for ''{0}'' diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceType.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceType.java index c3dfb185d4..09fb06ea99 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceType.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceType.java @@ -634,8 +634,9 @@ public final class TmfTraceType { * @throws TmfTraceImportException * if the traces don't match or there are errors in the trace * file + * @since 2.2 */ - TraceTypeHelper selectTraceType(String path, Shell shell, String traceTypeHint) throws TmfTraceImportException { + public TraceTypeHelper selectTraceType(String path, Shell shell, String traceTypeHint) throws TmfTraceImportException { List validCandidates = new ArrayList(); getCustomTraceTypes(); final Set traceTypes = fTraceTypes.keySet();