Ant objects and references: what is the scope of a reference's ID? -
seems odd there no documentation (at least no documentation i'm aware of; , i'll happy stand corrected).
when this:
<fileset id="my.fs" dir="..."/>
what scope of id my.fs
?
- the entire ant execution cycle?
- the current target (and target
depends
on current target)?
and, lastly, happens if multiple threads (spawned using parallel
task) attempt define filesets same id?
references visible across project in defined. example, if <fileset id="my.fs" dir="..."/>
placed outside target, visible targets in buildfile. if defined in target a
, visible in target b
if b
depends on a
:
example 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" /> <!-- work --> </copy> </target> </project>
example 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" /> <!-- work --> </copy> </target> </project>
however, if invoking subproject, e.g. using ant
or antcall
tasks, subproject default not inherit references defined in parent project (unlike ant properties). inherit them, can set inheritrefs
attribute true when invoking subproject:
example 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" /> <!-- fail --> </copy> </target> </project>
example 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" /> <!-- work --> </copy> </target> </project>
in case have parallel tasks executing inside parallel
task, , both defined same reference id, depending on order of execution, last 1 finish override 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" /> <!-- may copy either some_dir or another_dir, depending on parallel task finished last --> </copy> </target>
Comments
Post a Comment