Java Code Examples for org.eclipse.core.resources.IResource#setPersistentProperty()

The following examples show how to use org.eclipse.core.resources.IResource#setPersistentProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TraceAndExperimentTypeTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Test that the experiment opened is of the right class
 */
@Test
public void testExperimentType() {

    IResource resource = fExperiment.getResource();
    try {
        resource.setPersistentProperty(TmfCommonConstants.TRACETYPE, TEST_EXPERIMENT_TYPE);
        fExperiment.refreshTraceType();
    } catch (CoreException e) {
        fail(e.getMessage());
    }

    TmfOpenTraceHelper.openFromElement(fExperiment);
    ProjectModelTestData.delayUntilTraceOpened(fExperiment);

    ITmfTrace trace = fExperiment.getTrace();
    assertTrue(trace instanceof TmfExperimentStub);

    fExperiment.closeEditors();
}
 
Example 2
Source File: TraceAndExperimentTypeTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Test that the analysis get populated under an experiment of the proper type
 */
@Test
public void testExperimentTypeAnalysis() {

    /* Set the trace type of the experiment */
    IResource resource = fExperiment.getResource();
    try {
        resource.setPersistentProperty(TmfCommonConstants.TRACETYPE, TEST_EXPERIMENT_TYPE);
        fExperiment.refreshTraceType();
    } catch (CoreException e) {
        fail(e.getMessage());
    }

    /* Force the refresh of the experiment */
    fExperiment.getParent().refresh();
    assertFalse(fExperiment.getAvailableAnalysis().isEmpty());
}
 
Example 3
Source File: ResourceUtilTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
private void createCopyAndVerifyResource(String name, boolean isFile, boolean isAbsolute) throws CoreException {
    IResource resource = createAndVerifyResource(name, true);
    IPath newPath;
    if (isAbsolute) {
        newPath = resource.getParent().getFullPath().addTrailingSeparator().append(name + COPY_SUFFIX);
    } else {
        newPath = new Path ("..").append(resource.getParent().getName()).append(name + COPY_SUFFIX);
    }
    resource.setPersistentProperty(new QualifiedName(Activator.PLUGIN_ID, PROPERTY_KEY), PROPERTY_VALUE);
    IResource copyResource = ResourceUtil.copyResource(resource, newPath, IResource.FORCE, new NullProgressMonitor());
    assertNotNull(copyResource);
    Map<QualifiedName, String> persistentProperties = copyResource.getPersistentProperties();
    assertEquals(1, persistentProperties.size());
    for (Map.Entry<QualifiedName, String> entry: persistentProperties.entrySet()) {
        assertEquals(PROPERTY_KEY, entry.getKey().getLocalName());
        assertEquals(Activator.PLUGIN_ID, entry.getKey().getQualifier());
        assertEquals(PROPERTY_VALUE, entry.getValue());
    }
    resource.delete(true, null);
    copyResource.delete(true, null);
}
 
Example 4
Source File: TexlipseProperties.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Write a project property. This value will be stored to the project settings file on disk.
 * 
 * @param project the current project
 * @param property the name of the property
 * @param value new value for the property
 */
public static void setProjectProperty(IResource project, String property, String value) {
    try {
        project.setPersistentProperty(new QualifiedName(TexlipseProperties.PACKAGE_NAME, property), value);
    } catch (CoreException e) {
        // do nothing
    }
}
 
Example 5
Source File: ProjectModelTestData.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Gets a project element with traces all initialized
 *
 * @return A project stub element
 * @throws CoreException
 *             If something happened with the project creation
 */
public static TmfProjectElement getFilledProject() throws CoreException {

    IProject project = TmfProjectRegistry.createProject(PROJECT_NAME, null, null);
    final TmfProjectElement projectElement = TmfProjectRegistry.getProject(project, true);
    TmfTraceFolder tracesFolder = projectElement.getTracesFolder();
    if (tracesFolder != null) {
        IFolder traceFolder = tracesFolder.getResource();

        /* Create a trace, if it exist, it will be replaced */
        final IPath pathString = new Path(testTrace.getFullPath());
        IResource linkedTrace = TmfImportHelper.createLink(traceFolder, pathString, pathString.lastSegment());
        if (!(linkedTrace != null && linkedTrace.exists())) {
            return null;
        }
        linkedTrace.setPersistentProperty(TmfCommonConstants.TRACETYPE,
                "org.eclipse.linuxtools.tmf.core.tests.tracetype");

        // Refresh the project model
        tracesFolder.refresh();

        TmfTraceElement traceElement = tracesFolder.getTraces().get(0);
        traceElement.refreshTraceType();
    }
    projectElement.refresh();

    return projectElement;
}
 
