01.20.09

Ant Task To Fetch The Latest Subversion Revision Number

Posted in Uncategorized at 9:23 pm by GaZ

In an attempt to publish something useful on this blog, here’s a little Ant macrodef to fetch the last changed revision number from Subversion. It’s quite similar to some other suggestions I found.

<macrodef name="getsvnrevision">
<attribute name="revision" default="HEAD"/>
<attribute name="srcUrl"/>
<attribute name="property"/>
<sequential>
<tempfile property="svninfo.log"/>
<exec executable="svn" output="${svninfo.log}">
<arg line="info @{srcUrl}"/>
</exec>
<loadfile property="@{property}" srcFile="${svninfo.log}">
<filterchain>
<linecontains>
<contains value="Last Changed Rev: "/>
</linecontains>
<deletecharacters chars="Last Changed Rev: "/>
<striplinebreaks/>
</filterchain>
</loadfile>
<delete file="${svninfo.log}" quiet="true" />
</sequential>
</macrodef>

Example usage:

<target name="test">
<getsvnrevision srcUrl="${svn.url}" property="svn.revision" />
<echo>Latest revision is ${svn.revision}</echo>
</target>

Leave a Comment