tmf: Add source location to trace properties
authorPatrick Tasse <patrick.tasse@gmail.com>
Wed, 26 Mar 2014 20:45:36 +0000 (16:45 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Mon, 7 Apr 2014 17:14:02 +0000 (13:14 -0400)
The source location property is added and contains an URI indicating the
original source for a trace.

The source location URI depends on the method used to add the trace to a
Tracing project:

- Import wizard
- Batch Import wizard
- Open Trace File command
- Open Trace Directory command
- Drag and Drop from workspace
- Drag and Drop from external source

file:/<path>/<file>
file:/<path>/<folder>/

- Import Trace Package wizard

jar:file:/<path>/<archive>!/<path>/<file>
jar:file:/<path>/<archive>!/<path>/<folder>/

- Import action in LTTng Control view

sftp://<host>:<port>/<path>/<file>
sftp://<host>:<port>/<path>/<folder>/

Change-Id: I6bc4dc52bbbddd03d6f33ac4fc3d194cc1bded74
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/24268
Tested-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
12 files changed:
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/ImportHandler.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/TmfCommonConstants.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DropAdapterAssistant.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/tmf/ui/project/model/Messages.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfOpenTraceHelper.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfProjectModelElement.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceTypeUIUtils.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/messages.properties
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/BatchImportTraceWizard.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/ImportTraceWizardPage.java

index 61ca39605c311ef79a59e7f03286ba628b6e39c4..838722c1a7829435678580db008d11bad65695e5 100644 (file)
@@ -9,9 +9,12 @@
  * Contributors:
  *   Bernd Hufmann - Initial API and implementation
  *   Bernd Hufmann - Updated for support of streamed traces
+ *   Patrick Tasse - Add support for source location
  **********************************************************************/
 package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
 
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.Iterator;
 import java.util.List;
 
@@ -21,12 +24,14 @@ import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IProject;
 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.MultiStatus;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.core.runtime.URIUtil;
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.StructuredSelection;
@@ -40,6 +45,7 @@ import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ImportFil
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
+import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
 import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType;
 import org.eclipse.linuxtools.tmf.core.project.model.TraceTypeHelper;
 import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement;
@@ -158,6 +164,20 @@ public class ImportHandler extends BaseControlViewHandler {
                             if (helper != null) {
                                 status.add(TmfTraceTypeUIUtils.setTraceType(file, helper));
                             }
+
+                            try {
+                                final String scheme = "sftp"; //$NON-NLS-1$
+                                String host = remoteFile.getImportFile().getHost().getName();
+                                int port = remoteFile.getImportFile().getParentRemoteFileSubSystem().getConnectorService().getPort();
+                                String path = remoteFile.getImportFile().getAbsolutePath();
+                                if (file instanceof IFolder) {
+                                    path += IPath.SEPARATOR;
+                                }
+                                URI uri = new URI(scheme, null, host, port, path, null, null);
+                                String sourceLocation = URIUtil.toUnencodedString(uri);
+                                file.setPersistentProperty(TmfCommonConstants.SOURCE_LOCATION, sourceLocation);
+                            } catch (URISyntaxException e) {
+                            }
                         } catch (ExecutionException e) {
                             status.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_ImportFailure, e));
                         } catch (CoreException e) {
index f77e40b043daeb879b26624650022e37190c55d1..00419bf35df146655d608cbdd7f470fca5aadf7d 100644 (file)
@@ -8,6 +8,7 @@
  *
  * Contributors:
  *   Bernd Hufmann - Initial API and implementation
+ *   Patrick Tasse - Add support for source location
  *******************************************************************************/
 package org.eclipse.linuxtools.tmf.core;
 
@@ -30,6 +31,11 @@ public class TmfCommonConstants {
      */
     public static final QualifiedName TRACETYPE = new QualifiedName("org.eclipse.linuxtools.tmf", "tracetype.id"); //$NON-NLS-1$//$NON-NLS-2$
 
+    /**
+     * The source location persistent property of a trace resource.
+     * @since 3.0
+     */
+    public static final QualifiedName SOURCE_LOCATION = new QualifiedName("org.eclipse.linuxtools.tmf", "source.location"); //$NON-NLS-1$//$NON-NLS-2$
 
     /**
      * The supplementary folder name persistent property of a trace resource.
index ccfb5f64497e58117b02c759588445f1acfd87cc..bc04703eae4d97f3d18ad5cc653943501955e85f 100644 (file)
@@ -36,6 +36,7 @@ import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.QualifiedName;
 import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.URIUtil;
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
@@ -258,6 +259,11 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant {
                 } else if (sourceResource.getType() == IResource.FOLDER) {
                     traceResource = targetExperiment.getProject().getTracesFolder().getResource().getFolder(targetName);
                 }
+                String sourceLocation = sourceResource.getPersistentProperty(TmfCommonConstants.SOURCE_LOCATION);
+                if (sourceLocation == null) {
+                     sourceLocation = URIUtil.toUnencodedString(new File(sourceResource.getLocationURI()).toURI());
+                }
+                traceResource.setPersistentProperty(TmfCommonConstants.SOURCE_LOCATION, sourceLocation);
             } catch (CoreException e) {
                 displayException(e);
                 return null;
@@ -330,6 +336,11 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant {
                 createLink(traceFolder.getResource(), sourceResource, targetName);
             }
             IResource traceResource = traceFolder.getResource().findMember(targetName);
+            String sourceLocation = sourceResource.getPersistentProperty(TmfCommonConstants.SOURCE_LOCATION);
+            if (sourceLocation == null) {
+                sourceLocation = URIUtil.toUnencodedString(new File(sourceResource.getLocationURI()).toURI());
+            }
+            traceResource.setPersistentProperty(TmfCommonConstants.SOURCE_LOCATION, sourceLocation);
             setTraceType(traceResource);
             return traceResource;
         } catch (CoreException e) {
@@ -383,6 +394,12 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant {
                 resource = targetExperiment.getProject().getTracesFolder().getResource().getFolder(targetName);
             }
             if (resource != null && resource.exists()) {
+                try {
+                    String sourceLocation = URIUtil.toUnencodedString(path.toFile().toURI());
+                    resource.setPersistentProperty(TmfCommonConstants.SOURCE_LOCATION, sourceLocation);
+                } catch (CoreException e) {
+                    displayException(e);
+                }
                 setTraceType(resource);
                 createLink(targetExperiment.getResource(), resource, resource.getName());
                 targetExperiment.deleteSupplementaryResources();
@@ -421,6 +438,12 @@ public class DropAdapterAssistant extends CommonDropAdapterAssistant {
             createLink(traceFolder.getResource(), path, targetName);
         }
         IResource traceResource = traceFolder.getResource().findMember(targetName);
+        try {
+            String sourceLocation = URIUtil.toUnencodedString(path.toFile().toURI());
+            traceResource.setPersistentProperty(TmfCommonConstants.SOURCE_LOCATION, sourceLocation);
+        } catch (CoreException e) {
+            displayException(e);
+        }
         setTraceType(traceResource);
         return true;
     }
index f9ed1236ede84901112ba9cf61be6601f71551f5..89681a1be0cf2ecb9ebfd113408c78c1b985362a 100644 (file)
@@ -8,13 +8,16 @@
  *
  * Contributors:
  *     Marc-Andre Laperle - Initial API and implementation
+ *     Patrick Tasse - Add support for source location
  *******************************************************************************/
 
 package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.importexport;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
+import java.net.URI;
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Enumeration;
@@ -22,6 +25,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IMarker;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
@@ -31,6 +35,7 @@ import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.core.runtime.URIUtil;
 import org.eclipse.jface.operation.ModalContext;
 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
 import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.AbstractTracePackageOperation;
@@ -40,6 +45,7 @@ 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.core.project.model.TmfTraceImportException;
 import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType;
 import org.eclipse.linuxtools.tmf.core.project.model.TraceTypeHelper;
@@ -179,6 +185,7 @@ public class TracePackageImportOperation extends AbstractTracePackageOperation i
                 return;
             }
 
+            TracePackageFilesElement traceFilesElement = null;
             for (TracePackageElement packageElement : fImportTraceElements) {
                 TracePackageTraceElement traceElement = (TracePackageTraceElement) packageElement;
                 if (!isFilesChecked(packageElement)) {
@@ -190,7 +197,7 @@ public class TracePackageImportOperation extends AbstractTracePackageOperation i
                     ModalContext.checkCanceled(progressMonitor);
 
                     if (element instanceof TracePackageFilesElement) {
-                        TracePackageFilesElement traceFilesElement = (TracePackageFilesElement) element;
+                        traceFilesElement = (TracePackageFilesElement) element;
                         setStatus(importTraceFiles(traceFilesElement, progressMonitor));
 
                     } else if (element instanceof TracePackageSupplFilesElement) {
@@ -236,9 +243,20 @@ public class TracePackageImportOperation extends AbstractTracePackageOperation i
                 }
 
                 importBookmarks(traceRes, traceElement, progressMonitor);
-            }
-
 
+                try {
+                    if (traceFilesElement != null) {
+                        URI uri = new File(getFileName()).toURI();
+                        IPath entryPath = new Path(traceFilesElement.getFileName());
+                        if (traceRes instanceof IFolder) {
+                            entryPath = entryPath.addTrailingSeparator();
+                        }
+                        String sourceLocation = URIUtil.toUnencodedString(URIUtil.toJarURI(uri, entryPath));
+                        traceRes.setPersistentProperty(TmfCommonConstants.SOURCE_LOCATION, sourceLocation);
+                    }
+                } catch (CoreException e) {
+                }
+            }
 
         } catch (InterruptedException e) {
             setStatus(Status.CANCEL_STATUS);
index d18a067b568ebbe90bfba272ac0762f0c672c35f..0b422fbb88a1f4f6ae580d097c709eeb8e74bd36 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2013 Ericsson
+ * Copyright (c) 2013, 2014 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -8,6 +8,7 @@
  *
  * Contributors:
  *   Jean-Christian Kouamé - Initial API and implementation
+ *   Patrick Tasse - Add support for source location
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.ui.project.model;
@@ -68,8 +69,13 @@ public class Messages extends NLS {
     /** The descriptor for the event type property */
     public static String TmfTraceElement_EventType;
 
-    /** The description for the linked property */
+    /** The descriptor for the linked property */
     public static String TmfTraceElement_IsLinked;
+
+    /** The descriptor for the source location property
+     * @since 3.0*/
+    public static String TmfTraceElement_SourceLocation;
+
     /** Trace text
      * @since 3.0*/
     public static String TmfTraceElement_TypeName;
index ba4cd3873c8fc9f201d67f9840a466dd73a6b176..b08fa2d7c59552993777baca4e55fbccc85f90ec 100644 (file)
@@ -29,8 +29,10 @@ import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.URIUtil;
 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
 import org.eclipse.linuxtools.internal.tmf.ui.project.model.TmfImportHelper;
+import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceImportException;
@@ -129,6 +131,9 @@ public class TmfOpenTraceHelper {
                     Messages.TmfOpenTraceHelper_LinkFailed);
         }
 
+        String sourceLocation = URIUtil.toUnencodedString(new File(path).toURI());
+        linkedTrace.setPersistentProperty(TmfCommonConstants.SOURCE_LOCATION, sourceLocation);
+
         // No trace type was determined.
         if (traceTypeToSet == null) {
             return Status.OK_STATUS;
index 17a1a5b240a291e052b7bae08569a2307c36ca4c..28811ee39b9e819bb537c657b8e989cb29c80647 100644 (file)
@@ -14,6 +14,7 @@
 
 package org.eclipse.linuxtools.tmf.ui.project.model;
 
+import java.io.File;
 import java.net.URI;
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
@@ -83,7 +84,7 @@ public abstract class TmfProjectModelElement implements ITmfProjectModelElement
         fName = name;
         fResource = resource;
         fPath = resource.getFullPath();
-        fLocation = resource.getLocationURI();
+        fLocation = new File(resource.getLocationURI()).toURI();
         fParent = parent;
         fChildren = new CopyOnWriteArrayList<>();
     }
index f5b1a65c5b35386169c494879c9924ac37d58c8a..e1fa92fc890923ef0aa57d0f6547231c96e0b650 100644 (file)
@@ -35,6 +35,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.Platform;
 import org.eclipse.core.runtime.URIUtil;
 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtEvent;
 import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtTrace;
@@ -84,6 +85,7 @@ public class TmfTraceElement extends TmfCommonProjectElement implements IActionF
     private static final String sfLocation = Messages.TmfTraceElement_Location;
     private static final String sfEventType = Messages.TmfTraceElement_EventType;
     private static final String sfIsLinked = Messages.TmfTraceElement_IsLinked;
+    private static final String sfSourceLocation = Messages.TmfTraceElement_SourceLocation;
     private static final String sfTracePropertiesCategory = Messages.TmfTraceElement_TraceProperties;
 
     private static final ReadOnlyTextPropertyDescriptor sfNameDescriptor = new ReadOnlyTextPropertyDescriptor(sfName, sfName);
@@ -91,9 +93,10 @@ public class TmfTraceElement extends TmfCommonProjectElement implements IActionF
     private static final ReadOnlyTextPropertyDescriptor sfLocationDescriptor = new ReadOnlyTextPropertyDescriptor(sfLocation, sfLocation);
     private static final ReadOnlyTextPropertyDescriptor sfTypeDescriptor = new ReadOnlyTextPropertyDescriptor(sfEventType, sfEventType);
     private static final ReadOnlyTextPropertyDescriptor sfIsLinkedDescriptor = new ReadOnlyTextPropertyDescriptor(sfIsLinked, sfIsLinked);
+    private static final ReadOnlyTextPropertyDescriptor sfSourceLocationDescriptor = new ReadOnlyTextPropertyDescriptor(sfSourceLocation, sfSourceLocation);
 
     private static final IPropertyDescriptor[] sfDescriptors = { sfNameDescriptor, sfPathDescriptor, sfLocationDescriptor,
-            sfTypeDescriptor, sfIsLinkedDescriptor };
+            sfTypeDescriptor, sfIsLinkedDescriptor, sfSourceLocationDescriptor };
 
     static {
         sfNameDescriptor.setCategory(sfResourcePropertiesCategory);
@@ -101,6 +104,7 @@ public class TmfTraceElement extends TmfCommonProjectElement implements IActionF
         sfLocationDescriptor.setCategory(sfResourcePropertiesCategory);
         sfTypeDescriptor.setCategory(sfResourcePropertiesCategory);
         sfIsLinkedDescriptor.setCategory(sfResourcePropertiesCategory);
+        sfSourceLocationDescriptor.setCategory(sfResourcePropertiesCategory);
     }
 
     // ------------------------------------------------------------------------
