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;
}
}
}
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" }));
}
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 }));
}
Aggregations