我的情况涉及运行带有可选参数的 ant 构建,这些可选参数总是指定但并不总是定义,就像这样
ant -DBUILD_ENVIRONMENT=test -Dusername_ext= -Dconf.dir_ext= -Dcgi-dir_ext=
如果参数没有在命令行上给定值,它们将通过加载 .properties 文件。我有以下代码将检查属性 isset 是否为空。
<if>
<bool>
<and>
<isset property="username_ext"/>
<not>
<equals arg1="${username_ext}" arg2="" />
</not>
</and>
</bool>
<then>
<property name="username" value="${username_ext}" />
</then>
</if>
<property file="${BUILD_ENVIRONMENT}.properties" />
由于有多个属性,我似乎应该编写一个目标,该目标将对每个属性执行相同的操作,而不是每次都重复该代码。
<antcall target="checkexists">
<property name="propname" value="username"/>
<property name="paramname" value="username_ext"/>
</antcall>
<antcall target="checkexists">
<property name="propname" value="conf.dir"/>
<property name="paramname" value="conf.dir_ext"/>
</antcall>
但是 AFAIK an antcall 不会设置全局属性。那么我如何编写一个目标来接受它需要检查的参数名称已设置且不为空,然后将其复制到其他目标可以使用的参数中?