tags:

views:

187

answers:

2

I have a value in a properties file that I want to increment while the build is running. The goal is to copy a set of files and append a number to the front of each in order to maintain the order in which they were copied into the directory. I am using the <propertyfile> task as follows:

<propertyfile file="jsfiles.properties">
    <entry  key="file.number" type="int" operation="=" value="10" />
    <entry  key="file.number" type="int" default="010" operation="+" value="10" pattern="000" />
</propertyfile>

Then I do the copy:

<copy todir="${js-in.dir}">
    <resources>
        ...
    </resources>
    <chainedmapper>
        <flattenmapper />
        <globmapper from="*.js" to="${file.number}-*.js"/>
    </chainedmapper>
</copy>

This does exactly what I need it to EXCEPT that instead of the following output:

  • 010-file1.js
  • 020-file2.js
  • 030-file3.js
  • ...

I get:

  • ${file.number}-file1.js
  • ${file.number}-file2.js
  • ${file.number}-file3.js
  • ...

What am I doing wrong?

Update: Per one of the answers below, a simpler case:

<propertyfile file="jsfiles.properties">
    <entry  key="file.number" type="int" operation="=" value="10" />
    <entry  key="file.number" type="int" default="0010" operation="+" value="10" pattern="0000" />

</propertyfile>

<target name="concat">
    <echo>${file.number}</echo>
</target>

Prints [echo] ${file.number}

A: 

Can you test by calling the counter build.number in the propertyfile and

<globmapper from="*.js" to="${build.number}-*.js"/> 

UPDATE

Scratch the above answer. If you do an <echo>${file.number}</echo> after updating the <propertyfile> it shows as ${file.number} and not the value. That is the issue to be fixed.

The difference in your config and mine is a newline after the 2nd and the </propertyfile>. I added one extra blank line after <entry> and the <echo>${file.number}</echo> now displays correctly.

<entry key="file.number" type="int" default="010" value="010" operation="+" pattern="000" /> 

</propertyfile>
JoseK
Are saying try with an entry that is not in my property file? Or do you want me to rename file.number to build.number?
Brian
i tried your exact example, and it weirdly was working only when file.number was renamed to build.number
JoseK
I still get ${build.number}-file1.js etc.
Brian
This unfortunately won't allow formatting. But I tried adding a new line before the </propertyfile> tag and just echoing the variable. I still see ${file.number}. I will include the code in the original question
Brian
A: 

The

<propertyfile file="jsfiles.properties">
  <entry  key="file.number" type="int" operation="=" value="10" />
  <entry  key="file.number" type="int" default="010" operation="+" value="10" pattern="000" />
</propertyfile>

is used for incrementing values in property files. I dont know if this is related to your problem. You should be able to find a jsfiles.properties on disk in your ${basedir}

The reason you get ${file.number}-file1.js is because there are noe variable with that name outside the propertyfile context.

I tried this:

<target name="copy">
  <property name="indexStart" value="10"/>      
  <echo message="About to copy file from ${basedir}" /> 
  <copy todir="tmp" overwrite="true">
    <fileset dir="${basedir}" includes="*.js" />            
    <scriptmapper language="javascript">
      var i = parseInt(project.getProperty('indexStart'));          
      self.addMappedName(i+'_'+source);                 
      project.setProperty('indexStart', i+10);              
    </scriptmapper>         
  </copy>   
</target>

..and it kind of works. For some reason the increments is performed too many times, but at least you should be able to sort the file in the order they were copied.

PålOliver
Yes it is odd that the first few numbers are skipped (the files begin counting at 40, 50, 60,...). But this does seem to work. Thanks!
Brian