Ant <apply>在多个目录中</apply>

时间:2012-12-05 16:00:54

标签: ant

我想简化这个:

<target name="build">
   <parallel>
      <antcall target="build-A" />
      <antcall target="build-B" />
      <antcall target="build-C" />
   </parallel>
</target>

<target name="build-A">
   <exec executable="tool.exe" dir="projects/A">
      <arg value="input.xml" />
   </exec>
</target>

其中build-Bbuild-C执行相同的操作(分别仅在dirs BC中),类似于此:

<dirset id="projects" dir="." >
   <include name="projects/*" />
</dirset>

<apply executable="tool.exe" parallel="true">
   <arg value="input.xml" />
   <dirset refid="projects" />
</apply>

这不起作用,因为apply将执行以下操作之一:

如果parallel设置为true

tool.exe input.xml projects/A projects/B projects/C

parallel设置为false

tool.exe projects/A/input.xml
...waits for tool.exe to complete...
tool.exe projects/B/input.xml
...etc

即使这是不正确的,因为tool.exe期望在 projects/A目录中运行

有没有办法并行化这个,以便我得到的输出相当于:

cd project/A
tool.exe input.xml

cd ../B
tool.exe input.xml

cd ../C
tool.exe input.xml

但并行?

1 个答案:

答案 0 :(得分:4)

我会使用ant-contribfor task来执行此操作。

<for param="dir" parallel="true">
    <dirset id="projects" dir="." >
        <include name="projects/*" />
    </dirset>
    <sequential>
        <exec executable="tool.exe" dir="@{dir}">
            <arg value="input.xml" />
        </exec>
    </sequential>
</for>