如何检查是否一个属性在ANT价值 [英] How to check if a property has value in ANT

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

问题描述

我有我使用的共建ANT的XML文件。

I have a ANT XML file which I use for build.

我有3个属性。我想打破建立,如果这些属性不包含任何值。

I have 3 properties. I want to break the build if these properties does not contain any value.

此外,我想打破建立如果值是空的。

Also I want to break the build if the value is empty

我怎样才能做到这一点ANT?

How can I do this in ANT?

我一个使用Ant和不ANT-的contrib

I a using ANT and not ANT-CONTRIB

在此先感谢

KARTHIK

推荐答案

您可以通过使用条件的<&失败GT; 任务:

You can use conditions using the <fail> task:

<fail message="Property &quot;foo&quot; needs to be set to a value">
    <condition>
        <or>
            <equals arg1="${foo}" arg2=""/>
            <not>
                <isset property="foo"/>
            </not>
       </or>
   </condition>

这是等同于说的 如果(未设置$ {富}或$ {富} =) 的是伪code。你必须从内到外读取XML的条件。

This is equivalent to saying if (not set ${foo} or ${foo} = "") is pseudocode. You have to read the XML conditions from the inside out.

您可能已经使用了&LT;除非&GT; &LT条款;失败&GT; 任务,如果你只关心变量是否被设置,并且不是否它有一个实际值。

You could have used the <unless> clause on the <fail> task if you only cared whether or not the variable was set, and not whether it has an actual value.

<fail message="Property &quot;foo&quot; needs to be set"
    unless="foo"/>

不过,这也不会,如果属性设置失败,但是没有价值。

However, this won't fail if the property is set, but has no value.

有一个技巧,可以使这个简单

There's a trick that can make this simpler

 <!-- Won't change the value of `${foo}` if it's already defined -->
 <property name="foo" value=""/>
 <fail message="Property &quot;foo&quot; has no value">
     <condition>
             <equals arg1="${foo}" arg2=""/>
     </condition>
</fail>

请记住,我不能重置属性!如果 $ {富} 已经有一个值,在&LT;性&gt; 任务上面不会做任何事情。这样一来,我可以消除&LT;&使用isset GT; 状态。因为你有三个属性可能是不错的:

Remember that I can't reset a property! If ${foo} already has a value, the <property> task above won't do anything. This way, I can eliminate the <isset> condition. It might be nice since you have three properties:

<property name="foo" value=""/>
<property name="bar" value=""/>
<property name="fubar" value=""/>
<fail message="You broke the build, you dufus">
    <condition>
        <or>
            <equals arg1="${foo}" arg2=""/>
            <equals arg1="${bar}" arg2=""/>
            <equals arg1="${fubar}" arg2=""/>
       </or>
    </condition>
</fail>

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

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