2016-09-28 102 views
0

我可以使用以下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中做到這一點?

回答

2

您可以爲您檢查文件單一性,使用resourcecount條件與when屬性確實使用了相同的邏輯:上述

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

代碼片段設置jarexists爲true,如果有至少一個jar文件和目標目錄中有一個zip文件(但不一定需要相同的文件類型)...

相關問題