Search code examples
javaeclipseeclipse-plugineclipse-jdteclipse-pde

Programmatically accessing build.properties of a Java project through JDT API


Is there a way to access programmatically the build.properties of a Java project through the JDT API? Something like IJavaProject.getRawClasspath() just for the build.properties?

If I have an IProject/IJavaProject, can I add a line with the JDT API like this (through JDT API calls):

Before:

source.. = src/
output.. = bin/

After:

source.. = src/,\
           xtend-gen/
output.. = bin/

Solution

  • This is a PDE object rather than JDT so you need to use the PDE APIs. There is very little documentation on the PDE APIs.

    The build.properties is described by the org.eclipse.pde.core.build.IBuildModel interface. You get this using:

    IProject project = ... project ...
    
    IPluginModelBase base = PluginRegistry.findModel(project);
    
    IBuildModel buildModel = PluginRegistry.createBuildModel(base);
    

    You can get the entry for 'bin.includes' using

    IBuildEntry entry = buildModel.getBuild().getEntry(IBuildEntry.BIN_INCLUDES);
    

    The addToken method of IBuildEntry seems to be the way to add to the entry.

    To save you need to check the model is an instance of IEditableModel and call the IEditableModel.save method.

    if (buildModel instanceof IEditableModel) {
      ((IEditableModel)buildModel).save();
    }