@@ -452,8 +456,15 @@ public class TmfTraceElement extends TmfCommonProjectElement implements IActionF
             return URIUtil.toUnencodedString(getLocation());
         }
 
-        if (sfIsLinked.equals(id)) {
-            return Boolean.valueOf(getResource().isLinked()).toString();
+        if (sfSourceLocation.equals(id)) {
+            try {
+                String sourceLocation = getElementUnderTraceFolder().getResource().getPersistentProperty(TmfCommonConstants.SOURCE_LOCATION);
+                if (sourceLocation != null) {
+                    return sourceLocation;
+                }
+            } catch (CoreException e) {
+            }
+            return ""; //$NON-NLS-1$
         }
 
         if (sfEventType.equals(id)) {
index ca76dba8138d9acbc8962e9bfa2a3d32dacfaf48..587254e8976d2e6a289baa61af33f8d11115c4e2 100644 (file)
@@ -34,6 +34,7 @@ import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType.TraceElementTy
 import org.eclipse.linuxtools.tmf.core.project.model.TraceTypeHelper;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 import org.eclipse.linuxtools.tmf.core.util.Pair;
+import org.eclipse.osgi.util.NLS;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
@@ -217,7 +218,7 @@ public final class TmfTraceTypeUIUtils {
 
         TraceTypeHelper traceTypeToSet = null;
         if (validCandidates.isEmpty()) {
-            final String errorMsg = Messages.TmfOpenTraceHelper_NoTraceTypeMatch + path;
+            final String errorMsg = NLS.bind(Messages.TmfOpenTraceHelper_NoTraceTypeMatch, path);
             throw new TmfTraceImportException(errorMsg);
         } else if (validCandidates.size() != 1) {
             List<Pair<Integer, TraceTypeHelper>> candidates = new ArrayList<>(validCandidates);
index e59c031eab68bf558e1ffe610772540b584042ef..1d5c3a924ad43cabb52c8cac34fad0a584b925fd 100644 (file)
@@ -1,5 +1,5 @@
 ###############################################################################
-# Copyright (c) 2013 Ericsson
+# Copyright (c) 2013, 2014 Ericsson
 #
 # All rights reserved. This program and the accompanying materials
 # are made available under the terms of the Eclipse Public License v1.0
@@ -26,13 +26,14 @@ TmfTraceElement_Path = path
 TmfTraceElement_Location = location
 TmfTraceElement_EventType = type
 TmfTraceElement_IsLinked = linked
+TmfTraceElement_SourceLocation = source location
 TmfTraceElement_TypeName=Trace
 TmfTraceType_SelectTraceType=Select Trace Type
 
 # Open trace error messages
 TmfOpenTraceHelper_ErrorOpeningElement=Error opening {0}
 TmfOpenTraceHelper_LinkFailed=Link creation failed
-TmfOpenTraceHelper_NoTraceTypeMatch=No trace types found to match location
+TmfOpenTraceHelper_NoTraceTypeMatch=No trace types found to match location {0}
 TmfOpenTraceHelper_OpenElement=Open {0}
 TmfOpenTraceHelper_ReduceError=Something went wrong
 TmfOpenTraceHelper_NoTraceType = No trace type associated to that trace\nPlease select a valid type
index 816949f0135a8bcf2ee85241b3cbd8dec9f18d5e..915e5978a30f99be0da7c0c047a485be5dcb5ab6 100644 (file)
@@ -9,6 +9,7 @@
  * Contributors:
  *   Matthew Khouzam - Initial API and implementation
  *   Marc-Andre Laperle - Log some exceptions
+ *   Patrick Tasse - Add support for source location
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.ui.project.wizards.importtrace;
@@ -40,6 +41,7 @@ import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.core.runtime.URIUtil;
 import org.eclipse.jface.dialogs.ErrorDialog;
 import org.eclipse.jface.dialogs.IDialogSettings;
 import org.eclipse.jface.operation.IRunnableWithProgress;
@@ -48,13 +50,10 @@ import org.eclipse.jface.wizard.IWizardPage;
 import org.eclipse.jface.wizard.WizardDialog;
 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
 import org.eclipse.linuxtools.internal.tmf.ui.project.model.TmfImportHelper;
+import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
 import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType;
 import org.eclipse.linuxtools.tmf.core.project.model.TraceTypeHelper;
 import org.eclipse.linuxtools.tmf.core.project.model.TraceValidationHelper;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
-import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement;
-import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectRegistry;
-import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
 import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
 import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceTypeUIUtils;
 import org.eclipse.ui.IWorkbench;
@@ -256,7 +255,7 @@ public class BatchImportTraceWizard extends ImportTraceWizard {
                         success = false;
                     }
                     else {
-                        success = setTraceType(traceToImport).isOK();
+                        success = setTraceTypeAndSourceLocation(traceToImport).isOK();
                     }
                 }
                 else {
@@ -275,7 +274,7 @@ public class BatchImportTraceWizard extends ImportTraceWizard {
                                 }
                                 resource.create(source, true, new NullProgressMonitor());
                             }
-                            setTraceType(traceToImport);
+                            setTraceTypeAndSourceLocation(traceToImport);
                             success = true;
                         }
                     } else {
@@ -301,7 +300,7 @@ public class BatchImportTraceWizard extends ImportTraceWizard {
                         operation.setContext(getShell());
                         operation.setCreateContainerStructure(false);
                         if (executeImportOperation(operation)) {
-                            setTraceType(traceToImport);
+                            setTraceTypeAndSourceLocation(traceToImport);
                             success = true;
                         }
                     }
@@ -313,8 +312,8 @@ public class BatchImportTraceWizard extends ImportTraceWizard {
         return success;
     }
 
-    private IStatus setTraceType(FileAndName traceToImport) {
-        IStatus validate = Status.OK_STATUS;
+    private IStatus setTraceTypeAndSourceLocation(FileAndName traceToImport) {
+        IStatus status = Status.OK_STATUS;
         IResource resource = fTargetFolder.findMember(traceToImport.getName());
         if (resource != null) {
             try {
@@ -322,56 +321,31 @@ public class BatchImportTraceWizard extends ImportTraceWizard {
                 String traceTypeId = traceToImport.getTraceTypeId();
                 TraceTypeHelper traceType = TmfTraceType.getInstance().getTraceType(traceTypeId);
                 if (traceType != null) {
-                    TmfTraceTypeUIUtils.setTraceType(resource, traceType);
+                    status = TmfTraceTypeUIUtils.setTraceType(resource, traceType);
                 }
 
-                TmfProjectElement tmfProject =
-                        TmfProjectRegistry.getProject(resource.getProject());
-                if (tmfProject != null) {
-                    final TmfTraceFolder tracesFolder = tmfProject.getTracesFolder();
-
-                    List<TmfTraceElement> traces = tracesFolder.getTraces();
-                    boolean found = false;
-                    for (TmfTraceElement traceElement : traces) {
-                        if (traceElement.getName().equals(resource.getName())) {
-                            traceElement.refreshTraceType();
-                            found = true;
-                            break;
-                        }
-                    }
-                    if (!found) {
-                        TmfTraceElement te = new TmfTraceElement(traceToImport.getName(), resource, tracesFolder);
-                        te.refreshTraceType();
-                        traces = tracesFolder.getTraces();
-                        for (TmfTraceElement traceElement : traces) {
-                            if (traceElement.getName().equals(resource.getName())) {
-                                traceElement.refreshTraceType();
-                                ITmfTrace tmfTrace = null;
-                                try {
-                                    tmfTrace = traceElement.instantiateTrace();
-                                    if (tmfTrace != null) {
-                                        validate = tmfTrace.validate(tmfProject.getResource(), traceElement.getLocation().getPath());
-                                    } else {
-                                        return new Status(IStatus.ERROR, traceElement.getName(), "File does not exist : " + traceElement.getLocation().getPath()); //$NON-NLS-1$
-                                    }
-                                } finally {
-                                    if (tmfTrace != null) {
-                                        tmfTrace.dispose();
-                                    }
-                                }
-                                break;
-                            }
-                        }
-
-                    }
-
+                // Set the source location for this resource
+                File file = traceToImport.getFile();
+                String sourceLocation = null;
+                IResource sourceResource;
+                if (file.isDirectory()) {
+                    sourceResource = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(Path.fromOSString(file.getAbsolutePath()));
+                } else {
+                    sourceResource = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(Path.fromOSString(file.getAbsolutePath()));
+                }
+                if (sourceResource != null && sourceResource.exists()) {
+                    sourceLocation = sourceResource.getPersistentProperty(TmfCommonConstants.SOURCE_LOCATION);
+                }
+                if (sourceLocation == null) {
+                    sourceLocation = URIUtil.toUnencodedString(file.toURI());
                 }
+                resource.setPersistentProperty(TmfCommonConstants.SOURCE_LOCATION, sourceLocation);
             } catch (CoreException e) {
                 Activator.getDefault().logError(Messages.BatchImportTraceWizardErrorImportingTraceResource
                         + ' ' + resource.getName(), e);
             }
         }
-        return validate;
+        return status;
     }
 
     @Override
index a0b41f076cbae76262db0c650786a4ce3b3a576c..90ef87c8c6aa19ecc9f87ee9723d150a505b2027 100644 (file)
@@ -43,6 +43,7 @@ import org.eclipse.core.runtime.Platform;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.SubMonitor;
 import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.core.runtime.URIUtil;
 import org.eclipse.jface.dialogs.IDialogSettings;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.operation.IRunnableWithProgress;
@@ -918,6 +919,25 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
             operation.setVirtualFolders(false);
 
             operation.run(new SubProgressMonitor(monitor, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
+
+            File file = (File) fileSystemElement.getFileSystemObject();
+            String sourceLocation = null;
+            IResource sourceResource;
+            if (file.isDirectory()) {
+                sourceResource = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(Path.fromOSString(file.getAbsolutePath()));
+            } else {
+                sourceResource = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(Path.fromOSString(file.getAbsolutePath()));
+            }
+            if (sourceResource != null && sourceResource.exists()) {
+                sourceLocation = sourceResource.getPersistentProperty(TmfCommonConstants.SOURCE_LOCATION);
+            }
+            if (sourceLocation == null) {
+                sourceLocation = URIUtil.toUnencodedString(file.toURI());
+            }
+            IPath path = fContainerPath.addTrailingSeparator().append(fileSystemElement.getLabel());
+            IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
+            resource.setPersistentProperty(TmfCommonConstants.SOURCE_LOCATION, sourceLocation);
+
             return true;
         }
 
This page took 0.036088 seconds and 5 git commands to generate.