Search in sources :

Example 1 with TracePackageTraceElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.

the class ImportHandler method execute.

// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }
    CommandParameter param;
    fLock.lock();
    try {
        param = fParam;
        if (param == null) {
            return null;
        }
        param = param.clone();
    } finally {
        fLock.unlock();
    }
    // create default project
    IProject project = TmfProjectRegistry.createProject(RemoteFetchLogWizardRemotePage.DEFAULT_REMOTE_PROJECT_NAME, null, null);
    if (param.getSession().isLiveTrace()) {
        importLiveTrace(new LttngRelaydConnectionInfo(param.getSession().getLiveUrl(), param.getSession().getLivePort(), param.getSession().getName()), project);
        return null;
    } else if (param.getSession().isStreamedTrace()) {
        IPreferenceStore store = Activator.getDefault().getPreferenceStore();
        String notify = store.getString(NOTIFY_IMPORT_STREAMED_PREF_KEY);
        if (!MessageDialogWithToggle.ALWAYS.equals(notify)) {
            MessageDialogWithToggle.openInformation(window.getShell(), null, Messages.TraceControl_ImportDialogStreamedTraceNotification, Messages.TraceControl_ImportDialogStreamedTraceNotificationToggle, false, store, NOTIFY_IMPORT_STREAMED_PREF_KEY);
        }
        // Streamed trace
        TmfProjectElement projectElement = TmfProjectRegistry.getProject(project, true);
        TmfTraceFolder traceFolder = projectElement.getTracesFolder();
        ImportTraceWizard wizard = new ImportTraceWizard();
        wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(traceFolder));
        WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
        dialog.open();
        return null;
    }
    // Generate the profile
    TraceSessionComponent session = param.getSession();
    // $NON-NLS-1$
    RemoteImportProfileElement profile = new RemoteImportProfileElement(null, "LTTng Remote Traces");
    RemoteSystemProxy proxy = session.getTargetNode().getRemoteSystemProxy();
    IRemoteConnection rc = proxy.getRemoteConnection();
    String name = rc.getName();
    if (!rc.hasService(IRemoteConnectionHostService.class)) {
        return null;
    }
    String scheme = rc.getConnectionType().getScheme();
    IRemoteConnectionHostService hostService = checkNotNull(rc.getService(IRemoteConnectionHostService.class));
    String address = hostService.getHostname();
    String user = hostService.getUsername();
    int port = hostService.getPort();
    URI remoteUri;
    try {
        remoteUri = new URI(scheme, user, address, port, null, null, null);
    } catch (URISyntaxException e) {
        return false;
    }
    RemoteImportConnectionNodeElement connection = new RemoteImportConnectionNodeElement(profile, name, remoteUri.toString());
    String pathString = session.isSnapshotSession() ? session.getSnapshotInfo().getSnapshotPath() : session.getSessionPath();
    IPath path = new Path(pathString);
    RemoteImportTraceGroupElement group = new RemoteImportTraceGroupElement(connection, path.toString());
    group.setRecursive(true);
    // $NON-NLS-1$//$NON-NLS-2$
    TracePackageElement element = new TracePackageTraceElement(group, "", "");
    // $NON-NLS-1$
    new TracePackageFilesElement(element, ".*");
    String experimentName = path.lastSegment();
    if (!experimentName.startsWith(session.getName())) {
        experimentName = session.getName();
    }
    RemoteFetchLogWizard wizard = new RemoteFetchLogWizard(profile, experimentName);
    wizard.init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
    WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
    dialog.open();
    return null;
}
Also used : RemoteImportConnectionNodeElement(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportConnectionNodeElement) IRemoteConnectionHostService(org.eclipse.remote.core.IRemoteConnectionHostService) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) TmfProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement) URISyntaxException(java.net.URISyntaxException) RemoteImportProfileElement(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportProfileElement) URI(java.net.URI) ImportTraceWizard(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportTraceWizard) TmfTraceFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) RemoteFetchLogWizard(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.RemoteFetchLogWizard) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) TraceSessionComponent(org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent) IPath(org.eclipse.core.runtime.IPath) IRemoteConnection(org.eclipse.remote.core.IRemoteConnection) TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) RemoteImportTraceGroupElement(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportTraceGroupElement) IProject(org.eclipse.core.resources.IProject) RemoteSystemProxy(org.eclipse.tracecompass.tmf.remote.core.proxy.RemoteSystemProxy) LttngRelaydConnectionInfo(org.eclipse.tracecompass.internal.lttng2.control.ui.relayd.LttngRelaydConnectionInfo) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 2 with TracePackageTraceElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.

