-
-
Notifications
You must be signed in to change notification settings - Fork 302
[ant] Loading and Expanding Shared Headers or Properties
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.
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.
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_]+
There are two points at which the values of properties can be expanded.
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.
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.