Macros as functions

It is hard to think there are bnd users that never used a macro. After all, every property in a bnd file can be used as a macro, including all the instructions. For example, you can use a very foundational instruction as -buildpath as macro.

 ${-buildpath}

However, few users seem to know that you can also create your own macros with parameters. For each macro invocation, there are {0} to {9} available as the arguments.

service = osgi.service;objectClass="${1}";resolution:=active

Provide-Capability: \
   ${service;my.wonderful.Service}, \
   ${service;another.wonderful.Service}  

And don’t forget, you can hover over a selection in the bnd editors and then a tooltip will show you the expansion:

image

5 Likes

Wow, why didn’t I know about this?

Thx @pkriens

RTFM? :sunglasses:

There so many cool things in bnd, we even have an implementation of the Trajan algorithm in there! :slight_smile: