I'm trying to find a way to do use the below in my Ant build scripts, which means using groovy to modify the variable - this operation works fine when doing in serial, but when I use the parallel features it only ever sees the last value of the variable. This wasn't a problem when using javascript in the <script>
tags and I'm trying to work out why groovy is treating it differently.
<for list="${file.list}" delimiter="${line.separator}" param="single.val" keepgoing="true" parallel="true" threadCount="3">
<sequential>
<test.single.target test.single="@{single.val}"/>
<macrodef name="test.single.target">
<attribute name="test.single" default="false">
<sequential>
<var name="testVar" value="@{test.single}" />
<groovy>
testVar = project.properties."testVar"
println testVar
if (testVar.endsWith(".class")) {
testVar = testVar.substring(0, testVar.lastIndexOf(".class"))
}
testVar = testVar.replaceAll("//","/").replaceAll('/','.')
properties["testVar"] = testVar
</groovy>
<echo>$test.single</echo>
so when executed with
path/to/use/one/a.class
path/to/use/two/b.class
path/to/use/three/c.class
it results in:
path.to.use.three.c
path.to.use.three.c
path.to.use.three.c
Ah-ha!
The issue was in the use of the var
:
<var name="testVar" value="@{test.single}" />
, I've replaced it out with the following:
<local name="test.single"/>
<property name="test.single" value="@{test.single}"/>
And the values are getting get/set correctly, it seems there is an issue with how the var extension is treated in parallel runs.