如何检查属性是否存在? [英] How to check if a property exists?

查看:86
本文介绍了如何检查属性是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Ant检查属性的存在?

How do I check the existence of a property using Ant?

如果Ant没有提供类似的东西,我愿意使用ant-contrib.

I am open to the use of ant-contrib, if Ant doesn't provide a similar thing.

此外,ant-contrib有一个断言任务,该任务提供了exists,但是这里的断言不是我所需要的,因为我更喜欢布尔值.

Also, ant-contrib has an assert task, which provides exists, but the assertion is not what I need here since I would prefer a boolean return value.

推荐答案

您可以使用条件已设置的条件任务.

You can use the Condition task with an isset condition.

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

输出:

test:
     [echo] a set ? true
     [echo] b set ? false

这篇关于如何检查属性是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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