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

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

问题描述

是否有可用于 Ant 任务的 if/else 条件?

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>

如果条件为真,上面的脚本将复制文件.如果条件为假而我想复制另一个文件怎么办?这在 Ant 中可能吗?

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

推荐答案

不存在 if 属性.它应该应用于.

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

下面是一个示例,说明如何使用目标的 depends 属性和

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="${copy-condition}" 而不是 if="copy-condition".

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

在 ANT 1.7.1 及更早版本中,您指定属性的名称.如果该属性已定义并具有任何值(甚至是空字符串),则它将评估为真.

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.

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

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