Search in sources :

Example 66 with IProjectDescription

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

the class PMDNature method deconfigure.

@Override
public void deconfigure() throws CoreException {
    final IProjectDescription description = getProject().getDescription();
    final ICommand[] commands = description.getBuildSpec();
    for (int i = 0; i < commands.length; ++i) {
        if (commands[i].getBuilderName().equals(PMDBuilder.ID)) {
            final 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);
            project.setDescription(description, null);
            return;
        }
    }
}
Also used : ICommand(org.eclipse.core.resources.ICommand) IProjectDescription(org.eclipse.core.resources.IProjectDescription)

Example 67 with IProjectDescription

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

the class PMDNatureTest method removeFromRemovesPMDNatureFromProject.

/**
 * Verifies that {@link PMDNature#removeFrom(IProject)} removes the PMD nature if the project already has it and
 * that it keeps the remaining nature ids in the same order.
 */
@Test
public void removeFromRemovesPMDNatureFromProject() 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(true);
    when(description.getNatureIds()).thenReturn(new String[] { "org.example.a", PMDNature.ID, "org.example.b" });
    PMDNature.removeFrom(project);
    verify(project, times(1)).setDescription(same(description), any(IProgressMonitor.class));
    verify(description, times(1)).setNatureIds(eq(new String[] { "org.example.a", "org.example.b" }));
}
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 68 with IProjectDescription

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

the class PMDNatureTest method addToAddsPMDNatureToProject.

/**
 * Verifies that {@link PMDNature#addTo(IProject)} appends the PMD nature to the list of other nature ids if the
 * project does not yet have it.
 */
@Test
public void addToAddsPMDNatureToProject() 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.addTo(project);
    verify(project, times(1)).setDescription(same(description), any(IProgressMonitor.class));
    verify(description, times(1)).setNatureIds(eq(new String[] { "org.example.a", "org.example.b", PMDNature.ID }));
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

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