ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Fetzer <>
Subject Re: Reset BuildNumber
Date Thu, 07 May 2009 15:08:13 GMT
Why do you use <macrodef> for one line of code?  Basically, you're creating a subset
of <math> with <increment>.  Is that standard among the Ant community?

From: Francis Galiegue <>
To: Ant Users List <>
Sent: Wednesday, May 6, 2009 3:23:37 PM
Subject: Re: Reset BuildNumber

Le Wednesday 06 May 2009 19:17:25 Eric Fetzer, vous avez écrit :
> Get sidetracked?

Yup, but I got the result ;)

Here it is. Feel free to ask questions. This file is based on a build.number 
file which contains the major.number, minor.number, etc properties, and 
rewrites said file with the new values when it is done. Curiously, you don't 
reset hotfix if you update revision... I let it as is. I think you'll see 
where to reset hotfix otherwise.

It may be longer than your solution, but I think it is more legible - and more 
easily extensible.

Have fun!

<project name="test" basedir="." default="updateBuildNumber">
<!-- vim:set ts=4 noexpandtab syn=ant: -->

    <taskdef resource="net/sf/antcontrib/antlib.xml"/>
    <property file="build.number"/>

    <macrodef name="increment">
        <attribute name="victim"/>
            <math result="next.@{victim}" operand1="${@{victim}.number}"
                operation="+" operand2="1" datatype="int"/>

    <target name="init">
        <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}"/>

    <target name="andwhat" if="rebuild" depends="init">
        <property name="done" value="true"/>

    <target name="majorIncrement" if="majorIncrement" unless="done"
        <increment victim="major"/>
        <var name="next.minor" value="1"/>
        <var name="next.hotfix" value="1"/>
        <var name="next.revision" value="1"/>
        <var name="next.continuous" value="1"/>
        <property name="done" value="true"/>

    <target name="minorIncrement" if="minorIncrement" unless="done"
        <increment victim="minor"/>
        <var name="next.hotfix" value="1"/>
        <var name="next.revision" value="1"/>
        <var name="next.continuous" value="1"/>
        <property name="done" value="true"/>

    <target name="hotfixIncrement" if="hotfixIncrement" unless="done"
        <increment victim="hotfix"/>
        <var name="next.revision" value="1"/>
        <var name="next.continuous" value="1"/>
        <property name="done" value="true"/>

    <target name="continuousIncrement" if="continuous" unless="done"
            <equals arg1="${cont.reset}" arg2="true"/>
                <var name="next.continuous" value="1"/>
                <increment victim="continuous"/>
        <property name="done" value="true"/>

    <target name="revisionIncrement" unless="done"
        <increment victim="revision"/>
        <property name="done" value="true"/>

    <target name="updateBuildNumber" depends="revisionIncrement">
        <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}"/>


Francis Galiegue
Ingénieur système
Mob : +33 (0) 683 877 875
Tel : +33 (0) 178 945 552
40 avenue Raymond Poincaré
75116 Paris

To unsubscribe, e-mail:
For additional commands, e-mail:

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message