Macro magic for string manipulation

Hi,

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:

com.sun.activation:javax.activation:1.2.0;groupId="com.sun.activation";artifactId="javax.activation";version="1.2.0";scope=compile
com.sun.xml.bind:jaxb-impl:2.3.3;groupId="com.sun.xml.bind";artifactId=jaxb-impl;version="2.3.3";scope=compile
jakarta.activation:jakarta.activation-api:1.2.1;groupId="jakarta.activation";artifactId="jakarta.activation-api";version="1.2.1";scope=compile
jakarta.annotation:jakarta.annotation-api:1.3.5;groupId="jakarta.annotation";artifactId="jakarta.annotation-api";version="1.3.5";scope=compile

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:

${template;-maven-dependencies;${@}}

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.