Search in sources :

Example 1 with TmfExperimentFolder

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

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

the class RemoteFetchLogWizardRemotePage method determinePageCompletion.

@Override
protected boolean determinePageCompletion() {
    if (getElementViewer().getCheckedElements().length <= 0) {
        return false;
    }
    validateProject();
    if ((fExperimentName != null) && (fCreateExperimentCheckbox.getSelection())) {
        String name = fExperimentNameText.getText().trim();
        // verify if experiment name is empty
        if (name.isEmpty()) {
            setMessage(null);
            setErrorMessage(RemoteMessages.RemoteFetchLogWizardRemotePage_ErrorEmptyExperimentName);
            return false;
        }
        // verify that name is a valid resource name
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        if ((workspace != null) && (!workspace.validateName(name, IResource.FILE).isOK())) {
            setMessage(null);
            setErrorMessage(NLS.bind(RemoteMessages.RemoteFetchLogWizardRemotePage_ErrorExperimentNameInvalid, name));
            return false;
        }
        TmfExperimentFolder experimentFolder = fExperimentFolderElement;
        if (experimentFolder != null) {
            TmfExperimentElement element = experimentFolder.getExperiment(name);
            // verify if experiment already exists
            if (element != null) {
                setMessage(null);
                setErrorMessage(NLS.bind(RemoteMessages.RemoteFetchLogWizardRemotePage_ErrorExperimentAlreadyExists, name));
                return false;
            }
            // verify if a resource already exists in the experiment folder
            IFolder expResource = experimentFolder.getResource();
            IResource res = expResource.findMember(name);
            if (res != null) {
                setMessage(null);
                setErrorMessage(NLS.bind(RemoteMessages.RemoteFetchLogWizardRemotePage_ErrorResourceAlreadyExists, name));
                return false;
            }
        }
    }
    return true;
}
Also used : TmfExperimentFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentFolder) IWorkspace(org.eclipse.core.resources.IWorkspace) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 3 with TmfExperimentFolder

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

the class RemoteFetchLogWizardRemotePage method finish.

/**
 * Finishes the wizard page.
 *
 * @return <code>true</code> if successful else <code>false</code>
 */
public boolean finish() {
    boolean result;
    if (!fIsVisible) {
        result = updateViewer();
        if (!result) {
            return false;
        }
    }
    result = validateProject();
    if (!result) {
        return false;
    }
    Object[] elements = getElementViewer().getCheckedElements();
    final RemoteImportTracesOperation importOperation = new RemoteImportTracesOperation(getContainer().getShell(), fTmfTraceFolder, elements, fOverwriteAll);
    final List<IResource> traceResources = new ArrayList<>();
    try {
        getContainer().run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                importOperation.run(monitor);
                traceResources.addAll(importOperation.getImportedResources());
                monitor.done();
            }
        });
        if ((fExperimentName != null) && fCreateExperimentCheckbox.getSelection() && (!traceResources.isEmpty())) {
            final IFolder[] experimentFolders = new IFolder[1];
            final TmfExperimentFolder root = fExperimentFolderElement;
            final IStatus[] operationStatus = new IStatus[1];
            final String experimentName = fExperimentNameText.getText().trim();
            // just safety guards
            if ((root == null) || (experimentName.isEmpty())) {
                return true;
            }
            getContainer().run(true, true, new IRunnableWithProgress() {

                @Override
                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    operationStatus[0] = null;
                    final NewExperimentOperation operation = new NewExperimentOperation(root, experimentName);
                    operation.run(monitor);
                    monitor.done();
                    operationStatus[0] = operation.getStatus();
                    experimentFolders[0] = operation.getExperimentFolder();
                }
            });
            final IFolder expFolder = experimentFolders[0];
            final TmfTraceFolder parentTraceFolder = fTmfTraceFolder;
            // just safety guards
            if ((expFolder == null) || (parentTraceFolder == null)) {
                return true;
            }
            if ((operationStatus[0] != null) && (operationStatus[0].isOK())) {
                getContainer().run(true, true, new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        operationStatus[0] = null;
                        final SelectTracesOperation operation = new SelectTracesOperation(root, expFolder, parentTraceFolder, traceResources);
                        operation.run(monitor);
                        monitor.done();
                        operationStatus[0] = operation.getStatus();
                    }
                });
            }
        }
    } catch (InvocationTargetException e) {
        handleError(Messages.TracePackageExtractManifestOperation_ErrorReadingManifest, e);
        return false;
    } catch (InterruptedException e) {
        // Cancelled
        return false;
    }
    IStatus status = importOperation.getStatus();
    if (status.getSeverity() == IStatus.ERROR) {
        handleErrorStatus(status);
        return false;
    }
    disconnectAllRemoteHosts();
    return true;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) TmfExperimentFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentFolder) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) NewExperimentOperation(org.eclipse.tracecompass.internal.tmf.ui.project.operations.NewExperimentOperation) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) RemoteImportTracesOperation(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportTracesOperation) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TmfTraceFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder) SelectTracesOperation(org.eclipse.tracecompass.internal.tmf.ui.project.operations.SelectTracesOperation) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 4 with TmfExperimentFolder

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

