Search in sources :

Example 41 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project eclipse-pmd by acanda.

the class PMDNatureTest method removeFromDoesNotRemovePMDNatureFromProject.

/**
 * Verifies that {@link PMDNature#removeFrom(IProject)} does not change the nature ids if the project does not have
 * the PMD nature.
 */
@Test
public void removeFromDoesNotRemovePMDNatureFromProject() throws CoreException {
    final IProject project = mock(IProject.class);
    final IProjectDescription description = mock(IProjectDescription.class);
    when(project.getDescription()).thenReturn(description);
    when(project.hasNature(PMDNature.ID)).thenReturn(false);
    when(description.getNatureIds()).thenReturn(new String[] { "org.example.a", "org.example.b" });
    PMDNature.removeFrom(project);
    verify(project, never()).setDescription(any(IProjectDescription.class), any(IProgressMonitor.class));
    verify(description, never()).setNatureIds(any(String[].class));
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 42 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project jop by jop-devel.

the class JOPNature method deconfigure.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.core.resources.IProjectNature#deconfigure()
     */
public void deconfigure() throws CoreException {
    IProjectDescription description = getProject().getDescription();
    ICommand[] commands = description.getBuildSpec();
    for (int i = 0; i < commands.length; ++i) {
        if (commands[i].getBuilderName().equals(JOPizer.BUILDER_ID)) {
            ICommand[] newCommands = new ICommand[commands.length - 1];
            System.arraycopy(commands, 0, newCommands, 0, i);
            System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1);
            description.setBuildSpec(newCommands);
            return;
        }
    }
}
Also used : ICommand(org.eclipse.core.resources.ICommand) IProjectDescription(org.eclipse.core.resources.IProjectDescription)

Example 43 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project jop by jop-devel.

the class JOPNature method configure.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.core.resources.IProjectNature#configure()
     */
public void configure() throws CoreException {
    IProjectDescription desc = project.getDescription();
    ICommand[] commands = desc.getBuildSpec();
    for (int i = 0; i < commands.length; ++i) {
        if (commands[i].getBuilderName().equals(JOPizer.BUILDER_ID)) {
            return;
        }
    }
    ICommand[] newCommands = new ICommand[commands.length + 1];
    System.arraycopy(commands, 0, newCommands, 0, commands.length);
    ICommand command = desc.newCommand();
    command.setBuilderName(JOPizer.BUILDER_ID);
    newCommands[newCommands.length - 1] = command;
    desc.setBuildSpec(newCommands);
    project.setDescription(desc, null);
}
Also used : ICommand(org.eclipse.core.resources.ICommand) IProjectDescription(org.eclipse.core.resources.IProjectDescription)

Example 44 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project jop by jop-devel.

the class ToggleJOPNatureAction method toggleNature.

/**
	 * Toggles sample nature on a project
	 * 
	 * @param project
	 *            to have sample nature added or removed
	 */
private void toggleNature(IProject project) {
    try {
        IProjectDescription description = project.getDescription();
        String[] natures = description.getNatureIds();
        for (int i = 0; i < natures.length; ++i) {
            if (JOPNature.NATURE_ID.equals(natures[i])) {
                // Remove the nature
                String[] newNatures = new String[natures.length - 1];
                System.arraycopy(natures, 0, newNatures, 0, i);
                System.arraycopy(natures, i + 1, newNatures, i, natures.length - i - 1);
                description.setNatureIds(newNatures);
                project.setDescription(description, null);
                System.err.println("JOP Nature removed");
                return;
            }
        }
        // Add the nature
        String[] newNatures = new String[natures.length + 1];
        System.arraycopy(natures, 0, newNatures, 0, natures.length);
        newNatures[natures.length] = JOPNature.NATURE_ID;
        description.setNatureIds(newNatures);
        project.setDescription(description, null);
        System.err.println("JOP Nature added");
    } catch (CoreException e) {
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IProjectDescription(org.eclipse.core.resources.IProjectDescription)

Example 45 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project che by eclipse.

the class Resource method unprotectedMove.

/**
     * Calls the move/delete hook to perform the move.  Since this method calls
     * client code, it is run "unprotected", so the workspace lock is not held.
     * Returns true if resources were actually moved, and false otherwise.
     */
private boolean unprotectedMove(final IResource destination, int updateFlags, IProgressMonitor monitor) throws CoreException, ResourceException {
    //        IMoveDeleteHook hook = workspace.getMoveDeleteHook();
    switch(getType()) {
        case IResource.FILE:
            //                if (!hook.moveFile(tree, (IFile) this, (IFile) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2)))
            workspace.standardMoveFile((IFile) this, (IFile) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork));
            break;
        case IResource.FOLDER:
            //                if (!hook.moveFolder(tree, (IFolder) this, (IFolder) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2)))
            workspace.standardMoveFolder((IFolder) this, (IFolder) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork));
            break;
        case IResource.PROJECT:
            IProject project = (IProject) this;
            // if there is no change in name, there is nothing to do so return.
            if (getName().equals(destination.getName()))
                return false;
            IProjectDescription description = project.getDescription();
            description.setName(destination.getName());
            //                if (!hook.moveProject(tree, project, description, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2)))
            workspace.standardMoveProject(project, description, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork));
            break;
        case IResource.ROOT:
            String msg = Messages.resources_moveRoot;
            throw new ResourceException(new ResourceStatus(IResourceStatus.INVALID_VALUE, getFullPath(), msg));
    }
    return true;
}
Also used : IProjectDescription(org.eclipse.core.resources.IProjectDescription) IResourceStatus(org.eclipse.core.resources.IResourceStatus) ResourceException(org.eclipse.core.internal.resources.ResourceException) IProject(org.eclipse.core.resources.IProject)

Aggregations

IProjectDescription (org.eclipse.core.resources.IProjectDescription)68 IProject (org.eclipse.core.resources.IProject)35 CoreException (org.eclipse.core.runtime.CoreException)18 IWorkspace (org.eclipse.core.resources.IWorkspace)16 IPath (org.eclipse.core.runtime.IPath)13 ICommand (org.eclipse.core.resources.ICommand)12 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)11 File (java.io.File)9 IStatus (org.eclipse.core.runtime.IStatus)9 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 Path (org.eclipse.core.runtime.Path)8 Status (org.eclipse.core.runtime.Status)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 URI (java.net.URI)5 IResource (org.eclipse.core.resources.IResource)5 Test (org.junit.Test)5 HashSet (java.util.HashSet)4 InputStream (java.io.InputStream)3 IFile (org.eclipse.core.resources.IFile)3 Resource (org.eclipse.emf.ecore.resource.Resource)3