Example 6
Source File: TraceAndExperimentTypeTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Test that event editor, event table and statistics viewer are built
 * correctly when specified
 */
@Test
public void testExperimentTypeChildren() {

    /* Set the trace type of the experiment */
    IResource resource = fExperiment.getResource();
    try {
        resource.setPersistentProperty(TmfCommonConstants.TRACETYPE, TEST_EXPERIMENT_TYPE);
        fExperiment.refreshTraceType();
    } catch (CoreException e) {
        fail(e.getMessage());
    }

    TmfOpenTraceHelper.openFromElement(fExperiment);

    ProjectModelTestData.delayThread(500);

    /* Test the editor class */
    final IWorkbench wb = PlatformUI.getWorkbench();
    final IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage();
    IEditorPart editor = activePage.getActiveEditor();

    assertNotNull(editor);
    assertTrue(editor.getClass().equals(TmfEventsEditorStub.class));

    /* Test the event table class */
    TmfEventsEditorStub editorStub = (TmfEventsEditorStub) editor;
    TmfEventsTable table = editorStub.getNewEventsTable();

    assertNotNull(table);
    assertTrue(table.getClass().equals(TmfEventsTable.class));

    fExperiment.closeEditors();
}
 
Example 7
Source File: ResourceUtilTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private void createLinkCopyAndVerify(IPath path, String name, boolean isFile, boolean isSymLink, boolean isShallow, boolean isAbsolute) throws IOException, CoreException {
    IResource originialResource = createAndVerifyLink(path, name, isFile, isSymLink);
    originialResource.setPersistentProperty(new QualifiedName(Activator.PLUGIN_ID, PROPERTY_KEY), PROPERTY_VALUE);
    IPath newPath;
    if (isAbsolute) {
        newPath = originialResource.getParent().getFullPath().addTrailingSeparator().append(name + COPY_SUFFIX);
    } else {
        newPath = new Path ("..").append(originialResource.getParent().getName()).append(name + COPY_SUFFIX);
    }
    int flags = IResource.FORCE;
    flags |= (isShallow ? IResource.SHALLOW : 0);
    IResource copyResource = ResourceUtil.copyResource(originialResource, checkNotNull(newPath), flags, null);
    assertNotNull(copyResource);
    assertTrue(copyResource.exists());
    assertTrue(isFileSystemSymbolicLink(copyResource) == (isSymLink && isShallow));
    assertTrue(copyResource.isLinked() == (!isSymLink && isShallow));
    assertTrue(ResourceUtil.isSymbolicLink(copyResource) == ((isSymLink && isShallow) || (!isSymLink && isShallow)));

    Map<QualifiedName, String> persistentProperties = copyResource.getPersistentProperties();
    assertEquals(1, persistentProperties.size());
    for (Map.Entry<QualifiedName, String> entry: persistentProperties.entrySet()) {
        assertEquals(PROPERTY_KEY, entry.getKey().getLocalName());
        assertEquals(Activator.PLUGIN_ID, entry.getKey().getQualifier());
        assertEquals(PROPERTY_VALUE, entry.getValue());
    }
    originialResource.delete(true, null);
    copyResource.delete(true, null);
}
 
Example 8
Source File: TmfOpenTraceHelper.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 9
Source File: DropAdapterAssistant.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Drop a trace by importing/linking a path in a trace folder
 *
 * @param path the source path
 * @param traceFolder the target trace folder
 * @param operation the drop operation (DND.DROP_COPY | DND.DROP_LINK)
 * @return true if successful
 */
private static boolean drop(Path path,
        TmfTraceFolder traceFolder,
        int operation) {

    String targetName = path.lastSegment();
    for (ITmfProjectModelElement element : traceFolder.getChildren()) {
        if (element.getName().equals(targetName)) {
            targetName = promptRename(element);
            if (targetName == null) {
                return false;
            }
            break;
        }
    }
    if (operation == DND.DROP_COPY) {
        importTrace(traceFolder.getResource(), path, targetName);
    } else {
        createLink(traceFolder.getResource(), path, targetName);
    }
    IResource traceResource = traceFolder.getResource().findMember(targetName);
    if (traceResource != null && traceResource.exists()) {
        try {
            String sourceLocation = URIUtil.toUnencodedString(path.toFile().toURI());
            traceResource.setPersistentProperty(TmfCommonConstants.SOURCE_LOCATION, sourceLocation);
        } catch (CoreException e) {
            TraceUtils.displayErrorMsg(e);
        }
        setTraceType(traceResource);
    }
    return true;
}
 
