Reputation: 43
I am trying to extract some values from a property file using ant-contrib tasks but I keep on getting the error below. I've tried quite a few different ideas from search results but I'm still no further along.
xml:9: Property '${constituents}' is not defined.
My build file is:
<project name="hello" default="foo">
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<target name="foo">
<property file="props.file"/>
<propertyselector property="constituents" match="\bDIR1/workDir([^.]+)\b" select="\0" casesensitive="false"/>
<foreach list="${constituents}" target="print.name" param="myparam"/>
</target>
<target name="print.name">
<propertycopy property="key" from="${myparam}"/>
<echo message="${key}"/>
</target>
My properties file is:
identifier=ABC
constituents="ABC_Section"
constituents="$constituents DIR1/workDir/sec1/subSec1/File1"
constituents="$constituents DIR1/workDir/sec2/File2"
constituents="$constituents DIR1/workDir/sec3/File3"
constituents="$constituents DIR1/workDir/lib"
constituents="$constituents DIR1/OTHER"
I am essentially trying to extract all test that begins:
DIR1/workDir/......
I'm hoping that someone will be able to give me just a pointer as to where I'm going wrong.
Thanks
Upvotes: 0
Views: 1431
Reputation: 2739
See the manual of propertyselector:
Selects property names that match a given regular expression and returns them in a delimited list
So you are doing it wrong -- it's selecting property names, NOT values. It should be used when you have some properties that share a pattern with the names, see the example in the manual page.
An alternative (or, typical Ant) way to do what you want:
constituents=ABC_Section,\
DIR1/workDir/sec1/subSec1/File1,\
DIR1/workDir/sec2/File2,\
DIR1/workDir/sec3/File3,\
DIR1/workDir/lib,\
DIR1/OTHER
Then
<for list="${constituents}" param="myparam">
<sequential>
<if>
<matches string="@{myparam}" pattern="^DIR1/workDir/.+" casesensitive="false" />
<then>
<!-- deal with your property -->
<echo>@{myparam}</echo>
</then>
</if>
</sequential>
</for>
I didn't test the regex in matches
, you may need to fix it.
Upvotes: 1