Reputation: 142
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:
I get:
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}
Upvotes: 2
Views: 2944
Reputation: 41
I found that <propertyfile>
task by itself does not load property values, it's just edit specified property file.
To load property values use <property>
task:
<property file="jsfiles.properties" />
So add this line just after </propertyfile>
to load values
Upvotes: 4
Reputation: 2660
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.
Upvotes: 1
Reputation: 31371
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>
Upvotes: 0