antcall的 用法

前言

    AntCall 任务的作用是允许在一个target的执行过程中调用并执行其他的target。例如,在打包项目前需要对项目进行编译,那么可以在打包项目的target中通过AntCall任务使得编译的target先执行。当然这种情况也可以通过target间设置depends属性来实现。AntCall任务必须在target元素内执行,这个任务不能在target元素外执行。

1、antcall Task属性及功能

antcall任务主要包括target,inheritAll和inheritRefs3个属性,具体说明如下:
(1)target属性:在AntCall任务中target属性的作用是指定要被调用执行的target,通过名称指定这个target属性是必需的。值得注意的是,当通过AntCall任务调用的target存在依赖的target(depends中指定了target),则depends属性中被指定的target也会被执行。

(2)inheritAll属性:用于指定是否继承当前的属性。默认时为true,代表被调用的target可使用这些属性。

(3)inheritRefs属性:用于指定是否覆盖reference属性或者是否建立一个对当前reference属性的引用。在默认的情况下,AntCall任务不会覆盖reference属性,除非把inheritRefs属性设为true。默认时inheritRefs属性为false。

2、利用antcall Task实现target间调用的实例

    利用AntCall任务来实现target间的相互调用。下面编写构件文件antcallSample.xml,实现在targetA中调用执行targetB。构件文件内容如下:

这里写图片描述

结果:
这里写图片描述

如果targetB有依赖其他target呢?

<?xml version="1.0"  ?>

<project name="HelloWorld" default="all">
    <target name="all">
        <echo message="before init targetB"/>
        <antcall target="targetB"/>
        <echo message="after init targetB"/>
    </target>
    <target name="targetB" depends="targetC">
        <echo message="This is targetB"/>
    </target>
    <target name="targetC">
        <echo message="This is targetC"/>
    </target>


</project>

结果如下图所示:

这里写图片描述

targetB会先去调用targetB,然后再执行targetB

3、利用antcall Task实现target间调用时传递参数的实例

    当需要从一个target传递参数到被调用的target时,可以使用 类型进行传递。当然也可以在target中定义property来实现,与Java中的方法调用时传递参数相似。修改antcallSample.xml以实现传递参数的功能,内容如下:

<?xml version="1.0"  ?>

<project name="HelloWorld" default="all">
    <target name="all">
        <echo message="before init targetB"/>
        <property name="param1" value="param1Value"/>
        <antcall target="targetB">
            <param name="param2" value="param2Value"/>
        </antcall>
        <echo message="after init targetB"/>
    </target>

    <target name="targetB">
        <echo message="This is targetB,param1=${param1},param2=${param2}"/>
    </target>


</project>

结果如下:
这里写图片描述

从执行结果可看出,通过property指定和通过AntCall中的param指定的属性都传递到targetB中。对于param 类型只有两个属性:name和value。由于AntCall任务中的inheritAll属性默认时为true,所以property能被targetB引用。如果targetB中也定义了相同的property,那么可以通过设置inheritRefs属性和reference类型进行覆盖。

4、depends的任务调用和antcall任务调用的细微差别

    区别在于,用depends的方式调用,那么被调用任务中的设置或者修改的属性值可以在后面的任务中使用,而用antcall的调用就不可以

参考网址:http://blog.csdn.net/dancelonely/article/details/16960333

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值