Search in sources :

Example 1 with TraceTypeHelper

use of org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper in project tracecompass by tracecompass.

the class ImportHandler method initializeTraceResource.

private static void initializeTraceResource(final LttngRelaydConnectionInfo connectionInfo, final String tracePath, final IProject project) throws CoreException, TmfTraceImportException {
    final TmfProjectElement projectElement = TmfProjectRegistry.getProject(project, true);
    final TmfTraceFolder tracesFolder = projectElement.getTracesFolder();
    if (tracesFolder != null) {
        IFolder folder = tracesFolder.getResource();
        IFolder traceFolder = folder.getFolder(connectionInfo.getSessionName());
        Path location = new Path(tracePath);
        IStatus result = ResourcesPlugin.getWorkspace().validateLinkLocation(folder, location);
        if (result.isOK()) {
            traceFolder.createLink(location, IResource.REPLACE, new NullProgressMonitor());
        } else {
            throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, result.getMessage()));
        }
        TraceTypeHelper selectedTraceType = TmfTraceTypeUIUtils.selectTraceType(location.toOSString(), null, null);
        // No trace type was determined.
        TmfTraceTypeUIUtils.setTraceType(traceFolder, selectedTraceType);
        TmfTraceElement found = null;
        final List<TmfTraceElement> traces = tracesFolder.getTraces();
        for (TmfTraceElement candidate : traces) {
            if (candidate.getName().equals(connectionInfo.getSessionName())) {
                found = candidate;
            }
        }
        if (found == null) {
            throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_LiveTraceElementError));
        }
        // Properties used to be able to reopen a trace in live mode
        traceFolder.setPersistentProperty(CtfConstants.LIVE_HOST, connectionInfo.getHost());
        traceFolder.setPersistentProperty(CtfConstants.LIVE_PORT, Integer.toString(connectionInfo.getPort()));
        traceFolder.setPersistentProperty(CtfConstants.LIVE_SESSION_NAME, connectionInfo.getSessionName());
        final TmfTraceElement finalTrace = found;
        Display.getDefault().syncExec(() -> TmfOpenTraceHelper.openFromElement(finalTrace));
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) TraceTypeHelper(org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper) CoreException(org.eclipse.core.runtime.CoreException) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) TmfTraceFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder) TmfProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with TraceTypeHelper

use of org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper in project tracecompass by tracecompass.

the class TmfAnalysisModuleHelperXml method appliesToTraceType.

@Override
public boolean appliesToTraceType(Class<? extends ITmfTrace> traceClass) {
    /* Trace types may be available in XML header */
    List<Element> head = TmfXmlUtils.getChildElements(fSourceElement, TmfXmlStrings.HEAD);
    if (head.size() != 1) {
        return true;
    }
    /*
         * TODO: Test with custom trace types
         */
    List<Element> elements = TmfXmlUtils.getChildElements(head.get(0), TmfXmlStrings.TRACETYPE);
    if (elements.isEmpty()) {
        return true;
    }
    for (Element element : elements) {
        String traceTypeId = element.getAttribute(TmfXmlStrings.ID);
        traceTypeId = TmfTraceType.buildCompatibilityTraceTypeId(traceTypeId);
        TraceTypeHelper helper = TmfTraceType.getTraceType(traceTypeId);
        if ((helper != null) && helper.getTrace().getClass().isAssignableFrom(traceClass)) {
            return true;
        }
    }
    return false;
}
Also used : TraceTypeHelper(org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper) Element(org.w3c.dom.Element)

Example 3 with TraceTypeHelper

use of org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper in project tracecompass by tracecompass.

