Multiple Include-Package statements in single bnd file?

Hi,

My Gradle plugin is successfully generating an Import-Package instruction for the Jar task, which I am setting via the builder plugin’s bnd task extension. However, I am concerned that someone may accidentally clobber my Import-Package with one of their own, which would be bad…

I have tried creating a “merged instruction” via Import-Package.foo=...., but that didn’t work. Does Bnd support doing anything like this please?

For reference, while I have been able to create a merged instruction for -includeresource, I have also failed to do so for -exportcontents.

Thanks for any advice here,
Cheers,
Chris

Import-Package is not a merged instruction. And I am not sure it would be wise to make it merged. Similarly, Export-Package is also not a merged instruction. Not all instructions are merged.

The ultimate user of your plugin should be able to control the imports.

The ultimate user of your plugin should be able to control the imports.

Well, that’s definitely the plan. However, at the moment a developer with just enough knowledge to be dangerous could do something like:

tasks.named('jar', Jar) {
    bundle {
        bnd '''\
Import-Package: com.foo.bar.*, *
'''
   }
}

and trash my existing Import-Package instruction provider without realising. Or even worse:

tasks.named('jar', Jar) {
    bundle {
        bnd = 'Import-Package: com.foo.bar.*, *
    }
}

It looks like the most realistic way of preventing this would be invoking instructions.disallowChanges() immediately after adding my own contents.

Of course, that would require an extra method like this:

@Internal
public HasConfigurableValue getInstructions() {
    return instructions;
}

Cheers,
Chris