the class RemoteFetchLogWizardRemotePage method createElementViewer.

@Override
protected void createElementViewer(Composite compositeParent) {
    super.createElementViewer(compositeParent);
    CheckboxTreeViewer elementViewer = getElementViewer();
    elementViewer.setLabelProvider(new TracePackageLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof TracePackageTraceElement) {
                for (TracePackageElement files : ((TracePackageTraceElement) element).getChildren()) {
                    if (files instanceof TracePackageFilesElement) {
                        return ((TracePackageFilesElement) files).getFileName();
                    }
                }
            }
            return super.getText(element);
        }

        @Override
        public Image getImage(Object element) {
            if (element instanceof TracePackageTraceElement) {
                for (TracePackageElement files : ((TracePackageTraceElement) element).getChildren()) {
                    return files.getImage();
                }
            }
            return super.getImage(element);
        }
    });
    elementViewer.setComparator(new ViewerComparator() {

        @Override
        public int category(Object element) {
            if (element instanceof TracePackageTraceElement) {
                return 1;
            }
            return 0;
        }
    });
}
Also used : CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) TracePackageLabelProvider(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageLabelProvider) Image(org.eclipse.swt.graphics.Image)

Example 3 with TracePackageTraceElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.

the class RemoteImportProfilesWriter method exportTraceGroup.

private static void exportTraceGroup(Node nodeNode, RemoteImportTraceGroupElement traceGroup) {
    Element traceGroupElement = nodeNode.getOwnerDocument().createElement(RemoteImportProfileConstants.TRACE_GROUP_ELEMENT);
    traceGroupElement.setAttribute(RemoteImportProfileConstants.TRACE_GROUP_ROOT_ATTRIB, traceGroup.getRootImportPath());
    traceGroupElement.setAttribute(RemoteImportProfileConstants.TRACE_GROUP_RECURSIVE_ATTRIB, Boolean.toString(traceGroup.isRecursive()));
    for (TracePackageElement trace : traceGroup.getChildren()) {
        if (trace instanceof TracePackageTraceElement) {
            exportTrace(traceGroupElement, (TracePackageTraceElement) trace);
        }
    }
    nodeNode.appendChild(traceGroupElement);
}
Also used : TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) Element(org.w3c.dom.Element) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement)

Example 4 with TracePackageTraceElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement 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 TracePackageTraceElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.

the class RemoteProfilesPreferencePage method newTraceGroup.

private RemoteImportTraceGroupElement newTraceGroup(TracePackageElement parent, TracePackageElement previous) {
    RemoteImportTraceGroupElement traceGroup = new RemoteImportTraceGroupElement(null, DEFAULT_ROOT_IMPORT_PATH);
    TracePackageTraceElement trace = new TracePackageTraceElement(traceGroup, DEFAULT_IMPORT_NAME, null);
    new TracePackageFilesElement(trace, DEFAULT_FILE_PATTERN);
    int index = previous == null ? parent.getChildren().length : parent.indexOf(previous) + 1;
    parent.addChild(index, traceGroup);
    newElementAdded(traceGroup);
    return traceGroup;
}
Also used : TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) RemoteImportTraceGroupElement(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportTraceGroupElement)

Aggregations

TracePackageTraceElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement)32 TracePackageElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement)23 TracePackageFilesElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement)22 RemoteImportConnectionNodeElement (org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportConnectionNodeElement)9 RemoteImportTraceGroupElement (org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportTraceGroupElement)9 TracePackageExperimentElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement)9 ArrayList (java.util.ArrayList)8 RemoteImportProfileElement (org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportProfileElement)8 Element (org.w3c.dom.Element)7 IPath (org.eclipse.core.runtime.IPath)6 TracePackageBookmarkElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement)6 TracePackageSupplFileElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement)6 TracePackageSupplFilesElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement)6 TmfCommonProjectElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement)6 TmfExperimentElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement)6 TmfTraceElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement)6 Path (org.eclipse.core.runtime.Path)4 Node (org.w3c.dom.Node)4 URI (java.net.URI)3 HashMap (java.util.HashMap)3