检查Ant中是否存在“至少一个文件”

时间:2016-09-28 12:39:33

标签: ant

我可以使用以下Ant语法来检查是否存在确切的一个文件给定其模式或确切名称(事实上,我不知道任何文件系统允许两个文件具有相同的名称共存)

    <condition property="dependenciesXmlOk">
        <resourcecount count="1">
            <fileset id="fs" dir="ci" includes="dependencies.xml" />
        </resourcecount>
    </condition>

    <fail message="dependencies.xml not found. Please configure CI server to deploy the dependencies.xml file as an artifact to ci/ folder within this project" unless="dependenciesXmlOk" />

但是,我现在想添加一个新条件和相关的错误消息。如果目标目录中不存在*.jar文件,则Ant构建必须中断。复制和粘贴,.zip也是如此(是的,必须有尽可能多的zip和jar文件,但至少有两个扩展名)

我怎么能在Ant中做到这一点?

1 个答案:

答案 0 :(得分:2)

使用具有_context.Warnings.Where(w => w.Active == true).GroupBy(w => w.StartDate.Year) 属性的resourcecount条件,您可以使用与检查文件唯一性相同的逻辑:

when
如果目标目录中至少有一个jar文件和一个zip文件(但不一定是两种文件类型的相同数量),则

上面的代码段将<condition property="jarexists"> <and> <resourcecount when="greater" count="0"> <fileset dir="${target.dir}"> <include name="**/*.jar"/> </fileset> </resourcecount> <resourcecount when="greater" count="0"> <fileset dir="${target.dir}"> <include name="**/*.zip"/> </fileset> </resourcecount> </and> </condition> 设置为true ...

相关问题