0

我试图计算文件中“此构建列表是否需要编译:true ”行的出现次数。我尝试了以下代码,但它没有计算

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

当我尝试计算“此构建列表是否需要编译:”时,计数器工作并且我得到正确的值。因此,正则表达式肯定存在问题。有人可以帮忙吗?谢谢, 阿尔西

4

1 回答 1

4

您不需要一些额外的任务,但 Ant 1.7.1+<concat>必须是资源。这是ant manual resourcecount 给定输入 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

蚂蚁脚本示例:

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


编辑
要获得不匹配的行,意味着否定您的正则表达式,只需使用:

</linecontainsregexp negate="true">
于 2012-07-31T18:50:06.987 回答