Example 10
Source File: SelectTraceExecutableHandler.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Shell shell = HandlerUtil.getActiveShell(event);

    // Get the selection before opening the dialog because otherwise the
    // getCurrentSelection() call will always return null
    ISelection selection = HandlerUtil.getCurrentSelection(event);

    SelectTraceExecutableDialog dialog = new SelectTraceExecutableDialog(shell);
    dialog.open();
    if (dialog.getReturnCode() != Window.OK) {
        return null;
    }
    IPath tracedExecutable = dialog.getExecutablePath();

    if (selection instanceof IStructuredSelection) {
        for (Object o : ((IStructuredSelection) selection).toList()) {
            TmfTraceElement traceElement = (TmfTraceElement) o;
            IResource resource = traceElement.getResource();
            try {
                resource.setPersistentProperty(GdbTrace.EXEC_KEY, tracedExecutable.toString());
            } catch (CoreException e) {
                TraceUtils.displayErrorMsg(e);
            }
        }
    }
    return null;
}
 
Example 11
Source File: SelectTracesOperationTest.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Setup before test
 *
 * @throws ParseException
 *             Exception if unable to parse TimeStamps
 * @throws CoreException
 *             Core Exception
 */
@Before
public void setUp() throws ParseException, CoreException {
    IProject project = TmfProjectRegistry.createProject("Experiment Select Trace Test Project", null, null);
    fProjectElement = TmfProjectRegistry.getProject(project, true);

    TmfTraceFolder tmfTracesFolder = fProjectElement.getTracesFolder();
    assertNotNull(tmfTracesFolder);

    IFolder traceFolder = tmfTracesFolder.getResource();

    List<IPath> tracePaths = new ArrayList<>();
    tracePaths.add(new Path(TmfTestTrace.SYSLOG_1.getFullPath()));
    tracePaths.add(new Path(TmfTestTrace.SYSLOG_2.getFullPath()));
    tracePaths.add(new Path(TmfTestTrace.SYSLOG_3.getFullPath()));
    tracePaths.add(new Path(TmfTestTrace.SYSLOG_4.getFullPath()));
    tracePaths.add(new Path(TmfTestTrace.SYSLOG_5.getFullPath()));
    tracePaths.add(new Path(TmfTestTrace.SYSLOG_6.getFullPath()));

    for (IPath tracePath : tracePaths) {
        IResource traceResource = TmfImportHelper.createLink(traceFolder, tracePath, tracePath.lastSegment());
        traceResource.setPersistentProperty(TmfCommonConstants.TRACETYPE, "org.eclipse.linuxtools.tmf.tests.stubs.trace.text.testsyslog");
    }

    for (TmfTraceElement trace : tmfTracesFolder.getTraces()) {
        trace.refreshTraceType();
    }

    fProjectElement.refresh();
    for (int i = 0; i < fTraces.length; i++) {
        fTraces[i] = Objects.requireNonNull(tmfTracesFolder.getTraces().get(i));
    }

    for (int i = 0; i < fExpectedTimeRangeTraces.length; i++) {
        fExpectedTimeRangeTraces[i] = fTraces[i];
    }

    fStartTimeRange = parse("Jan 1 02:00:00");
    fEndTimeRange = parse("Jan 1 05:05:00");

    fExperiment = ProjectModelTestData.addExperiment(fProjectElement, EXPERIMENT_NAME);
}
 
Example 12
Source File: DropAdapterAssistant.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Drop a trace by copying/linking a resource in a trace folder
 *
 * @param sourceResource the source resource
 * @param traceFolder the target trace folder
 * @param operation the drop operation (DND.DROP_COPY | DND.DROP_LINK)
 * @return the target resource or null if unsuccessful
 */
