Use of the ${template} macro

The bnd instructions (any property that starts with a - sign) are using the same syntax as the OSGi headers for structured information. The syntax is basically:

 header    ::= (clause (',' clause )+)?
 clause    ::= key+( ';' parameter )+

For example:

-runbundles \
    org.apache.felix.scr;version="2.2"; startlevel="10",\
    org.apache.felix.log;version="1.4"; startlevel="5",\
    org.apache.felix.gogo.runtime;version="1.2"; startlevel="50"

Unfortunately, these headers are really hard to use as a parameter to a macro since they use the semicolon (;) as separator, as does the macro. They are even harder to parse using macros.

Last year I needed to do start levels and I really needed to access the startlevel attribute in -runbundles. So I added a template macro. The purpose is to take the _name_ of a property and then provide a _template_ to run over each clause. The ${@}` macro then refers to the key of the clause.

${template;-runbundles*;${@}}

Which gives:

org.apache.felix.scr,org.apache.felix.log,org.apache.felix.gogo.runtime

The parameters of each clause can be accessed by their name prefixed with the commercial at sign (@):

 ${template;-runbundles*;${@startlevel}}

Gives:

10,5,50

Don’t forget that you can test this in the bnd editor by hovering over a selection with macros.

3 Likes