且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何测试以查看 ANT 中的目录是否为空?

更新时间:2023-11-29 15:30:16

您可以使用 pathconvert 任务来做到这一点,使用 setonempty 属性.

<pathconvert refid="myfileset"
             property="fileset.notempty"
             setonempty="false"/>

仅当那些 refid 为 myfileset 的文件集不为空时,才会设置属性 fileset.notempty.

will set the property fileset.notempty only if the fileset those refid is myfileset is not empty.

你只需要在你的目录中定义 myfileset,并且没有排除会得到一个目录空测试:

You just have to define myfileset with your directory, and no excludes do get a directory empty test:

<fileset dir="foo/bar" id="myfileset"/>

这个用例示例:

使用 pathconvert 的 setonempty 属性,值为false".这样,如果文件集为空,则不会设置该属性.这个很好,因为目标检查他们的 if 属性是否是一个属性是否设置.

use the setonempty attribute of pathconvert, with the value "false". This way, if the fileset is empty, the property will not be set. this is good since targets check with their if attribut whether a property is set or not.

所以你做这样的事情:

<fileset dir="foo/bar" id="myfileset"/>
<target name="fileset.check">
    <pathconvert refid="myfileset" property="fileset.notempty"
setonempty="false"/>
</target>
<target name="main" depends="fileset.check" if="fileset.nonempty">
    <!-- your main work goes here -->
</target>