private static IResource drop(IResource sourceResource,
        TmfTraceFolder traceFolder,
        int operation) {

    if (sourceResource.getParent().equals(traceFolder.getResource())) {
        return null;
    }
    String targetName = sourceResource.getName();
    for (ITmfProjectModelElement element : traceFolder.getChildren()) {
        if (element.getName().equals(targetName)) {
            targetName = promptRename(element);
            if (targetName == null) {
                return null;
            }
            break;
        }
    }
    try {
        if (operation == DND.DROP_COPY && !ResourceUtil.isSymbolicLink(sourceResource)) {
            IPath destination = traceFolder.getResource().getFullPath().addTrailingSeparator().append(targetName);
            sourceResource.copy(destination, false, null);
            cleanupBookmarks(destination);
        } else {
            createLink(traceFolder.getResource(), sourceResource, targetName);
        }
        IResource traceResource = traceFolder.getResource().findMember(targetName);
        if (traceResource != null && traceResource.exists()) {
            String sourceLocation = sourceResource.getPersistentProperty(TmfCommonConstants.SOURCE_LOCATION);
            if (sourceLocation == null) {
                sourceLocation = URIUtil.toUnencodedString(new File(ResourceUtil.getLocationURI(sourceResource)).toURI());
            }
            traceResource.setPersistentProperty(TmfCommonConstants.SOURCE_LOCATION, sourceLocation);
            setTraceType(traceResource);
        }
        return traceResource;
    } catch (CoreException e) {
        TraceUtils.displayErrorMsg(e);
    }
    return null;
}
 
Example 13
Source File: TraceValidateAndImportOperation.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Imports a trace resource to project. In case of name collision the user
 * will be asked to confirm overwriting the existing trace, overwriting or
 * skipping the trace to be imported.
 *
 * @param fileSystemElement
 *            trace file system object to import
 * @param monitor
 *            a progress monitor
 * @return the imported resource or null if no resource was imported
 *
 * @throws InvocationTargetException
 *             if problems during import operation
 * @throws InterruptedException
 *             if cancelled
 * @throws CoreException
 *             if problems with workspace
 */
private IResource importResource(TraceFileSystemElement fileSystemElement, IProgressMonitor monitor)
        throws InvocationTargetException, InterruptedException, CoreException {

    IPath tracePath = getInitialDestinationPath(fileSystemElement);
    String newName = fConflictHandler.checkAndHandleNameClash(tracePath, monitor);

    if (newName == null) {
        return null;
    }
    fileSystemElement.setLabel(newName);

    List<TraceFileSystemElement> subList = new ArrayList<>();

    FileSystemElement parentFolder = fileSystemElement.getParent();

    IPath containerPath = fileSystemElement.getDestinationContainerPath();
    tracePath = containerPath.addTrailingSeparator().append(fileSystemElement.getLabel());
    boolean createLinksInWorkspace = (fImportOptionFlags & ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE) != 0;
    if (fileSystemElement.isDirectory() && !createLinksInWorkspace) {
        containerPath = tracePath;

        Object[] array = fileSystemElement.getFiles().getChildren();
        for (int i = 0; i < array.length; i++) {
            subList.add((TraceFileSystemElement) array[i]);
        }
        parentFolder = fileSystemElement;

    } else {
        if (!fileSystemElement.isDirectory()) {
            // File traces
            IFileInfo info = EFS.getStore(new File(fileSystemElement.getFileSystemObject().getAbsolutePath()).toURI()).fetchInfo();
            if (info.getLength() == 0) {
                // Don't import empty traces
                return null;
            }
        }
        subList.add(fileSystemElement);
    }

    ImportProvider fileSystemStructureProvider = new ImportProvider();

    IOverwriteQuery myQueryImpl = file -> IOverwriteQuery.NO_ALL;

    monitor.setTaskName(Messages.ImportTraceWizard_ImportOperationTaskName + " " + fileSystemElement.getFileSystemObject().getAbsolutePath()); //$NON-NLS-1$
    ImportOperation operation = new ImportOperation(containerPath, parentFolder, fileSystemStructureProvider, myQueryImpl, subList);
    operation.setContext(fShell);

    operation.setCreateContainerStructure(false);
    operation.setOverwriteResources(false);
    operation.setCreateLinks(createLinksInWorkspace);
    operation.setVirtualFolders(false);

    operation.run(SubMonitor.convert(monitor).newChild(1));
    String sourceLocation = fileSystemElement.getSourceLocation();
    IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(tracePath);
    if ((sourceLocation != null) && (resource != null)) {
        resource.setPersistentProperty(TmfCommonConstants.SOURCE_LOCATION, sourceLocation);
    }

    return resource;
}