For
The for task iterates over a list, a list of paths, or any type that has a public iterator() method. The list will be evaluated first. Nested paths are evaluated in the order they appear in the task. Nested types will then be evalulated.
This task is the same as the <foreach> task, except that
* it uses a nested sequential for each iteration; and
* it implements an additional "keepgoing" attribute.
<for> makes use of ant's macrodef task, so the @{} notation is used for parameter substition.
This task only works for ant version greater than or equal to ant 1.6.0.
Parameters
Attribute Description Required
list The list of values to process, with the delimiter character, indicated by the "delimiter" attribute, separating each value. Yes, unless a nested path has been specified.
param Name of the parameter to pass the tokens or files in as to the sequential. Yes
delimiter The delimiter characters that separates the values in the "list" attribute. Each character in the supplied string can act as a delimiter. This follows the semantics of the StringTokenizer class. No, defaults to ",".
parallel If true, all iterations of the nested <sequential> will execute in parallel. Defaults to false, which forces sequential execution of the iterations. It is up to the caller to ensure that parallel execution is safe. No
keepgoing If true, all iterations of the called <sequential> will be executed, even if a task in one or more of them fails. Defaults to false, which forces execution to stop as soon as a task fails. At the end, if any iterator has failed, the <for> task will fail, otherwise <for> will succeed.
Note that execution does not proceed keepgoing from one task to the next within the <sequential>, but rather from one iteration to the next.
It is up to the caller to ensure that keepgoing execution is safe.
No
threadCount The maximum number of allowable threads when executing in parallel. No. Defaults to 5.
trim If true, any leading or trailing whitespace will be removed from the list item before it is passed to the sequential. No. Defaults to false.
Parameters specified as nested elements
path
Paths are used to select sets of files or directories to iterate over.
Using a path allows you to determine the order by which files are considered by using filelists or explicit pathelements. You also can specify whether you want to iterate over files or directories by chosing either filesets or dirsets.
fileset
FileSets are used to select sets of files to iterate over.
dirset
DirSets are used to select sets of directories to iterate over.
sequential
This is the list of tasks to be run for each iteration of the list.
Example
To print out the first five letters of the latin alphabet:
<echo message="The first five letters of the alphabet are:"/>
<for list="a,b,c,d,e" param="letter">
<sequential>
<echo>Letter @{letter}</echo>
</sequential>
</for>
A more complicated example to to iterate over a set of c++ source files and invoke the <cc> task on them:
<for param="file">
<path>
<fileset dir="${test.dir}/mains" includes="*.cpp"/>
</path>
<sequential>
<propertyregex override="yes"
property="program" input="@{file}"
regexp=".*/([^\.]*)\.cpp" replace="\1"/>
<mkdir dir="${obj.dir}/${program}"/>
<mkdir dir="${build.bin.dir}"/>
<cc link="executable" objdir="${obj.dir}/${program}"
outfile="${build.bin.dir}/${program}">
<compiler refid="compiler.options"/>
<fileset file="@{file}"/>
<linker refid="linker-libs"/>
</cc>
</sequential>
</for>
The preceding example will stop as soon as one of the <cc> tasks fails. If you change the first line of the example to
<for param="file" keepgoing="true">
All iterations will be executed, and then <for> will fail if any one or more of the <cc> tasks failed.
The following example embeds an outofdate type and iterates over the sources that are newer than their corresponding targets.
<ac:for param="xmlfile" xmlns:ac="antlib:net.sf.antcontrib">
<ac:outofdate>
<ac:sourcefiles>
<ac:fileset dir="${basedir}/xdocs" includes="**/*.xml"/>
</ac:sourcefiles>
<ac:mapper dir="${basedir}/xdocs"
type="glob" from="*.xml" to="${basedir}/docs/*.html"/>
</ac:outofdate>
<ac:sequential>
<echo>Need to generate a target html file from source file @{xmlfile}</echo>
</ac:sequential>
</ac:for>
分享到:
相关推荐
ant进行打包脚本的时候会使用到foreach等方法,需要依赖使用ant-contrib-1.0b3.jar。
ant的扩展包,实现foreach等操作
前端开源库-gulp-foreach吞下foreach,将每个文件按流发送到自己的流中
前端项目-foreach,Foreach组件 NPM包
大厂前端面试|# 开始 大厂面试会通过各种难题来试探你的技术深度,评估你的技术发展潜力,这是入职后确定级别、薪资的重要参考。所以,技术深度将决定你的“钱途”。本章将通过多个面试题,讲解前端面试常考的底层...
前端el表达式应用。判断、循环
C-FOREACH用法需要遍历的集合放到items中,然后定义一个temp为每次应用到的集合元素,然后设置起步值及叠加步数
javascript-foreach用法
怎样选择并行处理:选择Parallel.ForEach 还是 PLINQ ?
JSTL核心表情控主要包括流程处理标签,如果用到<c:forEach>等,需要在lib下导入jstl-1.2.jar包
主要给大家介绍了关于C#并发实战记录之Parallel.ForEach使用的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用C#具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
前端开源库-foreach-clifor each cli,cli-util为每个与glob匹配的文件执行命令
VB085-foreach和array的应用源代码
Parallel.ForEach读取经常卡死,大家可以参考代码如何解决。
Make ForEach-Object faster for its commonly used scenarios (#10454) and fix ForEach-Object -Parallel performance problem with many runspaces (#10455) Experimental Features Update ...
改进了linux tailq队列下在遍历时删除多个元素的问题。可以使用TAILQ_FOREACH_SAFE下面进行节点删除操作。不会出现野指针问题
Array.prototype.forEach 这是Array.prototype.forEach polyfill 的 Git/Bower 包。
关于jsp中的<c:foreach>问题,要想使用它们,首先引用这两个语句需要导入两个包sjtl.1.2.jar和standard.1.1.2.jar
生成器-foreach forEach 用于生成器 想象一下,您想在生成器函数中使用forEach : var stuff = [ 1 , 2 , 3 , 4 , 5 ] function * fn ( ) { stuff . forEach ( something ) function something ( item ) { console ....
java-array-list-foreach