use of org.eclipse.core.resources.IProjectDescription in project knime-core by knime.
the class NewProjectWizard method doFinish.
/**
* Worker method, creates the project using the given options.
*
* @param workflowPath path of the workflow to create in workspace
* @param monitor Progress monitor
* @throws CoreException if error while creating the project
*/
public static void doFinish(final IPath workflowPath, final IProgressMonitor monitor) throws CoreException {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource resource = root.findMember(workflowPath);
if (resource != null) {
throwCoreException("Resource \"" + workflowPath.toString() + "\" does already exist.", null);
}
// check if there is a folder with the same name on the file system
// see bug (http://bimbug.inf.uni-konstanz.de/show_bug.cgi?id=1912)
IPath rootLocation = root.getLocation();
if (rootLocation != null) {
IPath absolutePath = rootLocation.append(workflowPath);
if (absolutePath.toFile().exists()) {
throwCoreException("Resource " + workflowPath + " already exists!", null);
}
}
ContainerGenerator generator = new ContainerGenerator(workflowPath);
IContainer containerResult = generator.generateContainer(monitor);
if (containerResult instanceof IProject) {
IProject project = (IProject) containerResult;
// open the project
project.open(monitor);
// Create project description, set the nature IDs and build-commands
try {
// set the nature id of the project is enough
// the name is already set by IProject#create()
IProjectDescription description = project.getDescription();
description.setNatureIds(new String[] { KNIMEProjectNature.ID });
project.setDescription(description, monitor);
} catch (CoreException ce) {
throwCoreException("Error while creating project description for " + project.getName(), ce);
}
}
//
// 2. Create the optional files, if wanted
//
final IFile defaultFile = containerResult.getFile(new Path(WorkflowPersistor.WORKFLOW_FILE));
InputStream is = new ByteArrayInputStream(new byte[0]);
defaultFile.create(is, true, monitor);
// open the default file, if it was created
// open the model file in the editor
monitor.setTaskName("Opening file for editing...");
Display.getDefault().asyncExec(new Runnable() {
public void run() {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
try {
IDE.openEditor(page, defaultFile, true);
} catch (PartInitException e) {
// ignore it
}
}
});
}
use of org.eclipse.core.resources.IProjectDescription in project eclipse-pmd by acanda.
the class PMDNature method removeFrom.
/**
* Removes the PMD nature from a project.
*/
public static void removeFrom(final IProject project) throws CoreException {
if (project.hasNature(ID)) {
final IProjectDescription description = project.getDescription();
final ArrayList<String> natureIds = Lists.newArrayList(description.getNatureIds());
natureIds.remove(ID);
description.setNatureIds(natureIds.toArray(new String[natureIds.size()]));
project.setDescription(description, null);
MarkerUtil.removeAllMarkers(project);
}
}
use of org.eclipse.core.resources.IProjectDescription in project eclipse-pmd by acanda.
the class PMDNature method configure.
@Override
public void configure() throws CoreException {
final IProjectDescription desc = project.getDescription();
final ICommand[] commands = desc.getBuildSpec();
for (int i = 0; i < commands.length; ++i) {
if (commands[i].getBuilderName().equals(PMDBuilder.ID)) {
return;
}
}
final ICommand[] newCommands = new ICommand[commands.length + 1];
System.arraycopy(commands, 0, newCommands, 0, commands.length);
final ICommand command = desc.newCommand();
command.setBuilderName(PMDBuilder.ID);
newCommands[newCommands.length - 1] = command;
desc.setBuildSpec(newCommands);
project.setDescription(desc, null);
}
use of org.eclipse.core.resources.IProjectDescription in project eclipse-pmd by acanda.
the class PMDNature method addTo.
/**
* Adds the PMD nature to a project.
*/
public static void addTo(final IProject project) throws CoreException {
if (!project.hasNature(ID)) {
final IProjectDescription description = project.getDescription();
final ArrayList<String> natureIds = Lists.newArrayList(description.getNatureIds());
natureIds.add(ID);
description.setNatureIds(natureIds.toArray(new String[natureIds.size()]));
project.setDescription(description, null);
MarkerUtil.removeAllMarkers(project);
}
}
use of org.eclipse.core.resources.IProjectDescription in project eclipse-pmd by acanda.
the class PMDNatureTest method addToDoesNotAddPMDNatureToProject.
/**
* Verifies that {@link PMDNature#addTo(IProject)} does not change the nature ids if the project already has it.
*/
@Test
public void addToDoesNotAddPMDNatureToProject() 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.addTo(project);
verify(project, never()).setDescription(any(IProjectDescription.class), any(IProgressMonitor.class));
verify(description, never()).setNatureIds(any(String[].class));
}
Aggregations