如果两个条件都满足执行Ant任务 [英] execute Ant task if TWO conditions are met

查看:202
本文介绍了如果两个条件都满足执行Ant任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以上蚂蚁脚本工具 如果 dir_is_empty ,然后 git的克隆的其他混帐取使用Ant-1.7.1核心语句:

The above ant script implements if dir_is_empty then git-clone else git-fetch using Ant-1.7.1 core statements:

<target name="update" depends="git.clone, git.fetch" />

<target name="check.dir">
  <fileset dir="${dir}" id="fileset"/>
  <pathconvert refid="fileset" property="dir.contains-files" setonempty="false"/>
</target>

<target name="git.clone" depends="check.dir" unless="dir.contains-files">
  <exec executable="git">
    <arg value="clone"/>
    <arg value="${repo}"/>
    <arg value="${dir}"/>
  </exec>
</target>

<target name="git.fetch" depends="check.dir" if="dir.contains-files" >
  <exec executable="git" dir="${dir}">
    <arg value="fetch"/>
  </exec>
</target>

(见我的其他帖子

但是如何实现目标由两个条件启用?

But how to implement a target enabled by two conditions?

如果 dir_does_not_exist dir_is_empty ,然后混帐克隆别人的git取

if dir_does_not_exist or dir_is_empty then git-clone else git-fetch

我目前的尝试:

<target name="git.clone" 
        depends="chk.exist, chk.empty" 
        unless="!dir.exist || dir.noempty" >
  [...]
</target>

<target name="chk.exist">
  <condition property="dir.exist">
    <available file="${dir}/.git" type="dir"/>
  </condition>
</target>

[...]


我想preFER蚂蚁1.7.1核心语句。不过,我对其他的可能性,蚂蚁的contrib ,或的嵌入的脚本 ...随意张贴您的想法......


I would prefer Ant-1.7.1 core statements. But I am open about other possibilities as Ant contrib, or embedded script... Feel free to post your ideas...

(参见问题执行只是如果条件满足 Ant任务)

(See also question Execute ANT task just if a condition is met)

推荐答案

即使势必蚂蚁1.7.1你可能会结合您的CHK 3成的目标之一,看到的条件的片段组成部分。
由于蚂蚁1.9.1(更好地利用,因为蚂蚁1.9.1 看到这个答案的详细信息)是可以添加 if和unless属性的所有任务和嵌套元素,所以没有多余的目标所需,FE :结果

Even when bound to Ant 1.7.1 you may combine your 3 chk targets into one, see the condition part in the snippet. Since Ant 1.9.1 (better use Ant 1.9.3 because of bugs in Ant 1.9.1 see this answer for details) it is possible to add if and unless attributes on all tasks and nested elements, so no extra target needed, f.e. :

<project
  xmlns:if="ant:if"
  xmlns:unless="ant:unless"
> 

<condition property="cloned" else="false">
   <and>
     <available file="${dir}/.git" type="dir"/>
     <resourcecount when="gt" count="0">
       <fileset dir="${dir}/.git"/>
     </resourcecount>
   </and>
</condition>

<exec  executable="git" unless:true="${cloned}">
   <arg value="clone"/>
   <arg value="${repo}"/>
   <arg value="${dir}"/>
</exec>
<exec executable="git" dir="${dir}" if:true="${cloned}">
   <arg value="fetch"/>
</exec>

</project>

这篇关于如果两个条件都满足执行Ant任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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