Macro magic for string manipulation


I want to automatically create a MavenBndRepository Index file with GAV coordinates for a template. I can extract the maven dependencies and replace it in a template.

The extraction of the GAVs looks as follows:

mavendeps: ${sjoin;\n; ${-maven-dependencies}}

with the following result:


I now need to cut of the ;groupId="jakarta.activation";artifactId="jakarta.activation-api";version="1.2.1";scope=compile part. I’m pretty sure this should be doable with some macro magic, but my attempts till now are in vain.

Somehow the foreach macro is the key, but as I need to cascade a split and sublist macro in it, I don’t see how.

Anybody any idea?

Look at ${template}. It was designed for this. You don’t read my tips? :slight_smile: :slight_smile:


Thanks heaps! That did the trick. I had a vague memory, that something like this exists. Now you told me, I know where it came from.

The format of the OSGi headers does rather nastily conflict with the macro’s use of the the semicolon (’;’) to separate its arguments. It used to be much worse since the arguments were expanded before a macro was parsed.

I recently changed to expand them per argument, keeping the macro argument boundaries. So today you could also use the different replacement/substitution macros to extract the first part. That said, the template macro is a lot easier.