Tip of the Day – Populate Version Number from an AIR Descriptor File in ANT

So I’ve seen this question pop up a few times.

Can I grab a version number from the app-descriptor via ant and add that to the AIR filename? Anyone know?

This is a pretty straight forward thing to do using Ant-Contrib tasks, that are publicly available.

You can download the example files –> here.

Let’s take a quick look at the ANT script.

<project name="PopulateVersion" default="populateVersion" basedir=".">
  <taskdef resource="net/sf/antcontrib/antcontrib.properties">
          <pathelement location="./ant-contrib.jar"/>
  <property name="app.descriptor" value="air-app.xml" />
  <target name="populateVersion">
    <echo message="Parsing application.version from ${app.descriptor}"/>
    <xmlproperty file="${app.descriptor}" prefix="airApp.appdescriptor"/>
    <propertycopy property="versionNumber" 
                  override="true" />
    <echo message="Parsed application version: ${versionNumber}"/>  
    <propertyregex property="fileVersionNumber"
                  casesensitive="false" />
    <echo>Version Number: ${versionNumber}</echo>                    
    <echo>File Version Number: ${fileVersionNumber}</echo>

As you can see it’s very straight forward to parse the version number out of the Application Descriptor. The only other thing we do is us RegEx to change the periods in the version number to underscores to make for more friendly file names.

Using the same concept it is very easy to also populate a Version file that gets compiled into your application which can include build numbers, or other interesting things… but we’ll save that for another day.

Related Posts

Comments Closed