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