Im trying to count the number of occurences of the line "Does this buildlist need compile: true" in a file. I tried the following code, but it does not pick up the count
<concat>
<fileset file="@{logPathInTestSetup}" />
<filterchain>
<tokenfilter>
<ct:countfilter property="noOfCompiledBuildlists" contains="Does this buildlist need compile:\s*(true)" override="true">
<ct:counteach propertyprefix="count." select="\1" />
</ct:countfilter>
</tokenfilter>
<ct:stopfilter />
</filterchain>
</concat>
When I try counting "Does this buildlist need compile:", the counter works and I get the correct value. So there is definitely a problem with the regex. Can someone please help?
Thanks,
Aarthi
You don't need some extra task, but Ant 1.7.1+ as <concat>
has to be resource.
Here's a slightly adapted example from ant manual resourcecount
given input, foobar.txt :
Does this buildlist need compile: true
whatever
Does this buildlist need compile: false
The quick brown fox
jumps over the lazy dog
Does this buildlist need compile: true
Does this buildlist need compile: false
Does this buildlist need compile: true
foo
blablabla
Does this buildlist need compile: true
example ant script :
<project>
<property name="file" value="foobar.txt"/>
<resourcecount property="file.lines">
<tokens>
<concat>
<filterchain>
<linecontainsregexp>
<regexp pattern="Does this buildlist need compile:\s*(true)"/>
</linecontainsregexp>
</filterchain>
<fileset file="${file}"/>
</concat>
</tokens>
</resourcecount>
<echo>The file '${file}' has ${file.lines} lines.</echo>
</project>
output :
[echo] The file 'foobar.txt' has 4 lines.
EDIT
To get the lines that do not match, means negate your regex, simply use :
</linecontainsregexp negate="true">