Skip to content

Instantly share code, notes, and snippets.

@lakemove
Created March 28, 2013 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lakemove/5261149 to your computer and use it in GitHub Desktop.
Save lakemove/5261149 to your computer and use it in GitHub Desktop.
showcase svn automated operations and invoking Java from shell script
#!/bin/bash
WORKDIR=/tmp/svn-work-dir
mkdir $WORKDIR && cd $WORKDIR
svn info svn+ssh://subversion.evenex.com/svn/comp/OutgoingDocumentReceiveService/branches/FDD-4256 >/dev/null
if [ $? -eq 0 ]; then
echo "branch already exist, delete it [y/n](y)?"
svn rm svn+ssh://subversion.evenex.com/svn/comp/OutgoingDocumentReceiveService/branches/FDD-4256 -m "delete to create"
fi
svn cp svn+ssh://subversion.evenex.com/svn/comp/OutgoingDocumentReceiveService/trunk svn+ssh://subversion.evenex.com/svn/comp/OutgoingDocumentReceiveService/branches/FDD-4256 -m 'create branch FDD-4256'
svn co svn+ssh://subversion.evenex.com/svn/comp/OutgoingDocumentReceiveService/branches/FDD-4256 document-receive
cd document-receive
svn rm integrationtest mock pom.xml
svn mv service/* .
svn rm service
POMXML="$PWD/pom.xml";
echo "start to edit pom.xml $POMXML"
jrunscript -f <(
cat << END
function XmlParser() {
this.doc = null;
this.current = null;
this.xpath = null;
return this;
}
XmlParser.prototype.parse = function(file) {
var dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(false);
var builder = dbf.newDocumentBuilder();
var input = new java.io.File(file);
this.doc = builder.parse(input);
this.xpath = javax.xml.xpath.XPathFactory.newInstance().newXPath();
return this;
}
XmlParser.prototype.save = function(file) {
var output = new java.io.File(file);
var t = javax.xml.transform.TransformerFactory.newInstance().newTransformer(),
source = new javax.xml.transform.dom.DOMSource(this.doc),
target = new javax.xml.transform.stream.StreamResult(output);
t.transform(source, target);
}
XmlParser.prototype.to = function(expr) {
println('evaluating' + expr);
this.current = this.xpath.compile(expr).evaluate(this.doc, javax.xml.xpath.XPathConstants.NODE);
return this;
}
XmlParser.prototype.text = function(text) {
this.current.setTextContent(text);
return this;
}
XmlParser.prototype.attr = function(name, value) {
this.current.setAttribute(name, value);
return this;
}
XmlParser.prototype.remove = function() {
if( ! this.current ) return; //nothing selected
var parent = this.current.getParentNode();
parent.removeChild(this.current);
this.current = parent;
return this;
}
var xp = new XmlParser();
xp.parse('pom.xml');
xp.to('//parent/groupId').text('com.mach.common');
xp.to('//parent/artifactId').text('parent-pom');
xp.to('//parent/version').text('1.34.0');
xp.to('/project/packaging').remove();
xp.to("/project/build/plugins/plugin[contains(artifactId/text() , 'jboss-packaging-maven-plugin')]").remove();
xp.to('/project/build[count(plugins/plugin) = 0]').remove();
xp.save('pom.xml');
END
)
echo 'commiting all changes'
svn commit -m 'change svn layout structure'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment