I am trying to get a ANT-Buildscript to count the lines that are stored inside a ANT-property. From the examples I got the way to count the lines in a file, like this:
<resourcecount count="0" when="eq">
<tokens>
<concat>
<filterchain>
<tokenfilter>
<linetokenizer/>
</tokenfilter>
</filterchain>
<fileset file="${file}" />
</concat>
</tokens>
</resourcecount>
Now I want to refer to a ANT-property instead of the file. Is there a way to do this? I know about the solution to write the contents of the property into a file using <echo file="${temp.file}">${the.property.with.many.lines}</echo>
and using the code above after. But I wonder if there is a solution that works without a temporary file.
A propertyresource
element may used in place of the fileset
as follows:
<property name="lines"
value="line01${line.separator}line02${line.separator}line03"/>
<target name="count-lines">
<resourcecount property="line.count" count="0" when="eq">
<tokens>
<concat>
<filterchain>
<tokenfilter>
<stringtokenizer delims="${line.separator}" />
</tokenfilter>
</filterchain>
<propertyresource name="lines" />
</concat>
</tokens>
</resourcecount>
<echo message="${line.count}" />
</target>
count-lines: [echo] 3
BUILD SUCCESSFUL Total time: 0 seconds
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With