* 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;
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;
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;
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) {
*
* Contributors:
* Bernd Hufmann - Initial API and implementation
+ * Patrick Tasse - Add support for source location
*******************************************************************************/
package org.eclipse.linuxtools.tmf.core;
*/
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.
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;
} 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;
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) {
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();
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;
}
*
* 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;
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;
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;
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;
return;
}
+ TracePackageFilesElement traceFilesElement = null;
for (TracePackageElement packageElement : fImportTraceElements) {
TracePackageTraceElement traceElement = (TracePackageTraceElement) packageElement;
if (!isFilesChecked(packageElement)) {
ModalContext.checkCanceled(progressMonitor);
if (element instanceof TracePackageFilesElement) {
- TracePackageFilesElement traceFilesElement = (TracePackageFilesElement) element;
+ traceFilesElement = (TracePackageFilesElement) element;
setStatus(importTraceFiles(traceFilesElement, progressMonitor));
} else if (element instanceof TracePackageSupplFilesElement) {
}
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);
/*******************************************************************************
- * 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
*
* Contributors:
* Jean-Christian Kouamé - Initial API and implementation
+ * Patrick Tasse - Add support for source location
*******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.project.model;
/** 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;
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;
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;
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;
fName = name;
fResource = resource;
fPath = resource.getFullPath();
- fLocation = resource.getLocationURI();
+ fLocation = new File(resource.getLocationURI()).toURI();
fParent = parent;
fChildren = new CopyOnWriteArrayList<>();
}
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;
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);
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);
sfLocationDescriptor.setCategory(sfResourcePropertiesCategory);
sfTypeDescriptor.setCategory(sfResourcePropertiesCategory);
sfIsLinkedDescriptor.setCategory(sfResourcePropertiesCategory);
+ sfSourceLocationDescriptor.setCategory(sfResourcePropertiesCategory);
}
// ------------------------------------------------------------------------
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)) {
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;
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);
###############################################################################
-# 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
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
* 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;
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;
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;
success = false;
}
else {
- success = setTraceType(traceToImport).isOK();
+ success = setTraceTypeAndSourceLocation(traceToImport).isOK();
}
}
else {
}
resource.create(source, true, new NullProgressMonitor());
}
- setTraceType(traceToImport);
+ setTraceTypeAndSourceLocation(traceToImport);
success = true;
}
} else {
operation.setContext(getShell());
operation.setCreateContainerStructure(false);
if (executeImportOperation(operation)) {
- setTraceType(traceToImport);
+ setTraceTypeAndSourceLocation(traceToImport);
success = true;
}
}
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 {
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
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;
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;
}