2017-04-03 93 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 –