Apache Ant is the de-facto standard for build script in Java development. However, its XML-based syntax make it sometime not so intuitive especially its conditional control via condition tag.
IMHO, a build script should be a script instead of XML. Although Ant does it job well, but a script-like syntax for Ant is always the top item on my Ant wish list. Gant is the answer to this.
Gant is a Groovy based build system that used Ant tasks. It means that you can write the conditional control in a more natural way. You may also access to all classes and method of JDK and Groovy API.
Let's have an example. I will demonstrate a Gant target that extract SVN revision number wihout connect to SVN server. This can be accomplish via SVN command of svnversion. If the folders is track by SVN, the output of this command might be something like 1002:1025M. So the Gant script shall do some string manipulation to extract the "1025" as revision number.
Below is the example:
target ( revision: 'Extract SVN revision info'){
exec (executable: 'svnversion', outputproperty: 'svn.revision' );
antProperty = Ant.project.properties; // define a "shortcut"
def versionArr = "${antProperty.'svn.revision'}".split('\\D');
if(versionArr.length > 0){
def svnRevision = versionArr[versionArr.size() -1];
Ant.property (name: 'app.revision', value: svnRevision);
echo (message: 'SVN-Revision: ${app.revision}');
}
}
From this Gant target, it make use of Ant task 'exec' to execute 'svnversion' command. It utilise standard JDK String.split(String regex) method. And the intuitive 'if' control is exactly the same as Java and Groovy.
If you like Groovy, just give Gant a try.
No comments:
Post a Comment