how to use ant count task countfilter

∥☆過路亽.° 提交于 2019-12-20 06:18:17

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/11732509/how-to-use-ant-count-task-countfilter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!