How to use ant count count countfilter

I am trying to count the number of occurrences of the line " Does the assembly require assembly: true " in the file. I tried the following code, but it does not pick up the counter

<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 to count "Does this compiler need to compile:", the counter works, and I get the correct value. So there is a certain problem with regex. Can someone help? Thanks, Aarthi

0
source share
1 answer

You do not need an additional task, but Ant 1.7.1+ as a <concat> should be a resource.
Here is a slightly adapted example from ant manual resource number
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 

Ant script example:

 <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> 

:

 [echo] The file 'foobar.txt' has 4 lines. 


EDIT
To get strings that don't match means to deny your regular expression, just use:

 </linecontainsregexp negate="true"> 
+3
source

Source: https://habr.com/ru/post/921653/


All Articles