I had to go a little deeper, David. I wanted to be able to rebuild the same build number and also, have a 5th build element when built by continuous integration. Something that bugs me about Ant properties (I've been writing with NAnt for the past 6 years) is that you can't simply set a new value for a Ant property, but rather have to unset first. Anyway, here's what I ended up with:
<project default="setBuildNumber"> <taskdef resource="net/sf/antcontrib/antlib.xml"/> <taskdef name="unset" classname="ise.antelope.tasks.Unset"/> <target name="setBuildNumber"> <property file="build.number"/> <var name="next.major" value="${major.number}"/> <var name="next.minor" value="${minor.number}"/> <var name="next.hotfix" value="${hotfix.number}"/> <var name="next.revision" value="${revision.number}"/> <var name="next.continuous" value="${continuous.number}"/> <if> <equals arg1="${rebuild}" arg2="true"/> <then/> <else> <if> <equals arg1="${majorIncrement}" arg2="true"/> <then> <!--Increment major, minor to 1, hotfix to 0, revision to 1--> <math result="next.major" operand1="${next.major}" operation="+" operand2="1" datatype="int"/> <var name="next.minor" value="1" /> <var name="next.hotfix" value="0" /> <var name="next.revision" value="1" /> </then> <elseif> <equals arg1="${minorIncrement}" arg2="true"/> <then> <!--Major stays the same, minor increments, hotfix goes to 0, revision to 1--> <math result="next.minor" operand1="${next.minor}" operation="+" operand2="1" datatype="int"/> <var name="next.hotfix" value="0" /> <var name="next.revision" value="1" /> </then> </elseif> <elseif> <equals arg1="${hotfixIncrement}" arg2="true"/> <then> <!--Major stays the same, minor stays the same, hotfix increments, revision goes to 1--> <math result="next.hotfix" operand1="${next.hotfix}" operation="+" operand2="1" datatype="int"/> <var name="next.revision" value="1" /> </then> </elseif> <elseif> <equals arg1="${continuous}" arg2="true"/> <then> <!--For continuous integration don't change anything but 5th build digit--> <if> <equals arg1="${cont.reset}" arg2="true"/> <then> <!--And reset it if they request you to do so--> <var name="next.continuous" value="1"/> </then> <else> <!--Otherwise increment it--> <math result="next.continuous" operand1="${next.continuous}" operation="+" operand2="1" datatype="int"/> </else> </if> </then> </elseif> <else> <!--Update revision number only, they didn't ask for anything special--> <math result="next.revision" operand1="${next.revision}" operation="+" operand2="1" datatype="int"/> </else> </if> </else> </if> <!--Now save the build number properties--> <propertyfile file="build.number"> <entry key="major.number" value="${next.major}"/> <entry key="minor.number" value="${next.minor}"/> <entry key="hotfix.number" value="${next.hotfix}"/> <entry key="revision.number" value="${next.revision}"/> <entry key="continuous.number" value="${next.continuous}"/> </propertyfile> <!--Unset the properties so that we can change their values--> <unset name="major.number"/> <unset name="minor.number"/> <unset name="hotfix.number"/> <unset name="revision.number"/> <unset name="continuous.number"/> <property file="build.number"/> <!--set the full.buildnumber property to be used by the build--> <if> <equals arg1="${continuous}" arg2="true"/> <then> <property name="full.buildnumber" value="${major.number}.${minor.number}.${hotfix.number}.${revision.number}.${continuous.number}"/> </then> <else> <property name="full.buildnumber" value="${major.number}.${minor.number}.${hotfix.number}.${revision.number}"/> </else> </if> <echo>${full.buildnumber}</echo> </target> </project> ________________________________ From: David Weintraub <qazw...@gmail.com> To: Ant Users List <user@ant.apache.org> Sent: Monday, May 4, 2009 12:41:13 PM Subject: Re: Reset BuildNumber Just playing around a bit and simplified the whole thing: <project name="test" default="test" basedir="."> <target name="test"> <!-- Note: This would be your default build task --> <property file="version.properties"/> <propertyfile file="version.properties" comment="Versioning file"> <entry key="major" default="1" type="int" pattern="00"/> <entry key="minor" default="0" type="int" pattern="00"/> <entry key="build.number" value="1" default="0" type="int" operation="+" pattern="0000"/> </propertyfile> <echo message="Now on build number ${major}.${minor}.${build.number}"/> </target> <target name="major" description="Increments Major"> <propertyfile file="version.properties" comment="Versioning file"> <entry key="major" value="1" default="0" type="int" operation="+" pattern="00"/> <entry key="minor" value="0" default="0" type="int" operation="=" pattern="00"/> <entry key="build.number" value="1" default="1" type="int" operation="=" pattern="0000"/> </propertyfile> </target> <target name="minor" description="Increments Minor"> <propertyfile file="version.properties" comment="Versioning file"> <entry key="minor" value="1" default="0" type="int" operation="+" pattern="00"/> <entry key="build.number" value="1" default="1" type="int" operation="=" pattern="0000"/> </propertyfile> </target> </project> -- David Weintraub qazw...@gmail.com --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@ant.apache.org For additional commands, e-mail: user-h...@ant.apache.org