Search in sources :

Example 1 with TmfTraceFolder

use of org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder 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 TmfTraceFolder

use of org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder 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 3 with TmfTraceFolder

use of org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder in project tracecompass by tracecompass.

the class XMLAnalysesManagerPreferencePage method deleteSupplementaryFiles.

/**
 * Delete the supplementary files associated with XML analysis files.
 *
 * @param xmlFiles
 *            the xml analysis files (with extension)
 * @return the list of elements that should be re-opened
 */
private static Collection<TmfCommonProjectElement> deleteSupplementaryFiles(Collection<String> xmlFiles) {
    // 1. Look for all traces that have these analyses
    // 2. Close them if they are opened, but remember them
    // 3. Delete the related supplementary files
    Collection<TmfCommonProjectElement> toReopen = new ArrayList<>();
    List<IResource> resourceToDelete = new ArrayList<>();
    Set<String> ids = Sets.newHashSet();
    xmlFiles.forEach(xmlFile -> ids.addAll(XmlUtils.getAnalysisIdsFromFile(xmlFile)));
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(0);
    for (IProject project : projects) {
        TmfProjectElement pElement = TmfProjectRegistry.getProject(project);
        if (pElement != null) {
            List<TmfCommonProjectElement> tElements = new ArrayList<>();
            TmfTraceFolder tracesFolder = pElement.getTracesFolder();
            if (tracesFolder != null) {
                tElements.addAll(tracesFolder.getTraces());
            }
            TmfExperimentFolder experimentsFolder = pElement.getExperimentsFolder();
            if (experimentsFolder != null) {
                tElements.addAll(experimentsFolder.getExperiments());
            }
            Set<IEditorReference> editorReferences = getEditorReferences();
            for (TmfCommonProjectElement tElement : tElements) {
                for (IResource resource : tElement.getSupplementaryResources()) {
                    for (String id : ids) {
                        if (resource.getName().startsWith(id)) {
                            resourceToDelete.add(resource);
                        }
                    }
                }
                IFile file = tElement.getBookmarksFile();
                FileEditorInput input = new FileEditorInput(file);
                boolean open = Iterables.any(editorReferences, editorReference -> {
                    try {
                        return editorReference.getEditorInput().equals(input);
                    } catch (PartInitException e) {
                        // $NON-NLS-1$ //$NON-NLS-2$
                        Activator.logError("Failed to test the " + tElement.getName() + " editor", e);
                        return false;
                    }
                });
                if (open) {
                    toReopen.add(tElement);
                }
                tElement.closeEditors();
            }
        }
    }
    for (IResource resource : resourceToDelete) {
        try {
            resource.delete(false, null);
        } catch (CoreException e) {
            Activator.logError(NLS.bind(Messages.ManageXMLAnalysisDialog_DeleteFileError, resource.getName()));
        }
    }
    return toReopen;
}
Also used : IFile(org.eclipse.core.resources.IFile) TmfExperimentFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentFolder) ArrayList(java.util.ArrayList) TmfProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) IProject(org.eclipse.core.resources.IProject) IEditorReference(org.eclipse.ui.IEditorReference) CoreException(org.eclipse.core.runtime.CoreException) TmfTraceFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder) FileEditorInput(org.eclipse.ui.part.FileEditorInput) PartInitException(org.eclipse.ui.PartInitException) IResource(org.eclipse.core.resources.IResource)

Example 4 with TmfTraceFolder

use of org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder in project tracecompass by tracecompass.

the class FetchRemoteTracesTest method test_8_13.

/**
 * Test 8.13: Run Profile "TestSpecificMultiGroupRecursive"
 */
@Test
public void test_8_13() {
    SWTBotView projectExplorerBot = fBot.viewByTitle(PROJECT_EXPLORER);
    projectExplorerBot.show();
    SWTBotTreeItem tracesFolderItem = getTracesFolderTreeItem(projectExplorerBot);
    tracesFolderItem.contextMenu(FETCH_COMMAND_NAME).click();
    SWTBotShell shell = fBot.shell(FETCH_SHELL_NAME).activate();
    fBot.comboBox().setSelection("TestSpecificMultiGroupRecursive");
    fBot.button("Next >").click();
    fBot.button("Finish").click();
    fBot.waitUntil(Conditions.shellCloses(shell), FETCH_TIME_OUT);
    WaitUtils.waitForJobs();
    TmfProjectElement project = TmfProjectRegistry.getProject(ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME), true);
    fBot.waitUntil(new TraceCountCondition(project, 2));
    final TmfTraceFolder tracesFolder = project.getTracesFolder();
    assertNotNull(tracesFolder);
    List<TmfTraceElement> traces = tracesFolder.getTraces();
    assertEquals(2, traces.size());
    testTrace(traces.get(0), CONNECTION_NODE1_NAME + "/resources/generated/synthetic-trace", TRACE_TYPE_KERNEL);
    testTrace(traces.get(1), CONNECTION_NODE1_NAME + "/resources/syslog", TRACE_TYPE_SYSLOG);
}
Also used : TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) TmfTraceFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) SWTBotView(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView) TmfProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) Test(org.junit.Test)

