PDA

View Full Version : SVN/Build info in your Ant tasks



gslender
2 Oct 2008, 4:29 AM
This is a nice feature to add to any Ant build.xml process and ensures your jar files have an embedded version number that might help with support issues etc.

I first download SvnAnt 1.2.0-RC1 http://subclipse.tigris.org/svnant.html - all this was tested working against Ant 1.7 in Eclipse 3.4

1 <<< Add this to the top of the build.xml (and make sure the 4 svn*.jar files are in the ant build / eclipse path**)


<property name="encoding" value="UTF-8" />
<typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classpath="svnant.jar" />

2 <<< This init task gets the svn build version properties and build date >>>

<tstamp>
<format property="DATE_DE" pattern="dd.MM.yyyy" />
</tstamp>
<svn>
<wcVersion path="user" processUnversioned="true"/>
</svn>

3 <<< This java compile task replaces a line in the Version or GXT source >>>

<replaceregexp file="user/com/company/client/Version.java" encoding="${encoding}" match="BUILD = [0-9]+L;" replace="BUILD = ${revision.max}L;"/>
<replaceregexp file="user/com/company/client/Version.java" encoding="${encoding}" match="DATE = [^a]*;" replace='DATE = "${DATE_DE}";'/>
4 <<< This is the Version.java file that is used to query and/or could be in GXT >>>


package com.company.client;

public final class Version { public static final long BUILD = 72L; //automatically set during Ant compilation!
public static final String DATE = "22.09.2008"; //automatically set during Ant compilation!
static public String getVer() {
return "(Date: "+DATE+", build "+BUILD+")"; // or do whatever
}
}

** note : easiest way to get into eclipse path is via a build.launch for the Ant build.xml - you can specify user libraries to add.