【问题标题】:Ant for script how to continue if any iteration fails如果任何迭代失败,Ant for script 如何继续
【发布时间】:2017-04-03 17:10:19
【问题描述】:

我编写了一个 ant 构建文件来检查目录中的所有翻译文件。 如果出现任何文件中的检查错误,我希望 ant for 脚本继续检查其余文件。 我的蚂蚁任务:

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

结果: 它检查文件直到出现第一个错误,然后 BUILD FAILED。

谁能帮我解决这个问题?

【问题讨论】:

    标签: ant


    【解决方案1】:

    for 任务不是标准 ANT 的一部分。这是此处记录的第 3 方扩展:

    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>
    

    更简单、更健壮。

    【讨论】:

    • 感谢您的解决方案。实际上我之前阅读了该页面中的代码,但我无法理解这种重构的方法。你知道如何迭代创建的文件吗?
    • @AhmadAl-Khazraji 我做了一些搜索,这里有一些从开源项目中提取的示例:programcreek.com/java-api-examples/…。就我个人而言,我更喜欢使用 groovy 脚本来扩展 Ant,请参阅:stackoverflow.com/questions/5075017/…
    猜你喜欢
    • 1970-01-01
    • 2015-04-15
    • 1970-01-01
    • 2013-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多