Example 5 with TmfTraceFolder

use of org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder in project tracecompass by tracecompass.

the class FetchRemoteTracesTest method test_8_06.

/**
 * Test 8.6: Re-Run Profile "TestAllRecursive" (Overwrite)
 *
 * @throws CoreException if an exception occurs
 */
@Test
public void test_8_06() throws CoreException {
    SWTBotView projectExplorerBot = fBot.viewByTitle(PROJECT_EXPLORER);
    projectExplorerBot.show();
    SWTBotTreeItem tracesFolderItem = getTracesFolderTreeItem(projectExplorerBot);
    tracesFolderItem.contextMenu(FETCH_COMMAND_NAME).click();
    SWTBotShell shell = fBot.shell(FETCH_SHELL_NAME).activate();
    fBot.comboBox().setSelection("TestAllRecursive");
    fBot.button("Next >").click();
    fBot.button("Finish").click();
    fBot.waitUntil(Conditions.shellCloses(shell), FETCH_TIME_OUT);
    WaitUtils.waitForJobs();
    TmfProjectElement project = TmfProjectRegistry.getProject(ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME), true);
    fBot.waitUntil(new TraceCountCondition(project, 3));
    final TmfTraceFolder tracesFolder = project.getTracesFolder();
    assertNotNull(tracesFolder);
    for (TmfTraceElement traceElement : tracesFolder.getTraces()) {
        traceElement.getResource().setPersistentProperty(ORIGINAL, Boolean.TRUE.toString());
    }
    tracesFolderItem.contextMenu(FETCH_COMMAND_NAME).click();
    shell = fBot.shell(FETCH_SHELL_NAME).activate();
    fBot.comboBox().setSelection("TestAllRecursive");
    fBot.button("Next >").click();
    fBot.button("Finish").click();
    fBot.shell(CONFIRMATION_SHELL_NAME).activate();
    fBot.button("Overwrite").click();
    fBot.shell(CONFIRMATION_SHELL_NAME).activate();
    fBot.button("Overwrite All").click();
    fBot.waitUntil(Conditions.shellCloses(shell), FETCH_TIME_OUT);
    WaitUtils.waitForJobs();
    fBot.waitUntil(new TraceCountCondition(project, 3));
    List<TmfTraceElement> traces = tracesFolder.getTraces();
    assertEquals(3, traces.size());
    testTrace(traces.get(0), CONNECTION_NODE1_NAME + "/resources/generated/synthetic-trace", TRACE_TYPE_KERNEL);
    testTrace(traces.get(1), CONNECTION_NODE1_NAME + "/resources/syslog", TRACE_TYPE_SYSLOG);
    testTrace(traces.get(2), CONNECTION_NODE1_NAME + "/resources/unrecognized", null);
    // Verify overwritten traces lost the original property
    for (TmfTraceElement traceElement : traces) {
        assertNull(traceElement.getResource().getPersistentProperty(ORIGINAL));
    }
}
Also used : TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) TmfTraceFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) SWTBotView(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView) TmfProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) Test(org.junit.Test)

Aggregations

TmfTraceFolder (org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder)66 TmfTraceElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement)44 TmfProjectElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement)37 Test (org.junit.Test)21 IFolder (org.eclipse.core.resources.IFolder)20 IProject (org.eclipse.core.resources.IProject)19 IPath (org.eclipse.core.runtime.IPath)19 CoreException (org.eclipse.core.runtime.CoreException)17 Path (org.eclipse.core.runtime.Path)15 IResource (org.eclipse.core.resources.IResource)14 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)13 TmfExperimentFolder (org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentFolder)13 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)12 ArrayList (java.util.ArrayList)11 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)11 SWTBotView (org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView)11 SWTBotShell (org.eclipse.swtbot.swt.finder.widgets.SWTBotShell)11 File (java.io.File)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)10 ISelection (org.eclipse.jface.viewers.ISelection)10