the class SWTBotUtils method createExperiment.

/**
 * Creates an experiment
 *
 * @param bot
 *            a given workbench bot
 * @param projectName
 *            the name of the project, creates the project if needed
 * @param expName
 *            the experiment name
 */
public static void createExperiment(SWTWorkbenchBot bot, String projectName, @NonNull final String expName) {
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, true);
    TmfExperimentFolder expFolder = tmfProject.getExperimentsFolder();
    assertNotNull(expFolder);
    NewExperimentOperation operation = new NewExperimentOperation(expFolder, expName);
    operation.run(new NullProgressMonitor());
    bot.waitUntil(new DefaultCondition() {

        @Override
        public boolean test() throws Exception {
            TmfExperimentElement experiment = expFolder.getExperiment(expName);
            return experiment != null;
        }

        @Override
        public String getFailureMessage() {
            return "Experiment (" + expName + ") couldn't be created";
        }
    });
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TmfExperimentFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentFolder) DefaultCondition(org.eclipse.swtbot.swt.finder.waits.DefaultCondition) TmfProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement) IProject(org.eclipse.core.resources.IProject) NewExperimentOperation(org.eclipse.tracecompass.internal.tmf.ui.project.operations.NewExperimentOperation) WaitTimeoutException(org.eclipse.tracecompass.tmf.ui.tests.shared.WaitTimeoutException) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) TimeoutException(org.eclipse.swtbot.swt.finder.widgets.TimeoutException) NotEnabledException(org.eclipse.core.commands.NotEnabledException) ExecutionException(org.eclipse.core.commands.ExecutionException) WorkbenchException(org.eclipse.ui.WorkbenchException) WidgetNotFoundException(org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException) NotHandledException(org.eclipse.core.commands.NotHandledException) ParseException(org.eclipse.jface.bindings.keys.ParseException)

Example 5 with TmfExperimentFolder

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

the class SWTBotUtils method clearExperimentFolder.

/**
 * Clear the experiment folder
 *
 * @param bot
 *            a given workbench bot
 * @param projectName
 *            the name of the project (needs to exist)
 */
public static void clearExperimentFolder(SWTWorkbenchBot bot, String projectName) {
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, false);
    TmfExperimentFolder expFolder = tmfProject.getExperimentsFolder();
    if (expFolder == null) {
        return;
    }
    expFolder.getExperiments().forEach(experiment -> {
        IResource resource = experiment.getResource();
        try {
            // Close the experiment if open
            experiment.closeEditors();
            IPath path = resource.getLocation();
            if (path != null) {
                // Delete supplementary files
                experiment.deleteSupplementaryFolder();
            }
            // Finally, delete the experiment
            resource.delete(true, null);
        } catch (CoreException e) {
            fail(e.getMessage());
        }
    });
    bot.waitUntil(new DefaultCondition() {

        private int fExperimentNb = 0;

        @Override
        public boolean test() throws Exception {
            List<TmfExperimentElement> experiments = expFolder.getExperiments();
            fExperimentNb = experiments.size();
            return fExperimentNb == 0;
        }

        @Override
        public String getFailureMessage() {
            return "Experiment Folder not empty (" + fExperimentNb + ")";
        }
    });
}
Also used : TmfExperimentFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentFolder) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) DefaultCondition(org.eclipse.swtbot.swt.finder.waits.DefaultCondition) TmfProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement) List(java.util.List) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource) Point(org.eclipse.swt.graphics.Point) WaitTimeoutException(org.eclipse.tracecompass.tmf.ui.tests.shared.WaitTimeoutException) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) TimeoutException(org.eclipse.swtbot.swt.finder.widgets.TimeoutException) NotEnabledException(org.eclipse.core.commands.NotEnabledException) ExecutionException(org.eclipse.core.commands.ExecutionException) WorkbenchException(org.eclipse.ui.WorkbenchException) WidgetNotFoundException(org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException) NotHandledException(org.eclipse.core.commands.NotHandledException) ParseException(org.eclipse.jface.bindings.keys.ParseException)

Aggregations

TmfExperimentFolder (org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentFolder)24 TmfExperimentElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement)13 TmfTraceFolder (org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder)13 IFolder (org.eclipse.core.resources.IFolder)12 CoreException (org.eclipse.core.runtime.CoreException)12 IResource (org.eclipse.core.resources.IResource)11 TmfProjectElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement)11 IPath (org.eclipse.core.runtime.IPath)9 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)9 TmfTraceElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 IProject (org.eclipse.core.resources.IProject)8 IFile (org.eclipse.core.resources.IFile)6 ArrayList (java.util.ArrayList)5 IStatus (org.eclipse.core.runtime.IStatus)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)5 File (java.io.File)3 ExecutionException (org.eclipse.core.commands.ExecutionException)3