如何使用Ant检查属性是否存在?
我愿意使用ant-contrib,如果Ant没有提供类似的东西.
另外,ant-contrib有一个断言任务,它提供exists,但断言不是我需要的,因为我更喜欢布尔返回值.
sud*_*ode 53
<project default="test">
<property name="a" value="a"/>
<target name="test">
<condition property="a.set" else="false">
<isset property="a"/>
</condition>
<condition property="b.set" else="false">
<isset property="b"/>
</condition>
<echo message="a set ? ${a.set}"/>
<echo message="b set ? ${b.set}"/>
</target>
</project>
Run Code Online (Sandbox Code Playgroud)
输出:
test:
[echo] a set ? true
[echo] b set ? false
Run Code Online (Sandbox Code Playgroud)
Dan*_*iel 11
从Ant 1.9.1开始,可以使用"if"和"unless"属性.如果将2个名称空间xmlns:if ="ant:if"和xmlns:unless ="ant:unless"添加到项目中,则可以使用这些新属性.
<!DOCTYPE project>
<project xmlns:if="ant:if" xmlns:unless="ant:unless">
<property unless:set="property" name="property.is.set" value="false"/>
<property if:set="property" name="property.is.set" value="true"/>
<echo>${property.is.set}</echo>
</project>
Run Code Online (Sandbox Code Playgroud)
另见https://ant.apache.org/manual/ifunless.html
| 归档时间: |
|
| 查看次数: |
67843 次 |
| 最近记录: |