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 Fri, 01 May 2009 17:46:14 GMT
So to make it work, here's what I had to do.  Seems like an awful lot of work to accomplish
something simple like this.

<project default="main">
  <taskdef resource="net/sf/antcontrib/antlib.xml"/>
  <taskdef name="unset" classname="ise.antelope.tasks.Unset"/>
  <target name="main">
    <if>
      <equals arg1="${major.increment}" arg2="true"/>
      <then>
        <propertyfile file="major.number">
          <entry key="build.number" value="=" type="int" operation="+"/>
        </propertyfile>
        <property file="major.number"/>
        <propertycopy name="major.number" from="build.number"/>
        <unset name="build.number"/>
        <property file="minor.number"/>
        <propertyfile file="minor.number">
          <entry key="build.number" value="0" />
        </propertyfile>
        <unset name="build.number"/>
        <property file="minor.number"/>
      </then>
      <else>
        <property file="major.number"/>
        <propertycopy name="major.number" from="build.number"/>
        <unset name="build.number"/>
        <propertyfile file="minor.number">
          <entry key="build.number" value="=" type="int" operation="+"/>
        </propertyfile>
        <property file="minor.number"/>
      </else>
    </if>
    <propertycopy name="minor.number" from="build.number"/>
    <property name="full.buildnumber" value="${major.number}.${minor.number}"/>
    <echo>${full.buildnumber}</echo>
  </target>
</project>

Anyone have an easier way?





________________________________
From: Eric Fetzer <elstonkers@yahoo.com>
To: Ant Users List <user@ant.apache.org>
Sent: Friday, May 1, 2009 11:00:07 AM
Subject: Re: Reset BuildNumber

OK, yeah, I totally don't understand the <buildnumber/> task.  It seems simple enough,
but doesn't behave how it should.  I started off with major.number set to 1 and minor.number
set to 0.  Here's my simple build file:

<project default="main">
  <taskdef resource="net/sf/antcontrib/antlib.xml"/>
  <taskdef name="unset" classname="ise.antelope.tasks.Unset"/>
  <target name="main">
    <if>
      <equals arg1="${major.increment}" arg2="true"/>
      <then>
        <buildnumber file="major.number"/>
        <propertycopy name="major.number" from="build.number"/>
        <unset name="build.number"/>
        <property file="minor.number"/>
        <replace file="minor.number" token="build.number=${build.number}" value="build.number=0"/>
        <unset name="build.number"/>
        <property file="minor.number"/>
      </then>
      <else>
        <property file="major.number"/>
        <propertycopy name="major.number" from="build.number"/>
        <unset name="build.number"/>
        <buildnumber file="minor.number"/>
      </else>
    </if>
    <propertycopy name="minor.number" from="build.number"/>
    <property name="full.buildnumber" value="${major.number}.${minor.number}"/>
    <echo>${full.buildnumber}</echo>
  </target>
</project>

And here's the results:

C:\TestAnt>ant -f TestBuildNumber.xml
Buildfile: TestBuildNumber.xml
main:
     [echo] 1.0
BUILD SUCCESSFUL
Total time: 0 seconds

***I would have expected it to increment minor to get 1.1***

C:\TestAnt>ant -f TestBuildNumber.xml
Buildfile: TestBuildNumber.xml
main:
     [echo] 1.1
BUILD SUCCESSFUL
Total time: 0 seconds

***That's what I would have expected***

C:\TestAnt>ant -f TestBuildNumber.xml
Buildfile: TestBuildNumber.xml
main:
     [echo] 1.2
BUILD SUCCESSFUL
Total time: 0 seconds

***That's what I would have expected***

C:\TestAnt>ant -f TestBuildNumber.xml -Dmajor.increment=true
Buildfile: TestBuildNumber.xml
main:
     [echo] 1.0
BUILD SUCCESSFUL
Total time: 0 seconds

***I would have expected 2.0***

C:\TestAnt>ant -f TestBuildNumber.xml -Dmajor.increment=true
Buildfile: TestBuildNumber.xml
main:
     [echo] 2.0
BUILD SUCCESSFUL
Total time: 0 seconds

***That's what I would have expected***

