需要蚂蚁条件例子 [英] Need Ant condition example

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

问题描述

有人可以解释我用如果蚂蚁财产状况的例子,和,不是和IsTrue运算与code?

Can someone please explain me with Example of Ant condition property with "if", "and", "not" and "istrue" with the code??

我是新来的蚂蚁,需要在这方面的帮助。

I'm new to Ant and need help on this.

基本上我需要使用FTP下载文件。我有code下载。但也有少数情况,我需要在下载前检查。

Basically i need to download file using FTP. I have code to download it. but there are few condition i need to check before downloading.


  1. 下载之前检查Downloadstatusvariable值(通常它的真或假值)

  2. 检查文件是否在路径已下载或可用

  3. 如果这两个条件的失败则执行的是FTP下载code。

先谢谢了。

推荐答案

蚂蚁的contrib被广泛使用的库和的if / else /为/的foreach任务将不仅更容易编写复杂的Ant脚本,它们会让你的Ant脚本更具可读性。

ant-contrib is widely-used library and the if/else/for/foreach tasks will not only make it easier to write complex ant scripts, they'll make your ant scripts much more readable.

不过,既然你坚持:)

我已经在过去处理这个问题的方法是设置任务的,只有当属性x设置执行,并进行任务A取决于检查的条件和一些任务B设置属性x如果他们是真正的。例如:

The way I've handled this in the past is to set up a task A that only executes if property X is set, and make task A depend on some task B that checks the conditions and sets property X if they are true. For example:

<target name="get-ftp-file" depends="check-need-ftp-file" if="ftp.call.required">
  <ftp ... />
</target>

<target name="check-need-ftp-file">
  <condition property="ftp.call.required">
    <and>
      <not>
        <!-- Checks if Downloadstatusvariable variable is true -->
        <istrue value="${Downloadstatusvariable}"/>
      </not>
      <not>
        <!-- Checks if file is present in filesystem -->
        <available file="${my.file}"/>
      </not>
    </and>
  </condition>
</target>

编辑:

coolgokul,在&LT;和&gt; &LT;不&GT; 任务是标准的逻辑运算。在&LT;可用&gt;在这个例子情况,如果该文件在本地计算机上存在的上述计算结果为真。但我们要下载的文件仅当文件不在本地计算机上存在的,所以我们把它包起来的&LT;而非&GT; 任务。为 $ {Downloadstatusvariable} 检查类似 - 我们要确保它是不正确的,所以我们使用&LT; IsTrue运算&GT; ,然后把它包起来&LT;未方式&gt;

coolgokul, the <and> and <not> tasks are standard logical operators. The <available> condition in the example above evaluates to true if the file exists on the local machine. But we want to download the file only if the file does NOT exist on the local machine, so we wrap it up in the <not> task. Similar for the ${Downloadstatusvariable} check--we want to make sure it is not true, so we use <istrue> and then wrap it up in <not>.

最后,我们要确保这​​个变量是不正确的,该文件不存在的,所以我们结束在&LT这两个条件;和&gt; 。翻译成英文,我们要求是Downloadstatusvariable不正确的,不可用下载的文件?

Finally, we want to make sure that that the variable is not true AND the file does not exist, so we wrap up both those conditions in <and>. Translated to English, we're asking "Is Downloadstatusvariable not true, and is the downloaded file not available?"

建议您阅读更多有关条件运算符@ <一个href=\"http://ant.apache.org/manual/Tasks/conditions.html\">http://ant.apache.org/manual/Tasks/conditions.html

Recommend you read more about conditional operators @ http://ant.apache.org/manual/Tasks/conditions.html

希望有所帮助。

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

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