Cannot add Builders to Project programmatically [message #1734399] |
Tue, 07 June 2016 23:30 |
Marc Schlegel Messages: 69 Registered: July 2009 |
Member |
|
|
Hello everyone
I am having trouble working with projects natures, especially with the included Builders.
Actually, I just want to add this Nature to my Project. It creates the necessary Classpath-Container as well as adding a Builder.
Unfortunately this isnt happening: the nature is added to a .project file within the filesystem (I delete all eclipse-files before importing), but no Builders are added to the project -> opening the project-properties yield no Builders.
According to this documentation, nature are only updated when calling project.setDescription(desc), but still I must be missing something.
private void importBndProject(Project bndProject, Workspace bndWorkspace, IProgressMonitor monitor) throws IOException, CoreException, Exception {
final IWorkspace eclipseWorkspace = ResourcesPlugin.getWorkspace();
final IWorkspaceRoot eclipseWorkspaceRoot = eclipseWorkspace.getRoot();
deleteOldProjectFiles(Paths.get(bndWorkspace.getBaseURI()).resolve(bndProject.getName()));
// create generic project
final IProject project = eclipseWorkspaceRoot.getProject(bndProject.getName());
final IProjectDescription projectDescription = eclipseWorkspace.newProjectDescription(bndProject.getName());
IPath path = URIUtil.toPath(bndProject.getBaseURI()); name
if (Platform.getLocation().isPrefixOf(path)) {
projectDescription.setLocation(null);
} else {
projectDescription.setLocation(path);
}
project.create(projectDescription, monitor);
project.open(monitor);
IProjectNatureDescriptor descriptor = ResourcesPlugin.getWorkspace().getNatureDescriptor(Plugin.BNDTOOLS_NATURE);
System.out.println(descriptor.getLabel()); // -> works, Nature available
IProjectDescription updatingDescription = project.getDescription();
updatingDescription.setNatureIds(new String[] {
JavaCore.NATURE_ID, Plugin.BNDTOOLS_NATURE
});
ICommand javaCommand = updatingDescription.newCommand();
javaCommand.setBuilderName(JavaCore.BUILDER_ID);
ICommand bndCommand = updatingDescription.newCommand();
bndCommand.setBuilderName(BndtoolsConstants.BUILDER_ID);
updatingDescription.setBuildSpec(new ICommand[] {
javaCommand, bndCommand
});
project.setDescription(updatingDescription, null);
project.setDefaultCharset("UTF-8", monitor);
// create JavaProject
IJavaProject javaProject = JavaCore.create(project);
importSourceAndOutputFolders(bndWorkspace, bndProject, project, javaProject, monitor);
// addSystemLibraryContainer(cnfJavaProject, monitor);
// create BndToolsProject
IBndProject bndtoolsProject = new BndProject(javaProject.getProject());
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
}
All this runs within an WorkspaceModifyOperation
As you can see, in this code I am already settings the Builders manually
ICommand javaCommand = updatingDescription.newCommand();
javaCommand.setBuilderName(JavaCore.BUILDER_ID);
ICommand bndCommand = updatingDescription.newCommand();
bndCommand.setBuilderName(BndtoolsConstants.BUILDER_ID);
updatingDescription.setBuildSpec(new ICommand[] {
javaCommand, bndCommand
}); but this has the only affect that the Builders are added to .project, but do not appear in the project-properties, nor is any Build triggered when building the project.
Do I have to fire some notication-event for the workspace in order to pick up those changes to the project? Everywhere I looked, the examples only show what I actually wrote.
[Updated on: Tue, 07 June 2016 23:31] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03738 seconds