蚂蚁过滤 - 如果未设置属性则失败 [英] ant filtering - fail if property not set

查看:32
本文介绍了蚂蚁过滤 - 如果未设置属性则失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ant build.xml,它使用 任务来复制各种 xml 文件.它使用过滤来合并来自 build.properties 文件的属性.每个环境(开发、阶段、生产)都有一个不同的 build.properties,用于存储该环境的配置.

I've got a ant build.xml that uses the <copy> task to copy a variety of xml files. It uses filtering to merge in properties from a build.properties file. Each environment (dev, stage, prod) has a different build.properties that stores configuration for that environment.

有时我们会向 Spring XML 或其他需要更新 build.properties 文件的配置文件添加新属性.

Sometimes we add new properties to the Spring XML or other config files that requires updating the build.properties file.

如果 build.properties 中缺少属性,我希望 ant 快速失败.也就是说,如果任何原始 @...@ 标记进入生成的文件,我希望构建终止,以便用户知道他们需要向本地构建添加一个或多个属性.属性.

I want ant to fail fast if there are properties missing from build.properties. That is, if any raw @...@ tokens make it into the generated files, I want the build to die so that the user knows they need to add one or more properties to their local build.properties.

这可以通过内置任务实现吗?我在文档中找不到任何内容.我即将编写一个自定义的 ant 任务,但也许我可以省点力气.

Is this possible with the built in tasks? I couldn't find anything in the docs. I'm about to write a custom ant task, but maybe I can spare myself the effort.

谢谢

推荐答案

你可以在 ant 1.7 中做到,使用 LoadFile 任务和 match 条件的组合.

You can do it in ant 1.7, using a combination of the LoadFile task and the match condition.

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

这篇关于蚂蚁过滤 - 如果未设置属性则失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