I'm trying to edit my pom.xml file with a script. It involves inserting a plugin module after one that I expect to exist.
My reduced pom looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>very</groupId>
<artifactId>secret</artifactId>
<version>2.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Something</name>
<properties>
...
</properties>
<modules>
<module>...</module>
</modules>
<prerequisites>
...
</prerequisites>
<profiles>
<profile>
...
</profile>
</profiles>
<dependencyManagement>
<dependencies>
<dependency>
...
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
...
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
...
</plugin>
<plugin>
<groupId>org.zeroturnaround</groupId>
<artifactId>jrebel-maven-plugin</artifactId>
<executions>
<execution>
<id>Generate JRebel configuration</id>
<phase>process-resources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<relativePath>${relativeRoot}</relativePath>
<rootPath>$${webapp.jrebel.root}</rootPath>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
...
</plugin>
</plugins>
</reporting>
</project>
I want to use a script to add another plugin after the zeroturnaround one. So basically I am looking for this pattern:
<rootPath>$${webapp.jrebel.root}</rootPath>
</configuration>
</plugin>
And would like to insert something after this pattern. So the output should be
<rootPath>$${webapp.jrebel.root}</rootPath>
</configuration>
</plugin>
Something new here
sed doesn't work because the inputs come in line by line. So this
sed '/<rootPath>\$\${webapp.jrebel.root}<\/rootPath>/a Something new here' pom.xml
prints out
<rootPath>$${webapp.jrebel.root}</rootPath>
Something new here
</configuration>
</plugin>
I have tried
sed -i -e '/<rootPath>\$\${webapp.jrebel.root}<\/rootPath>/ {
N; /\n<\/configuration>/ {
N; /\n<\/plugin>/ {
s/<\/plugin>/<\/plugin>hello/
}
}
}' pom.xml
But that does nothing.
How can I pattern match this? I am open to using either sed or awk.