check all files in fileset contain a string in ant

半腔热情 提交于 2019-12-13 15:43:04

问题


Can anyone provide an example of an ant build which checks if all files found by a fileset contain some token and do not contain some other token?

(google has not been very useful with this, so here I am...)


回答1:


I think this can be done using ant's resourcecontains condition, but I'm not sure it accept multiple resources (see the docs for details). However, it can be done using resourcecount contition:

<project name="Test" default="main" basedir=".">

  <patternset id="filestotest">
    <include name="*.c"/>
  </patternset>

  <target name="main">
    <condition property="contain">
      <resourcecount when="greater" count="0">
        <fileset dir=".">
          <patternset refid="filestotest"/>
          <contains text="main" casesensitive="yes"/>
        </fileset>
      </resourcecount>
    </condition>
    <condition property="donotcontain">
      <isfalse value="${contain}"/>
    </condition>
    <echo message="${contain}"/>
    <echo message="${donotcontain}"/>
  </target>
</project>

You can use <resourcecount when="equal" count="0"> to test for the opposite condition for another token.



来源:https://stackoverflow.com/questions/4353095/check-all-files-in-fileset-contain-a-string-in-ant

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