如果蚂蚁else条件? [英] Ant if else condition?

查看:124
本文介绍了如果蚂蚁else条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个if / else条件,我可以用一个Ant任务?

Is there an if/else condition that I can use for an Ant task?

这是我至今写:

<target name="prepare-copy" description="copy file based on condition">
        <echo>Get file based on condition</echo>
    <copy file="${some.dir}/true" todir="."  if="true"/>
</target>

脚本,如果条件为真,将上面复制的文件。如果条件为假,我要复制另一个文件?这有可能在蚂蚁?

The script above will copy the file if a condition is true. What if the condition is false and I wish to copy another file? Is that possible in Ant?

我可以一个参数传递给上述任务,确保公司顺利通过参数是

I could pass a param to the above task and make sure the param that's passed is

推荐答案

如果属性不存在对&LT;复制&GT; 。它应该被应用到&lt;目标方式&gt;

The if attribute does not exist for <copy>. It should be applied to the <target>.

下面是如何使用的为例取决于目标的属性和的 如果除非属性来控制的依赖的目标执行。只有两个中的一个应该执行。

Below is an example of how you can use the depends attribute of a target and the if and unless attributes to control execution of dependent targets. Only one of the two should execute.

<target name="prepare-copy" description="copy file based on condition"
    depends="prepare-copy-true, prepare-copy-false">
</target>

<target name="prepare-copy-true" description="copy file based on condition"
    if="copy-condition">
    <echo>Get file based on condition being true</echo>
    <copy file="${some.dir}/true" todir="." />
</target>

<target name="prepare-copy-false" description="copy file based on false condition" 
    unless="copy-condition">
    <echo>Get file based on condition being false</echo>
    <copy file="${some.dir}/false" todir="." />
</target>

如果您正在使用ANT 1.8+,那么你可以使用属性扩展,它会评估属性的值来确定布尔值。所以,你可以使用如果=$ {复制条件}而不是如果=复制条件

If you are using ANT 1.8+, then you can use property expansion and it will evaluate the value of the property to determine the boolean value. So, you could use if="${copy-condition}" instead of if="copy-condition".

和蚂蚁1.7.1早些时候,指定属性的名称。如果定义了属性,并具有任何价值(甚至一个空字符串),那么它的值为true。

In ANT 1.7.1 and earlier, you specify the name of the property. If the property is defined and has any value (even an empty string), then it will evaluate to true.

这篇关于如果蚂蚁else条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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