[tweetmeme source=”gosub3000”]
Here’s a nifty Ant snippet. This can be used to get the Subversion revision number from your Ant build system. Using this, you can label your build artefacts, providing better visibility on what exactly is contained in each build.
<target name="find_revision" description="Sets property 'revision.number' to the head svn revision"> <property name="revision" value="HEAD"/> <!-- find out revision number of HEAD, need svn.exe installed on local machine --> <exec executable="svn" outputproperty="svnlog.out"> <arg line="log ${homedir}/.. -r ${revision} -q"/> </exec> <echo>${svnlog.out}</echo> <!-- need ant-contrib.jar for this in lib dir of ant install --> <taskdef resource="net/sf/antcontrib/antcontrib.properties"/> <propertyregex property="revision.number" input="${svnlog.out}" select="\1"> <regexp pattern="r([0-9]*)"/> </propertyregex> <echo>Revision found: ${revision.number}</echo> </target>