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>

「このビルドリストにはコンパイルが必要ですか:」を数えようとすると、カウンターが機能し、正しい値が得られます。したがって、正規表現には間違いなく問題があります。誰か助けてもらえますか?ありがとう、Aarthi

4

1 に答える 1

4

追加のタスクは必要ありませんが、Ant1.7.1+<concat>はリソースである必要があります。これは、入力が与えられたant手動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

antスクリプトの例:

<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 に答える