I'm trying to create an automated release script that can update several Maven pom files. At present the "release script" is a text file containing instructions and some example sed commands which assume that the old version number will always be unique. (When updating from 1.8-SNAPSHOT
to 1.9-SNAPSHOT
it assumes that every occurrence of 1.8-SNAPSHOT
anywhere in the pom refers to this project and needs to be updated)
I'd like to make this safer by reading the XML properly to identify the specific elements that need updating. Because the resulting changes will be committed to the git repository, I don't want any unnecessary changes to whitespace.
So far I've come up with this XQuery script
declare boundary-space preserve;
declare namespace mvn="http://maven.apache.org/POM/4.0.0";
declare variable $new_version external;
replace value of node //*[mvn:artifactId/text()="geowebcache"][mvn:groupId/text()="org.geowebcache"]/mvn:version with $new_version
Which I run in xqilla:
xqilla -i pom.xml -u -v new_version "TEST" test.xq
This updates the version number as expected, but strips out much of the whitespace; this makes for an ugly and confusing commit.
I'm not wedded to xqilla or XQuery but I want to keep dependencies to a minimum. One small package with few transitive dependencies that's available in Ubuntu 12.04's main repositories is about what I'm looking for.