Subversion support in Ant, while present, isn’t that great. It handles the basics, but not much else. One are of improvement that I had needed was in accessing the repository metadata, specifically the revision number that was being used to build, so that the distributable could embed that as part of the filename. Previously, I had been using the build date, but that’s obviously not accurate.
To support cross-platform, I ended up with JavaSVN from Tmate. It didn’t totally do what I needed to do, but at least I could call it as a command line application to recursively display the information about every file in the repository. After that, it’s only a matter of grep‘ing for “Revision:” and finding the highest revision. I also had to write a simple sorting class to extend Ant (which has tail and head but no sort). It works well, in a wasteful sort of way.
Here’s what I did:
<target name="checkRevision">
<property name="source-root" value="."/>
<java classname="org.tmatesoft.svn.cli.SVN"
dir="${source-root}" fork="true" outputproperty="revision.list">
<arg line="info -R ."/>
<classpath>
<pathelement location="${tools}/svnant/javasvn.jar" />
<pathelement location="${tools}/svnant/javasvn-cli.jar" />
</classpath>
<redirector>
<outputfilterchain>
<linecontainsregexp>
<regexp pattern="^Revision:"/>
</linecontainsregexp>
<deletecharacters chars="Revision: "/>
</outputfilterchain>
</redirector>
</java>
<java classname="Sort" inputString="${revision.list}"
outputproperty="coconut.revision">
<classpath>
<pathelement location="${tools}/sort" />
</classpath>
<redirector>
<outputfilterchain>
<tailfilter lines="1"/>
</outputfilterchain>
</redirector>
</java>
<echo message="Latest commited revision: ${coconut.revision}"/>
</target>



