tmf: Import trace package without manifest
authorMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tue, 19 Nov 2013 01:23:49 +0000 (20:23 -0500)
committerMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Mon, 2 Dec 2013 16:49:28 +0000 (11:49 -0500)
Change-Id: I4e97dcc25734b6a5a91ffb35bfa38a94246b4b85
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/18591

org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/Messages.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageExportOperation.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageExtractManifestOperation.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageImportOperation.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/messages.properties
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceType.java

index 051423a5ddf985a19df169c83b0b2e2321183bf1..f8a6f0bf4ee312e92310f7040794f0ec5be67088 100644 (file)
@@ -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
      */
index f9168ae212230d2c57099e5cf31f77b247e9bfb0..23f053e789986819dd638aad463f7399f5a80f12 100644 (file)
@@ -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 {
index 1d67e1dc0e8c8996a85b9b1a89719b72d1a460f1..d4648cef3ef66eec2bbcc2c2b9db8d4ae1b5cdf2 100644 (file)
@@ -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<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
      *
index 871b7a3cc9f28c754e62426b79f0df2d23b4e1d4..ec3710b64161fdef06daec86bbd1ac0cf5ba47ea 100644 (file)
@@ -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<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);
         }
@@ -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<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()) {
@@ -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);
index 09d6b18e728489cab01e94b9f6f43ec67f15bde3..a5fc3ed1674adf47dbcdc5084b4e6b380cbe1eb1 100644 (file)
@@ -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}''
index c3dfb185d47891093de1235dba0a7db45f4f08bc..09fb06ea993150ad7ba38c6c136171188ace2e6f 100644 (file)
@@ -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<TraceTypeHelper> validCandidates = new ArrayList<TraceTypeHelper>();
         getCustomTraceTypes();
         final Set<String> traceTypes = fTraceTypes.keySet();
This page took 0.032303 seconds and 5 git commands to generate.