use of org.eclipse.tracecompass.tmf.core.project.model.TmfTraceImportException in project tracecompass by tracecompass.
the class RemoteImportTracesOperation method doRun.
// ------------------------------------------------------------------------
// Helper methods
// ------------------------------------------------------------------------
private void doRun(IProgressMonitor monitor) throws ExecutionException, CoreException, IOException, InterruptedException {
IFolder destinationFolder = fDestination.getResource();
if (!destinationFolder.exists()) {
// $NON-NLS-1$//$NON-NLS-2$
throw new ExecutionException(RemoteMessages.RemoteImportTracesOperation_ImportDialogInvalidTracingProject + " (" + destinationFolder + ")");
}
SubMonitor subMonitor = SubMonitor.convert(monitor, fTraceElements.length * 4);
subMonitor.beginTask(RemoteMessages.RemoteImportTracesOperation_DownloadTask, fTraceElements.length * 4);
for (Object packageElement : fTraceElements) {
if (!(packageElement instanceof TracePackageTraceElement)) {
continue;
}
TracePackageTraceElement traceElement = (TracePackageTraceElement) packageElement;
TracePackageElement parentElement = traceElement.getParent();
while (parentElement != null) {
if (parentElement instanceof RemoteImportTraceGroupElement) {
break;
}
parentElement = parentElement.getParent();
}
if (parentElement == null) {
continue;
}
RemoteImportTraceGroupElement traceGroup = (RemoteImportTraceGroupElement) parentElement;
String rootPath = traceGroup.getRootImportPath();
// Create folder with node name in destination folder
RemoteImportConnectionNodeElement nodeElement = (RemoteImportConnectionNodeElement) traceGroup.getParent();
String nodeName = nodeElement.getName();
IFolder nodeFolder = destinationFolder.getFolder(nodeName);
TracePackageElement[] children = traceElement.getChildren();
SubMonitor childMonitor = subMonitor.newChild(1);
TraceUtils.createFolder(nodeFolder, childMonitor);
for (TracePackageElement element : children) {
ModalContext.checkCanceled(monitor);
if (element instanceof RemoteImportTraceFilesElement) {
RemoteImportTraceFilesElement traceFilesElement = (RemoteImportTraceFilesElement) element;
IFileStore remoteFile = traceFilesElement.getRemoteFile();
// Preserve folder structure
IPath sessionParentPath = TmfTraceCoreUtils.newSafePath(rootPath).removeLastSegments(1);
IPath traceParentPath = TmfTraceCoreUtils.newSafePath(remoteFile.getParent().toURI().getPath());
IPath relativeTracePath = Path.EMPTY;
if (sessionParentPath.isPrefixOf(traceParentPath)) {
relativeTracePath = traceParentPath.makeRelativeTo(sessionParentPath);
}
String[] segments = relativeTracePath.segments();
for (int i = 0; i < segments.length; i++) {
String segment = TmfTraceCoreUtils.validateName(TmfTraceCoreUtils.safePathToString(segments[i]));
if (i == 0) {
relativeTracePath = new Path(segment);
} else {
relativeTracePath = relativeTracePath.append(segment);
}
}
IFolder traceFolder = nodeFolder.getFolder(new Path(relativeTracePath.toOSString()));
childMonitor = subMonitor.newChild(1);
TraceUtils.createFolder(traceFolder, childMonitor);
childMonitor.done();
// Import trace
IResource traceRes = null;
IFileInfo info = remoteFile.fetchInfo();
if (info.isDirectory()) {
traceRes = downloadDirectoryTrace(remoteFile, traceFolder, subMonitor.newChild(1));
} else {
traceRes = downloadFileTrace(remoteFile, traceFolder, subMonitor.newChild(1));
}
String traceName = traceElement.getText();
if (traceRes == null || !traceRes.exists()) {
continue;
}
// Select trace type
TraceTypeHelper traceTypeHelper = null;
String traceTypeStr = traceElement.getTraceType();
if (traceTypeStr != null) {
traceTypeHelper = TmfTraceType.getTraceType(traceTypeStr);
}
// no specific trace type found
if (traceTypeHelper == null) {
try {
// Try to auto-detect the trace typ
childMonitor = subMonitor.newChild(1);
childMonitor.setTaskName(NLS.bind(RemoteMessages.RemoteImportTracesOperation_DetectingTraceType, traceName));
childMonitor.done();
traceTypeHelper = TmfTraceTypeUIUtils.selectTraceType(traceRes.getLocation().toOSString(), null, null);
} catch (TmfTraceImportException e) {
// Could not figure out the type
}
}
if (traceTypeHelper != null) {
TmfTraceTypeUIUtils.setTraceType(traceRes, traceTypeHelper);
fImportedResources.add(traceRes);
}
// Set source location
URI uri = remoteFile.toURI();
String sourceLocation = URIUtil.toUnencodedString(uri);
traceRes.setPersistentProperty(TmfCommonConstants.SOURCE_LOCATION, sourceLocation);
}
}
}
}
use of org.eclipse.tracecompass.tmf.core.project.model.TmfTraceImportException in project tracecompass by tracecompass.
the class TraceValidateAndImportOperation method validateAndImportTrace.
/**
* Import a single file system element into the workspace.
*/
private void validateAndImportTrace(TraceFileSystemElement fileSystemElement, IProgressMonitor monitor) throws TmfTraceImportException, CoreException, InvocationTargetException, InterruptedException {
String path = fileSystemElement.getFileSystemObject().getAbsolutePath();
TraceTypeHelper traceTypeHelper = null;
// $NON-NLS-1$
monitor.setTaskName(Messages.ImportTraceWizard_ExamineOperationTaskName + " " + fileSystemElement.getFileSystemObject().getAbsolutePath());
if ((fImportOptionFlags & ImportTraceWizardPage.OPTION_SKIP_ARCHIVE_EXTRACTION) == 0) {
File file = (File) fileSystemElement.getFileSystemObject().getRawFileSystemObject();
boolean isArchiveFileElement = fileSystemElement.getFileSystemObject() instanceof FileFileSystemObject && ArchiveUtil.isArchiveFile(file);
if (isArchiveFileElement) {
// We'll be extracting this later, do not import as a trace
return;
}
}
if (fTraceType == null) {
// Auto Detection
try {
traceTypeHelper = TmfTraceTypeUIUtils.selectTraceType(path, null, null);
} catch (TmfTraceImportException e) {
// the trace did not match any trace type
}
if (traceTypeHelper == null) {
if ((fImportOptionFlags & ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES) != 0) {
importResource(fileSystemElement, monitor);
}
return;
}
} else {
boolean isDirectoryTraceType = TmfTraceType.isDirectoryTraceType(fTraceType);
if (fileSystemElement.isDirectory() != isDirectoryTraceType) {
return;
}
traceTypeHelper = TmfTraceType.getTraceType(fTraceType);
if (traceTypeHelper == null) {
// Trace type not found
throw new TmfTraceImportException(Messages.ImportTraceWizard_TraceTypeNotFound);
}
if (!traceTypeHelper.validate(path).isOK()) {
// Trace type exist but doesn't validate for given trace.
return;
}
}
// Finally import trace
TraceFileSystemElement resourceToImport = filterSelectedFileSystemElement(fileSystemElement, monitor);
if (resourceToImport == null) {
return;
}
IResource importedResource = importResource(resourceToImport, monitor);
if (importedResource != null) {
TmfTraceTypeUIUtils.setTraceType(importedResource, traceTypeHelper, false);
fImportedResources.add(importedResource);
}
}
use of org.eclipse.tracecompass.tmf.core.project.model.TmfTraceImportException in project tracecompass by tracecompass.
the class TracePackageImportOperation method importTraceFiles.
private IStatus importTraceFiles(TracePackageFilesElement traceFilesElement, TracePackageTraceElement traceElement, IProgressMonitor monitor) {
List<Pair<String, String>> fileNameAndLabelPairs = new ArrayList<>();
String sourceName = checkNotNull(traceFilesElement.getFileName());
String destinationName = checkNotNull(traceElement.getImportName());
fileNameAndLabelPairs.add(new Pair<>(sourceName, destinationName));
IPath containerPath = fTmfTraceFolder.getPath();
IStatus status = importFiles(getSpecifiedArchiveFile(), fileNameAndLabelPairs, containerPath, Path.EMPTY, Collections.emptyMap(), monitor);
if (!getStatus().isOK()) {
return status;
}
// We need to set the trace type before importing the supplementary files so we do it here
IResource traceRes = fTmfTraceFolder.getResource().findMember(traceElement.getDestinationElementPath());
if (traceRes == null || !traceRes.exists()) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format(Messages.ImportTracePackageWizardPage_ErrorFindingImportedTrace, destinationName));
}
TraceTypeHelper traceType = null;
String traceTypeStr = traceElement.getTraceType();
if (traceTypeStr != null) {
traceType = TmfTraceType.getTraceType(traceTypeStr);
if (traceType == null) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format(Messages.ImportTracePackageWizardPage_ErrorSettingTraceType, traceElement.getTraceType(), destinationName));
}
} else {
try {
monitor.subTask(MessageFormat.format(Messages.TracePackageImportOperation_DetectingTraceType, destinationName));
traceType = TmfTraceTypeUIUtils.selectTraceType(traceRes.getLocation().toOSString(), null, null);
} catch (TmfTraceImportException e) {
// Could not figure out the type
}
}
if (traceType != null) {
try {
TmfTraceTypeUIUtils.setTraceType(traceRes, traceType);
} catch (CoreException e) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format(Messages.ImportTracePackageWizardPage_ErrorSettingTraceType, traceElement.getTraceType(), destinationName), e);
}
}
importBookmarks(traceRes, traceElement, monitor);
try {
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) {
}
return status;
}
use of org.eclipse.tracecompass.tmf.core.project.model.TmfTraceImportException in project tracecompass by tracecompass.
the class TmfOpenTraceHelper method openTraceFromPath.
/**
* Opens a trace from a path while importing it to the destination folder.
* The trace is linked as a resource.
*
* @param destinationFolder
* The destination trace folder
* @param path
* the file to import
* @param shell
* the shell to use for dialogs
* @param tracetypeHint
* The trace type id, can be null
* @return IStatus OK if successful. In addition to the OK status, a code OK
* means the trace will be opened correctly, otherwise, a code of
* {@link IStatus#INFO} means the operation completely successfully,
* but the path won't be opened as a trace.
* @throws CoreException
* core exceptions if something is not well set up in the back
* end
*/
public static IStatus openTraceFromPath(TmfTraceFolder destinationFolder, String path, Shell shell, String tracetypeHint) throws CoreException {
final String pathToUse = checkTracePath(path);
TraceTypeHelper traceTypeToSet = null;
try (ScopeLog scopeLog = new ScopeLog(LOGGER, Level.FINE, "TmfOpenTraceHelper#openTraceFromPath", "Get trace type")) {
// $NON-NLS-1$//$NON-NLS-2$
traceTypeToSet = TmfTraceTypeUIUtils.selectTraceType(pathToUse, null, tracetypeHint);
} catch (TmfTraceImportException e) {
TraceUtils.displayErrorMsg(e);
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage());
}
IFolder folder = destinationFolder.getResource();
String traceName = getTraceName(pathToUse, folder);
if (traceExists(pathToUse, folder)) {
return openTraceFromFolder(destinationFolder, traceName);
}
final IPath pathString = Path.fromOSString(pathToUse);
IResource linkedTrace = TmfImportHelper.createLink(folder, pathString, traceName);
if (linkedTrace == null || !linkedTrace.exists()) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TmfOpenTraceHelper_LinkFailed);
}
String sourceLocation = URIUtil.toUnencodedString(pathString.toFile().toURI());
linkedTrace.setPersistentProperty(TmfCommonConstants.SOURCE_LOCATION, sourceLocation);
// No trace type was determined.
if (traceTypeToSet == null) {
return new Status(IStatus.OK, Activator.PLUGIN_ID, IStatus.INFO, Messages.TmfOpenTraceHelper_NoTraceType, null);
}
IStatus ret = TmfTraceTypeUIUtils.setTraceType(linkedTrace, traceTypeToSet);
if (ret.isOK()) {
ret = openTraceFromFolder(destinationFolder, traceName);
}
return ret;
}
use of org.eclipse.tracecompass.tmf.core.project.model.TmfTraceImportException in project tracecompass by tracecompass.
the class ImportHandler method importLiveTrace.
// ------------------------------------------------------------------------
// Helper methods
// ------------------------------------------------------------------------
private static void importLiveTrace(final LttngRelaydConnectionInfo connectionInfo, final IProject project) {
Job job = new Job(Messages.TraceControl_ImportJob) {
@Override
protected IStatus run(final IProgressMonitor monitor) {
try {
// We initiate the connection first so that we can retrieve the trace path
LttngRelaydConsumer lttngRelaydConsumer = LttngRelaydConnectionManager.getInstance().getConsumer(connectionInfo);
try {
lttngRelaydConsumer.connect();
} catch (CoreException e) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, org.eclipse.tracecompass.internal.lttng2.control.ui.relayd.Messages.LttngRelaydConnectionManager_ConnectionError, e);
}
initializeTraceResource(connectionInfo, lttngRelaydConsumer.getTracePath(), project);
return Status.OK_STATUS;
} catch (CoreException | TmfTraceImportException e) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_LiveTraceInitError, e);
}
}
};
job.setSystem(true);
job.schedule();
}
Aggregations