From: Patrick Tasse Date: Wed, 26 Mar 2014 20:45:36 +0000 (-0400) Subject: tmf: Add source location to trace properties X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=89730b51d3b2a2edeca0afbc9ee072e6724b3a64;p=deliverable%2Ftracecompass.git tmf: Add source location to trace properties 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:// file:/// - Import Trace Package wizard jar:file://!// jar:file://!/// - Import action in LTTng Control view sftp://:// sftp://:/// Change-Id: I6bc4dc52bbbddd03d6f33ac4fc3d194cc1bded74 Signed-off-by: Patrick Tasse Reviewed-on: https://git.eclipse.org/r/24268 Tested-by: Hudson CI Reviewed-by: Matthew Khouzam Tested-by: Matthew Khouzam --- diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/ImportHandler.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/ImportHandler.java index 61ca39605c..838722c1a7 100644 --- a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/ImportHandler.java +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/ImportHandler.java @@ -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) { diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/TmfCommonConstants.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/TmfCommonConstants.java index f77e40b043..00419bf35d 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/TmfCommonConstants.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/TmfCommonConstants.java @@ -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. diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DropAdapterAssistant.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DropAdapterAssistant.java index ccfb5f6449..bc04703eae 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DropAdapterAssistant.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DropAdapterAssistant.java @@ -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; } 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 f9ed1236ed..89681a1be0 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 @@ -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); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/Messages.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/Messages.java index d18a067b56..0b422fbb88 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/Messages.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/Messages.java @@ -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; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfOpenTraceHelper.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfOpenTraceHelper.java index ba4cd3873c..b08fa2d7c5 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfOpenTraceHelper.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfOpenTraceHelper.java @@ -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; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfProjectModelElement.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfProjectModelElement.java index 17a1a5b240..28811ee39b 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfProjectModelElement.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfProjectModelElement.java @@ -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<>(); } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java index f5b1a65c5b..e1fa92fc89 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java @@ -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)) { diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceTypeUIUtils.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceTypeUIUtils.java index ca76dba813..587254e897 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceTypeUIUtils.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceTypeUIUtils.java @@ -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> candidates = new ArrayList<>(validCandidates); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/messages.properties b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/messages.properties index e59c031eab..1d5c3a924a 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/messages.properties +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/messages.properties @@ -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 diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/BatchImportTraceWizard.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/BatchImportTraceWizard.java index 816949f013..915e5978a3 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/BatchImportTraceWizard.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/BatchImportTraceWizard.java @@ -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 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 diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/ImportTraceWizardPage.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/ImportTraceWizardPage.java index a0b41f076c..90ef87c8c6 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/ImportTraceWizardPage.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/ImportTraceWizardPage.java @@ -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; }