ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Fetzer <elstonk...@yahoo.com>
Subject Re: Reset BuildNumber
Date Thu, 07 May 2009 15:50:34 GMT
So what do you think about this?


<project default="setBuildNumber">
  <taskdef resource="net/sf/antcontrib/antlib.xml"/>
  <taskdef name="unset" classname="ise.antelope.tasks.Unset"/>

    <target name="setBuildNumber" depends="initBuildNum,getBuildNum">
      <!--First 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>
        <or>
          <equals arg1="${increment}" arg2="continuous"/>
          <equals arg1="${increment}" arg2="contReset"/>
        </or>
        <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>

    <target name="initBuildNum" description="Get current build number properties">
      <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}"/>
    </target>

    <target name="getBuildNum">
      <switch value="${increment}">
        <case value="rebuild"/>
        <case value="major">
          <!--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" />
        </case>
        <case value="minor">
          <!--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" />
        </case>
        <case value="hotfix">
          <!--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" />
        </case>
        <case value="continuous">
          <!--For continuous integration don't change anything but 5th build digit-->
          <math result="next.continuous" operand1="${next.continuous}" operation="+"
operand2="1" datatype="int"/>
        </case>
        <case value="contReset">
          <!--Continuous build, but they want the 5th digit reset (i.e. new week)-->
          <var name="next.continuous" value="1"/>
        </case>
        <default>
          <!--Update revision number only, they didn't ask for anything special-->
          <math result="next.revision" operand1="${next.revision}" operation="+"
operand2="1" datatype="int"/>
        </default>
      </switch>
    </target>

</project>

 



________________________________
From: Francis Galiegue <fge@one2team.com>
To: Ant Users List <user@ant.apache.org>
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"/>
        <sequential>
            <math result="next.@{victim}" operand1="${@{victim}.number}"
                operation="+" operand2="1" datatype="int"/>
        </sequential>
    </macrodef>


    <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>

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

    <target name="majorIncrement" if="majorIncrement" unless="done"
        depends="andwhat">
        <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>

    <target name="minorIncrement" if="minorIncrement" unless="done"
        depends="majorIncrement">
        <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>

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

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

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

    <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}"/>
        </propertyfile>
    </target>

</project>
----

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

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


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