2017-04-03 95 views
0

我正在編寫一個ant構建文件來檢查目錄中的所有翻譯文件。 我希望腳本的ant能夠在任何文件中出現檢查錯誤時繼續檢查其餘文件。 我的Ant任務: Ant腳本如果任何迭代失敗,如何繼續

<taskdef name="validate" classname="ValidateTranslateFile"> 
     <classpath> 
      <pathelement location="${ant-libs-dir}/TranslateFileUtilities.jar" /> 
      <pathelement location="../web/WEB-INF/lib/commons-io-2.5.jar" /> 
      <pathelement location="../web/WEB-INF/lib/commons-lang3-3.5.jar" /> 
     </classpath> 
    </taskdef> 

    <for param="program"> 
     <path> 
      <fileset dir="../web/WEB-INF" includes="*.txt" /> 
     </path> 
     <sequential> 
      <validate targetFile="@{program}" checkLanguages="true" checkKeysOrder="true" /> 
     </sequential> 
    </for> 

</target> 

的結果: 它會檢查,直到第一個錯誤的文件出現,然後構建失敗。

任何人都可以幫助我嗎?

回答

0

for任務不是標準ANT的一部分。它是一個第三方擴展記錄在這裏:

http://ant-contrib.sourceforge.net/tasks/tasks/for.html

文檔建議使用「keepgoing」屬性忽略的錯誤,這可能是你正在尋找的答案。

如果這是您正在編寫的自定義ANT任務,或許您應該考慮refactoring the code to operate on a fileset?這將使您能夠按如下方式調用任務:

<validate checkLanguages="true" checkKeysOrder="true"> 
    <fileset dir="../web/WEB-INF" includes="*.txt" /> 
</validate> 

更簡單,更健壯。

+0

感謝您的解決方案。實際上我之前讀過那個頁面中的代碼,但我無法理解這種重構的方法論。 你知道如何迭代創建的文件嗎? –

+0

@ AhmadAl-Khazraji我在這裏搜索了一些從開源項目中提取的示例:http://www.programcreek.com/java-api-examples/org.apache.tools.ant.types.FileSet。我個人更喜歡使用groovy腳本來擴展Ant,請參閱:http://stackoverflow.com/questions/5075017/ant-process-the-files-in-the-subfolder-using-tasks/5083342#5083342 –