我在一个从外部源作为输入读取的Ant构建文件中使用FileSet。如何检查FileSet中是否存在特定文件?
例如,如果正在读取的FileSet是**/src/*.java,我应该能够在其中找到MyClass.java。但是,如果FileSet是**/src/AClass.java, **/src/BClass.java,那么MyClass.java就不在其中。
即使有一种方法可以展开FileSet并执行字符串包含检查,那么这也是可行的。
在FileSet中创建选择器有很多种方法,但是没有什么可以告诉我如何在给定的FileSet中找到/选择一个文件。所以我不能用一个我可以尝试的例子来支持它。任何帮助都将不胜感激。
发布于 2015-12-15 17:20:35
我实现了这一点,方法是将完整的文件集与包含我正在查找的这个文件集的文件集进行交集,并验证如果计数等于1,则其他条件可以很容易地进行编辑或修改。
<target name="checkSomething">
<condition property="something.present">
<and>
<available file="/src/theFile"/>
<resourcecount when="equal" count="1">
<intersect>
<fileset dir="${src.dir}" includes="*"/>
<fileset dir="${src.dir}" includes="**/src/something.java"/>
</intersect>
</resourcecount>
</and>
</condition>
<echo message="Something present: ${something.present}"/>
</target>发布于 2015-12-03 20:31:18
使用restrict资源集合仅包含命名文件:
<project ... xmlns:rsel="antlib:org.apache.tools.ant.types.resources.selectors">
...
<restrict id="filtered.fileset">
<fileset refid="source.fileset"/>
<rsel:name name="MyClass.java"/>
</restrict>
<condition property="file.found" value="yes">
<resourcecount when="greater" count="0" refid="filtered.fileset" />
</condition>https://stackoverflow.com/questions/34075028
复制相似问题