Skip to content

[ant] Loading and Expanding Shared Headers or Properties

bnd edited this page Aug 1, 2012 · 1 revision

It is quite common for many bundles to have a common set of Headers.

For example:

Bundle-Vendor: Example, Inc.

Reproducing these headers repeatedly in each .bnd file increases the chance of error, not to mention this goes against the DRY principle.

Handling this in Ant is trivial due to three nice features offered by Bnd.

bndexpand Ant task

The first feature comes form the <bndexpand /> task.

Assuming we have a file called shared-headers.bnd, simply including a call to

<bndexpand propertyfile="shared-headers.bnd" />

will result in the inclusion of the contained headers or properties to be added to the current ant execution scope.

Automatic header inclusion

The second feature is offered as a passive side effect of the <bnd /> task execution. The effect is that any ant properties in the current execution scope having keys which are formatted as OSGi bundle headers are automatically added to the resulting manifest. The exact key format check is against this regular expression: [A-Za-z0-9][-a-zA-Z0-9_]+

Automatic value expansion

There are two points at which the values of properties can be expanded.

Expansion of values during bndexpand task

First, during the execution of the <bndexpand /> task any value that is already in the ant context will be expanded. Having a header formatted like so:

Bundle-Vendor: ${vendor}

in the file shared-headers.bnd from earlier will expand the value of ${vendor} with the appropriate value in the execution context.

Expansion of values during bnd task

Secondly the .bnd descriptor syntax offers a whole slew of built in macros as well as providing extension points for the creation of additional ones. See Bnd - Macros for more details on those.

Clone this wiki locally