有没有办法可以保证一个蚂蚁依赖只运行一次? [英] Is there a way to guarantee that an ant dependency is run only once?

查看:143
本文介绍了有没有办法可以保证一个蚂蚁依赖只运行一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是类似<一个href=\"http://stackoverflow.com/questions/1861569/avoiding-re-building-$p$prequisites-in-ant\">avoiding-re-building-$p$prequisites-in-ant,除了我的需要不涉及创建的对象,但调用的进程,这样的解决方案讨论有我将无法工作。至少我是这么认为的 - 但我是新来的蚂蚁

My question is similar to avoiding-re-building-prerequisites-in-ant, except that my need doesn't involve created objects, but processes invoked, so the solutions discussed there won't work for me. At least I think so - but I'm new to ant.

我的情况是,我写了一组Ant目标,我需要让叩它的设置的执行一次的目标只有一次,无论是调用了哪些目标。下面是一个大大简化的例子:

My situation is that I'm writing a set of ant targets, and I need the lets-call-it setup target to be executed once and only once, no matter which target is invoked. Here's a greatly simplified example:


    <?xml version="1.0"?>
    <project name="Ant_Test" basedir=".">
      <target name="setup">
        <echo message="In setup" />
      </target>
      <target name="do.several" depends="setup">
        <echo message="In do.several, calling do.first" />
        <antcall target="do.first" />
        <echo message="In do.several, calling do.second" />
        <antcall target="do.second" />
      </target>
      <target name="do.first" depends="setup">
        <echo message="In do.first" />
      </target>
      <target name="do.second" depends="setup">
        <echo message="In do.second" />
      </target>
    </project>

我需要的设置的要调用只有一次,无论的 do.several do.first 的,或者的做的。第二个的调用。随着我的上述天真的尝试,在调用三个调用的设置的do.several结果。

I need setup to be invoked exactly once, regardless of whether do.several, do.first, or do.second are invoked. With my naive attempt above, invoking do.several results in three calls to setup.

我想过设置属性的(我们称之为的 setup.has.been.invoked 的),并用它来有条件地调用的设置的从每个目标之内,但现在看来,属性设置仅限于它在做的范围,因此,如果在的设置的,我设置的 setup.has.been.invoked 的为true,则该值只存在内部的设置

I've thought of setting a property (let's call it setup.has.been.invoked), and using that to conditionally invoke setup from within each target, but it appears that property setting is limited to the scope it's done in, so if in setup, I set setup.has.been.invoked to true, that value only exists within setup.

我在想什么?有没有我跳过教程或联机文档的一部分?任何指针或提示?

What am I missing? Is there a section of the tutorials or online documentation I've skipped? Any pointers or hints?

推荐答案

您应该删除 antcalls 并添加 do.first do.second 作为依赖的 do.several

You should remove the antcalls and add do.first and do.second as dependencies of do.several:

<target name="do.several" depends="setup, do.first, do.second">
</target>

这将确保,即设置只调用一次:

This will make sure, that setup is only called once:

setup:
     [echo] In setup

do.first:
     [echo] In do.first

do.second:
     [echo] In do.second

do.several:

BUILD SUCCESSFUL
Total time: 0 seconds

文件说,为什么在设置一个属性集不antcall工作:

Documentation says why a property set in setup does not work with antcall:

被叫目标(S)在一个新项目运行;要知道,这意味着特性,参考等被称为目标设定将不会持续返回给调用项目。

The called target(s) are run in a new project; be aware that this means properties, references, etc. set by called targets will not persist back to the calling project.

这篇关于有没有办法可以保证一个蚂蚁依赖只运行一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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