Ant 如何从目录中获取文件并一次并行执行5个文件
我使用ant获取目录中的所有文件,只并行执行5个文件,然后再次执行5个文件。已执行的文件不应再次执行Ant 如何从目录中获取文件并一次并行执行5个文件,ant,ant-contrib,Ant,Ant Contrib,我使用ant获取目录中的所有文件,只并行执行5个文件,然后再次执行5个文件。已执行的文件不应再次执行 <target name="ParallelTest" description="Checking the parallelTest"> <for param="file" > <path> <fileset dir="C:/RCBuild3/ofs/bin/prd1">
<target name="ParallelTest" description="Checking the parallelTest">
<for param="file" >
<path>
<fileset dir="C:/RCBuild3/ofs/bin/prd1">
<include name="*.xml"/>
</fileset>
</path>
<sequential>
<antcall target="parallelexecutoin">
<param name="productfile" value="@{file}"/>
</antcall>
</sequential>
</for>
</target>
<target name="parallelexecutoin">
<exec dir="C:/RCBuild3/ofs/bin/" executable="cmd">
<arg value="/c"/>
<arg value="productupload.bat"/>
<arg value="-fileName"/>
<arg value="${productfile}"/>
</exec>
</target>
上述代码按顺序执行。首先执行代码:
<fileset dir="C:/RCBuild3/ofs/bin/prd1" id="src.files">
<include name="*.xml"/>
</fileset>
<pathconvert pathsep="," property="file.list" refid="src.files"/>
<for list="${file.list}" delimiter="," param="file" parallel="true" threadCount="5">
<sequential>
<antcall target="parallelexecutoin">
<param name="productfile" value="@{file}"/>
</antcall>
</sequential>
</for>
说明:
首先,为所有需要处理的文件准备一个文件集
然后,使用pathconvert
将文件集转换为属性“file.list”,如:filename1.xml、filename2.xml、filename3.xml
for
任务的java代码(隐藏在Ant文件后面)将使用逗号将“file.list”拆分为列表
,并在列表
中循环。对于列表中的每个元素
,循环体(顺序
部分)将运行
parallel
告诉for
任务使用多个线程运行循环体,而threadcount
是可以同时运行的最大线程数
因此,对于parallel=true
和threadcount=5
,is的行为与您描述的完全相同:一次5个文件