蚂蚁对象和引用:什么是参考的ID的范围有多大? [英] Ant objects and references: what is the scope of a reference's ID?

查看:190
本文介绍了蚂蚁对象和引用:什么是参考的ID的范围有多大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎很奇怪,有没有关于它的文件(至少没有文件,我所知道的,我会很乐意指正)。

Seems odd that there is no documentation about it (at least no documentation that I'm aware of; and I'll be happy to stand corrected).

当我这样做:

<fileset id="my.fs" dir="..."/>

什么是ID的范围 my.fs


  • 整个蚂蚁执行周期?

  • (<即code>取决于对当前目标和任何目标)目前的目标?

  • The entire Ant execution cycle?
  • The current target (and any target that depends on the current target)?

和,最后,会发生什么情况,如果多个线程试图用相同的ID定义文件集(使用平行任务生成)?

And, lastly, what happens if multiple threads (spawned using the parallel task) attempt to define filesets with the same ID?

推荐答案

引用是整个的项目的它们被定义可见。例如,如果&LT;文件集ID =my.fsDIR =.../&GT; 放置任何目标之外,这将是对所有目标可见在构建文件中。如果在目标定义 A ,那么这将是在目标可见 B 如果 B 取决于 A

References are visible across the project in which they are defined. For example, if <fileset id="my.fs" dir="..."/> is placed outside any target, it will be visible for all targets in the buildfile. If it is defined in target A, then it will be visible in target B if B depends on A:

实施例1:

<project name="Project1" default="doIt">

   <fileset id="my.fs" dir="some_dir"/>
   ...

   <target name="doIt">
       <copy todir="some_dir_copy">
           <fileset refid="my.fs" />  <!-- this will work -->
       </copy>
   </target>
</project>

例2:

<project name="Project1" default="doIt">

   <target name="prepare">
       <fileset id="my.fs" dir="some_dir"/>
   </target>

   <target name="doIt" depends="prepare">
       <copy todir="some_dir_copy">
           <fileset refid="my.fs" />  <!-- this will work -->
       </copy>
   </target>
</project>

不过,如果你正在调用的的子项目的,例如使用蚂蚁 antcall 任务,默认子项目会的的继承引用定义在父项目(不像Ant属性)。继承它们,您可以设置 inheritrefs 属性设置为true调用子项目时:

However, if you are invoking a subproject, e.g. using the ant or antcall tasks, the subproject by default will not inherit the references defined in the parent project (unlike Ant properties). To inherit them, you can set the inheritrefs attribute to true when invoking the subproject:

实施例3:

<project name="Project1" default="doIt">

   <target name="doIt">
       <fileset id="my.fs" dir="some_dir"/>
       <ant antfile="./build.xml" target="run" />
   </target>

   <target name="run">
       <copy todir="some_dir_copy">
           <fileset refid="my.fs" />  <!-- this will fail -->
       </copy>
   </target>
</project>

例4:

<project name="Project1" default="doIt">

   <target name="doIt">
       <fileset id="my.fs" dir="some_dir"/>
       <ant antfile="./build.xml" target="run" inheritrefs="true" />
   </target>

   <target name="run">
       <copy todir="some_dir_copy">
           <fileset refid="my.fs" />  <!-- this will work -->
       </copy>
   </target>
</project>

如果你有一个平行任务内部执行并行任务,并且都定义相同的参考编号,则根据执行的顺序,最后一个完成会重写其他任务的参考。

In case you have parallel tasks executing inside a parallel task, and both defined the same reference ID, then depending on the order of execution, the last one to finish will override the other task's reference.

<parallel>
    <fileset id="my.fs" dir="some_dir"/>
    <fileset id="my.fs" dir="another_dir"/>
</parallel>

...

<target name="doIt">
    <copy todir="some_dir_copy">
        <fileset refid="my.fs" />  <!-- this may copy either some_dir or another_dir, depending on which parallel task finished last -->
    </copy>
</target>

这篇关于蚂蚁对象和引用:什么是参考的ID的范围有多大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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