【问题标题】:Ant fail if filter token not present or token not replaced如果过滤器令牌不存在或令牌未替换,则 Ant 失败
【发布时间】:2012-12-19 16:30:57
【问题描述】:

在 Ant 中,如果在复制文件时没有发生对特定令牌的令牌替换,那么有没有人知道一种简洁的方法来让 build.xml 失败。即,在文件中找不到令牌,因此没有被替换。

这背后的想法是,在某些情况下,替换某些标记可​​能对标记化文件至关重要,因此值得验证这些标记是否存在于文件中 - 默认情况下,如果出现以下情况,Ant 将不执行任何操作令牌不存在。

我查看了 filterfilterset 的文档,但如果搜索的令牌不存在,它们似乎没有失败的属性。

也许这可以通过正则表达式任务来检查令牌是否存在。有没有人们能想到的更简洁的方法?

【问题讨论】:

    标签: ant


    【解决方案1】:

    你绝对可以这样做:

    ant filtering - fail if property not set

    <loadfile property="all-build-properties" srcFile="build.properties"/>
    <condition property="missing-properties">
        <matches pattern="@[^@]*@" string="${all-build-properties}"/>
    </condition>
    <fail message="Some properties not set!" if="missing-properties"/>
    

    Jason Day 的所有权利

    dovetalk 解决方案也很好:

    <fail unless="my.property">
        Computer says no. You forgot to set 'my.property'!
    </fail>
    

    【讨论】:

    • 这很简洁,没有正则表达式:)
    • 这不是我想要的。我真的需要先找到令牌,然后再替换。这两件事都必须是真的。如果其中任何一个不正确,则构建必须失败,这也不能解释。还是谢谢。
    猜你喜欢
    • 2018-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-01
    • 2018-10-27
    • 2015-10-02
    • 1970-01-01
    • 2011-04-10
    相关资源
    最近更新 更多