Reputation: 18228
I am having a difficulty getting the following Apache Ant script to work. The idea is to copy property values from properties with a certain prefix to properties without the prefix.
<project name="scp.result.files">
<taskdef resource="net/sf/antcontrib/antlib.xml" />
<property name="prop.a.sub1" value="a" />
<property name="prop.b.extra2" value="b" />
<property name="prop.c.foo" value="c" />
<property name="prop.d.foo" value="not selected" />
<target name="prep-props">
<!-- Select all interesting properties. -->
<propertyselector property="prop.list"
delimiter=","
match="prop\.(a|b|c)\..+"
casesensitive="false"
override="true" />
<echo message="matched properties: ${prop.list}" />
<!-- For each selected property, set a property without the "prop." prefix. -->
<for param="prop" list="${prop.list}" delimiter="," trim="true">
<propertyregex property="dest.prop"
input="@{prop}"
regex="prop\.((a|b|c)\..+)"
select="\1"
overrride="true" />
<propertycopy name="${dest.prop}"
from="prop.${dest.prop}"
override="true" />
<propertycopy name="_pval" from="${dest.prop}" override="true" />
<echo message="${dest.prop} is ${_pval}" />
</for>
</target>
</project>
Unfortunately, the above script produces the following error for me.
BUILD FAILED
C:\test.xml:19: Invalid type class net.sf.antcontrib.property.RegexTask used in For task, it does not have a public iterator method
at net.sf.antcontrib.logic.ForTask$ReflectIterator.<init>(ForTask.java:450)
at net.sf.antcontrib.logic.ForTask.add(ForTask.java:411)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.IntrospectionHelper$13.create(IntrospectionHelper.java:1552)
at org.apache.tools.ant.IntrospectionHelper$Creator.create(IntrospectionHelper.java:1329)
at org.apache.tools.ant.UnknownElement.handleChild(UnknownElement.java:574)
at org.apache.tools.ant.UnknownElement.handleChildren(UnknownElement.java:358)
at org.apache.tools.ant.UnknownElement.configure(UnknownElement.java:204)
at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:163)
at org.apache.tools.ant.Task.perform(Task.java:347)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.Main.runBuild(Main.java:851)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Is it possible to fix this? Is there any other way of iterating over the selected properties list and getting the un-prefixed properties set?
Upvotes: 1
Views: 1235
Reputation: 72844
The list of tasks to execute for each iteration of for
needs to be placed inside a sequential
element, otherwise the propertyregex
will be considered as a "list" the for
task will iterate on. Also the propertyregex
uses regexp
instead of regex
(checking its documentation).
<for param="prop" list="${prop.list}" delimiter="," trim="true">
<sequential>
<propertyregex property="dest.prop"
input="@{prop}"
regexp="prop\.((a|b|c)\..+)"
select="\1"
overrride="true" />
<propertycopy name="${dest.prop}"
from="prop.${dest.prop}"
override="true" />
<propertycopy name="_pval" from="${dest.prop}" override="true" />
<echo message="${dest.prop} is ${_pval}" />
</sequential>
</for>
Upvotes: 1