Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Cannot add Builders to Project programmatically
Cannot add Builders to Project programmatically [message #1734399] Tue, 07 June 2016 23:30 Go to next message
Marc Schlegel is currently offline Marc SchlegelFriend
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

Re: Cannot add Builders to Project programmatically [message #1734743 is a reply to message #1734399] Fri, 10 June 2016 22:56 Go to previous message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 69
Registered: July 2009
Member
The Builders are acutally working.

I was missing the following bunbles in my run-configuration

  • org.eclipse.core.externaltools
  • org.eclipse.ui.externaltools


Then the Builders-section is visible in the projects properties
Previous Topic:Get an IType's type signature?
Next Topic:Local history
Goto Forum:
  


Current Time: Fri Apr 26 02:48:08 GMT 2024

Powered by FUDForum. Page generated in 0.03190 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top