I am working on an Ant build process for an application that uses a versioning in the following format: major.minor.buildcount. So currently the application is around 2.1.52, where we are on version 2.1 and there have been 35 builds.
I am now adding in an ant target to ask the user if they would like to advance the major version and/or the minor version.
When I run my target from the command line I would like to follow the following:
@@ ant version
Versioning application...
Would you like to advance the major version to 3? (Y|n)
@@ n
Not Advancing major version
Would you like to advance the minor version to 2? (y|N)
@@ y
Advancing minor version
The lines prepended with @@ is the user input that I would like to take. My major and minor versions are stored in a build.properties file.
Here is my code so far
<?xml version="1.0"?>
<project name="StudentMS" default="zip" basedir=".">
<propertyfile file="./.ant/build.properties">
<entry key="version.buildnumber" type="int" default="0" operation="+" pattern="00" />
</propertyfile>
<property file="./.ant/build.properties" />
<property name="sourceDir" location="/Users/dave/Workspace/ColdFusion/StudentMs" />
<property name="buildDir" location="${sourceDir}/builds" />
<target name="version" description="Adds a major and minor version to the build.">
<input message="Advance major version? ${version.major}" addproperty="updatemajor" validargs="y,n" defaultvalue="n" />
<propertyfile file="./.ant/build.properties">
<entry key="version.major" type="int" default="0" operation="+" pattern="00" />
</propertyfile>
<input message="Advance minor version? ${version.minor}" addproperty="updateminor" validargs="y,n" defaultvalue="y" />
<propertyfile file="./.ant/build.properties">
<entry key="version.minor" type="int" default="0" operation="+" pattern="00" />
</propertyfile>
</target>
</project>
And my build.properties
#Tue, 29 Mar 2011 11:46:30 -0400
version.buildnumber=35
version.major=2
version.minor=1
I am still very new to Ant so I am sorry that I can’t post more advanced code. So the first thing I need to do is add some kind of conditional around my property file edits.
what you want can be achieved by combining the condition and antcall task and by adding a couple of extra targets.
I think something like this should work:
Basically, what it does is set the executeMajor and executeMinor properties just in the case that the updatemajor/updateminor are set to “y”. Then, ant will run the update targets just if the executeMajor/Minor variables are set, and it will skip them otherwise.