C:\TestAnt>ant -f TestBuildNumber.xml -Dmajor.increment=true
Buildfile: TestBuildNumber.xml
main:
     [echo] 3.0
BUILD SUCCESSFUL
Total time: 0 seconds

***That's what I would have expected***

C:\TestAnt>ant -f TestBuildNumber.xml
Buildfile: TestBuildNumber.xml
main:
     [echo] 4.0
BUILD SUCCESSFUL
Total time: 0 seconds

***I would have expected it to go to 3.1***

C:\TestAnt>ant -f TestBuildNumber.xml
Buildfile: TestBuildNumber.xml
main:
     [echo] 4.1
BUILD SUCCESSFUL
Total time: 0 seconds

***That's what I would have expected***

Can someone explain why it seems to skip the first run of <buildnumber/> and then work
every time afterward?




________________________________
From: Eric Fetzer <elstonkers@yahoo.com>
To: Ant Users List <user@ant.apache.org>
Sent: Friday, May 1, 2009 10:24:18 AM
Subject: Re: Reset BuildNumber

Yeah, the macrodef was overkill, huh.  How about:

  <target name="main">
    <if>
      <equals arg1="${major.increment}" arg2="true"/>
      <then>
        <buildnumber file="major.number"/>
        <propertycopy name="major.number" from="build.number"/>
        <property file="minor.number"/>
        <replace file="${minor.number}" token="build.number=${build.number}" value="build.number=0"/>
        <property file="minor.number"/>
      </then>
      <else>
        <property file="major.number"/>
        <propertycopy name="major.number" from="build.number"/>
        <buildnumber file="minor.number"/>
      </else>
    </if>
    <property name="full.buildnumber" value="${major.number}.${minor.number}"/>
  </target>



________________________________
From: Eric Fetzer <elstonkers@yahoo.com>
To: Ant Users List <user@ant.apache.org>
Sent: Friday, May 1, 2009 10:17:24 AM
Subject: Re: Reset BuildNumber

So, here's how I'd do it.  Is there a better way?

  <target name="main">
    <if>
      <equals arg1="${major.increment}" arg2="true"/>
      <then>
        <buildnumber file="major.number"/>
        <propertycopy name="major.number" from="build.number"/>
        <property file="minor.number"/>
        <setPropertyInFile
            var.filename="${minor.number}"
            var.varname="${build.number}"
            var.oldvalue="${build.number}"
            var.newvalue="0"
        />
      </then>
      <else>
        <property file="major.number"/>
        <propertycopy name="major.number" from="build.number"/>
        <buildnumber file="minor.number"/>
      </else>
    </if>
    <property name="full.buildnumber" value="${major.number}.${minor.number}"/>
  </target>

  <macrodef name="setPropertyInFile">
    <attribute name="var.filename"/>
    <attribute name="var.varname"/>
    <attribute name="var.oldvalue"/>
    <attribute name="var.newvalue"/>
    <sequential>
      <replace file="@{var.filename}" token="@{var.varname}=@{var.oldvalue}" value="@{var.varname}=@{var.newvalue}"/>
    </sequential>
  </macrodef>




________________________________
From: Eric Fetzer <elstonkers@yahoo.com>
To: Ant Users <user@ant.apache.org>
Sent: Friday, May 1, 2009 9:31:50 AM
Subject: Reset BuildNumber

What is the prescribed method of setting properties in a property file?  Specifically, I'm
speaking of a file that keeps track of one of the build numbers.  Here's a simple example
with what I'd like to do in it:

  <target name="main">
    <if>
      <equals arg1="${major.increment}" arg2="true"/>
      <then>
        <buildnumber file="major.number"/>
        <propertycopy name="major.number" from="build.number"/>
        <!--This would be great, but is my imagination, how would it really work?-->
        <buildnumber file="minor.number" reset="true"/>
        <propertycopy name="minor.number" from="build.number"/>
      </then>
      <else>
        <property file="major.number"/>
        <propertycopy name="major.number" from="build.number"/>
        <buildnumber file="minor.number"/>
        <propertycopy name="minor.number" from="build.number"/>
      </else>
    </if>
    <property name="full.buildnumber" value="${major.number}.${minor.number}"/>
  </target>

Thanks,
Eric


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