How to add the Subversion revision number to an ActionScript class using Ant

Posted by Dennis on Aug 4, 2008 in AIR, ActionScript, Flex4 comments

This comes in quite handy when you want to keep track of which version of your swf file resides on the server. You can trace it out and use Flashtracer or other tools like Flash Inspector. In short, this is what you have to do:

  • Make sure you have the latest Subversion
  • Create a template ActionScript class with a placeholder for the revision number
  • Call the svnversion command from your build script and assign the value to a variable
  • Copy the template class to a location in your source folder and replace the placeholder with the revision number
  • trace() the value in your application

The ActionScript class template file


package
{
	public class AppVersion
	{
		public static const SVN_VERSION		: String = "%SVNVERSION%";
		public static const BUILD_TIME		: String = "%BUILDTIME%";

		public static function log() : void
		{
			trace( "----------------------------------------------------" );
			trace( "- SVN VERSION:              [" + SVN_VERSION + "]" );
			trace( "- BUILD TIME:               [" + BUILD_TIME + "]" );
			trace( "----------------------------------------------------" );
		}
	}
}

The Ant build script


<target name="setBuildVersion">
<!--
		Get the SVN build version range
		-->
<exec executable="svnversion" outputproperty="version.number" failifexecutionfails="false">
<arg line="." />
</exec>
<!--
		Get the current date & time
		-->
<tstamp>
<format property="build.time" pattern="dd/MM/yyyy hh:mm aa" locale="en,UK"/>
</tstamp>
<!--
		Copy the template file and replace %SVNVERSION% and %BUILDTIME%
		-->
<copy file="MySourceClassFile.as" tofile="MyDestClassFile.as" overwrite="true" />
<replace file="MyDestClassFile.as" token="%SVNVERSION%" value="${version.number}" />
<replace file="MyDestClassFile.as" token="%BUILDTIME%" value="${build.time}" />
</target>

The output


----------------------------------------------------
- SVN VERSION:              [70467:72783M]
- BUILD TIME:               [04/08/2008 09:02 AM]
----------------------------------------------------


Tags: , , ,


4 comments

» Comments RSS Feed
  1. Oom Dennis,

    That is very cool. I’m going to use it on my next project.

    Terimakasih.

  2. [...] Useful guide to all that jazz here. [...]

  3. Cool thing. Thanks

  4. seems like you should be using wcVersion instead of svnversion (unless you just don’t want to install the svn task). e.g.,

    which gives you access to ${revision.max} (and lots of other data) in your build script.

    http://subclipse.tigris.org/svnant/svn.html#wcVersion

Leave a comment