the class TmfFilterContentHandler method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
    ITmfFilterTreeNode node = null;
    if (localName.equalsIgnoreCase(TmfFilterRootNode.NODE_NAME)) {
        node = new TmfFilterRootNode();
    } else if (localName.equals(TmfFilterNode.NODE_NAME)) {
        node = new TmfFilterNode(atts.getValue(TmfFilterNode.NAME_ATTR));
    } else if (localName.equals(TmfFilterTraceTypeNode.NODE_NAME)) {
        node = new TmfFilterTraceTypeNode(null);
        String traceTypeId = atts.getValue(TmfFilterTraceTypeNode.TYPE_ATTR);
        traceTypeId = TmfTraceType.buildCompatibilityTraceTypeId(traceTypeId);
        ((TmfFilterTraceTypeNode) node).setTraceTypeId(traceTypeId);
        TraceTypeHelper helper = TmfTraceType.getTraceType(traceTypeId);
        if (helper != null) {
            ((TmfFilterTraceTypeNode) node).setTraceClass(helper.getTraceClass());
        }
        ((TmfFilterTraceTypeNode) node).setName(atts.getValue(TmfFilterTraceTypeNode.NAME_ATTR));
    } else if (localName.equals(TmfFilterAndNode.NODE_NAME)) {
        node = new TmfFilterAndNode(null);
    } else if (localName.equals(TmfFilterOrNode.NODE_NAME)) {
        node = new TmfFilterOrNode(null);
    } else if (localName.equals(TmfFilterContainsNode.NODE_NAME)) {
        node = new TmfFilterContainsNode(null);
        createEventAspect((TmfFilterAspectNode) node, atts);
        String value = atts.getValue(TmfFilterContainsNode.IGNORECASE_ATTR);
        if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {
            ((TmfFilterContainsNode) node).setIgnoreCase(true);
        }
    } else if (localName.equals(TmfFilterEqualsNode.NODE_NAME)) {
        node = new TmfFilterEqualsNode(null);
        createEventAspect((TmfFilterAspectNode) node, atts);
        String value = atts.getValue(TmfFilterEqualsNode.IGNORECASE_ATTR);
        if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {
            ((TmfFilterEqualsNode) node).setIgnoreCase(true);
        }
    } else if (localName.equals(TmfFilterMatchesNode.NODE_NAME)) {
        node = new TmfFilterMatchesNode(null);
        createEventAspect((TmfFilterAspectNode) node, atts);
        ((TmfFilterMatchesNode) node).setRegex(atts.getValue(TmfFilterMatchesNode.REGEX_ATTR));
    } else if (localName.equals(TmfFilterCompareNode.NODE_NAME)) {
        node = new TmfFilterCompareNode(null);
        createEventAspect((TmfFilterAspectNode) node, atts);
        String value = atts.getValue(TmfFilterCompareNode.TYPE_ATTR);
        if (value != null) {
            ((TmfFilterCompareNode) node).setType(Type.valueOf(value));
        }
        value = atts.getValue(TmfFilterCompareNode.RESULT_ATTR);
        if (value != null) {
            if (value.equals(Integer.toString(-1))) {
                ((TmfFilterCompareNode) node).setResult(-1);
            } else if (value.equals(Integer.toString(1))) {
                ((TmfFilterCompareNode) node).setResult(1);
            } else {
                ((TmfFilterCompareNode) node).setResult(0);
            }
        }
    // Backward compatibility with event type filter node
    } else if (localName.equals(EVENTTYPE_NODE_NAME)) {
        node = new TmfFilterTraceTypeNode(null);
        String label = atts.getValue(NAME_ATTR);
        if (label != null) {
            // Backward compatibility with renamed LTTng Kernel Trace
            if (label.equals(LTTNG_KERNEL_TRACE)) {
                label = LINUX_KERNEL_TRACE;
            }
            String traceTypeId = TmfTraceType.getTraceTypeId(label);
            TraceTypeHelper helper = TmfTraceType.getTraceType(traceTypeId);
            if (helper == null) {
                // Backward compatibility with category-less custom trace types
                for (TraceTypeHelper h : TmfTraceType.getTraceTypeHelpers()) {
                    if (h.getName().equals(label)) {
                        label = h.getLabel();
                        helper = h;
                        break;
                    }
                }
            }
            if (helper != null) {
                ((TmfFilterTraceTypeNode) node).setTraceTypeId(helper.getTraceTypeId());
                ((TmfFilterTraceTypeNode) node).setTraceClass(helper.getTraceClass());
            }
            ((TmfFilterTraceTypeNode) node).setName(label);
        }
    }
    String value = atts.getValue(ITmfFilterWithNot.NOT_ATTRIBUTE);
    if (node instanceof ITmfFilterWithNot && Boolean.TRUE.toString().equalsIgnoreCase(value)) {
        ((ITmfFilterWithNot) node).setNot(true);
    }
    if (node instanceof ITmfFilterWithValue) {
        ((ITmfFilterWithValue) node).setValue(atts.getValue(ITmfFilterWithValue.VALUE_ATTRIBUTE));
    }
    fFilterTreeStack.addFirst(node);
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) TmfFilterAndNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode) TmfFilterContainsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode) TmfFilterMatchesNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode) TmfFilterTraceTypeNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode) ITmfFilterWithValue(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterWithValue) TraceTypeHelper(org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper) TmfFilterOrNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode) TmfFilterAspectNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAspectNode) TmfFilterEqualsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode) TmfFilterNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode) TmfFilterRootNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode) TmfFilterCompareNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode) ITmfFilterWithNot(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterWithNot)

Example 4 with TraceTypeHelper

use of org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper 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);
            }
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) SubMonitor(org.eclipse.core.runtime.SubMonitor) URI(java.net.URI) IFileInfo(org.eclipse.core.filesystem.IFileInfo) TraceTypeHelper(org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper) TmfTraceImportException(org.eclipse.tracecompass.tmf.core.project.model.TmfTraceImportException) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) IFileStore(org.eclipse.core.filesystem.IFileStore) IFileSystemObject(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.IFileSystemObject) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) ExecutionException(org.eclipse.core.commands.ExecutionException) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 5 with TraceTypeHelper

use of org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper 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);
    }
}
Also used : TraceTypeHelper(org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper) TmfTraceImportException(org.eclipse.tracecompass.tmf.core.project.model.TmfTraceImportException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IResource(org.eclipse.core.resources.IResource)

Aggregations

TraceTypeHelper (org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper)24 IFolder (org.eclipse.core.resources.IFolder)9 CoreException (org.eclipse.core.runtime.CoreException)8 IFile (org.eclipse.core.resources.IFile)6 IPath (org.eclipse.core.runtime.IPath)6 IStatus (org.eclipse.core.runtime.IStatus)6 TmfTraceImportException (org.eclipse.tracecompass.tmf.core.project.model.TmfTraceImportException)6 IResource (org.eclipse.core.resources.IResource)5 Path (org.eclipse.core.runtime.Path)4 File (java.io.File)3 URI (java.net.URI)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 Status (org.eclipse.core.runtime.Status)3 TmfProjectElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement)3 TmfTraceElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement)3 TmfTraceFolder (org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder)3 HashMap (java.util.HashMap)2 IFileInfo (org.eclipse.core.filesystem.IFileInfo)2 SubMonitor (org.eclipse.core.runtime.SubMonitor)2 TreeColumn (org.eclipse.swt.widgets.TreeColumn)2