Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File 检查Ant文件集中是否存在文件_File_Collections_Ant_Fileset - Fatal编程技术网

File 检查Ant文件集中是否存在文件

File 检查Ant文件集中是否存在文件,file,collections,ant,fileset,File,Collections,Ant,Fileset,我在一个Ant构建文件中使用文件集,该文件作为外部源的输入读取。如何检查文件集中是否存在特定文件 例如,如果正在读取的文件集是**/src/*.java,我应该能够在其中找到MyClass.java。但是,如果文件集是**/src/AClass.java、**/src/BClass.java,则MyClass.java不在其中 即使有一种方法可以扩展文件集并执行字符串包含检查,也应该可以 有很多方法可以在文件集中创建选择器,但是我找不到任何方法可以告诉我如何在给定的文件集中查找/选择文件。所以我

我在一个Ant构建文件中使用文件集,该文件作为外部源的输入读取。如何检查文件集中是否存在特定文件

例如,如果正在读取的文件集是
**/src/*.java
,我应该能够在其中找到MyClass.java。但是,如果文件集是
**/src/AClass.java、**/src/BClass.java
,则MyClass.java不在其中

即使有一种方法可以扩展文件集并执行字符串包含检查,也应该可以

有很多方法可以在文件集中创建选择器,但是我找不到任何方法可以告诉我如何在给定的文件集中查找/选择文件。所以我不能用一个我可以尝试的例子来支持它。非常感谢您的帮助。

使用资源集合仅包含命名文件:

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

...

我实现了这一点,方法是将完整的文件集与只包含我正在查找的这一个文件的文件集进行交集,并验证计数是否等于1。其他条件可以很容易地进行AND和ed或or-ed

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