如何使用蚂蚁计数任务countfilter [英] how to use ant count task countfilter

查看:37
本文介绍了如何使用蚂蚁计数任务countfilter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试计算文件中此构建列表是否需要编译:true"行的出现次数.我试过下面的代码,但它不拿起计数

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

推荐答案

你不需要一些额外的任务,但是 Ant 1.7.1+ as 必须是资源.
这是 ant manual resourcecount
的一个稍微改编的示例给定输入,foobar.txt :

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>

输出:

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

这篇关于如何使用蚂蚁计数任务countfilter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