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-contrib-1.0b3.jar`是Ant Contrib项目的一个版本,它包含了一系列自定义的任务和标签,用于增强Ant的灵活性。这些任务通常不包含在标准的Ant发行版中,因此需要单独下载并引入到构建脚本中。这个版本的发布解决...
标题中的"ant-contrib-1.0b1.jar.zip"是一个包含特定版本(1.0b1)的"ant-contrib"库的压缩文件,其格式为ZIP,并且内部包含了一个JAR(Java Archive)文件。"ant-contrib"是Apache Ant的一个扩展库,提供了额外的...
本文将详细探讨"ant-contrib-1.0b3-bin.jar"这个组件,并讲解其在Ant构建过程中的作用和使用方法。 一、ant-contrib库介绍 "ant-contrib"库是由社区开发的一个非官方Ant扩展,它包含了一系列自定义的任务和条件,...
例如,"ant-contrib-1.0b3.jar"是Ant Contrib的一个版本,其中包含了一系列增强Ant功能的类和任务。这个特定的版本"1.0b3"是一个早期的发布版,但即便如此,它也提供了许多实用的构建工具。 在Ant项目中,如果没有...
本文将深入探讨Ant在多循环打包方面的应用,以及如何通过"ant-contrib-1.0b3-bin.tar.gz"这个压缩包中的Ant Contrib库来实现多渠道打包。 首先,让我们理解Ant的基本概念。Ant是一种基于XML的构建工具,它的任务是...
Ant Contrib库的核心在于其jar文件,即"ant-contrib.jar",它包含了各种实用的Ant任务和元素,这些任务和元素在标准Ant库中并未提供。 "ant-contrib.jar"通常在完成编译后,会被放置在Ant的安装目录下的"lib"子目录...
"ant-contrib-0.3.jar.zip" 是一个包含Ant贡献库(Ant-Contrib)的压缩文件,主要用于扩展Apache Ant构建工具的功能。Ant是Java项目自动化构建的首选工具,而Ant-Contrib则是Ant的一个非官方扩展,提供了许多额外的...
在压缩包中包含的"ant-contrib-1.0b3.jar"文件,这是Ant Contrib的一个早期版本(1.0b3),它包含了如foreach、if、propertyregex等自定义任务。这些任务在标准Ant中未提供,但它们在实际项目中非常有用,例如,...
《Ant Contrib 0.6.jar.zip:Apache Ant的扩展库及其应用》 在软件开发领域,构建工具扮演着至关重要的角色,它们自动化了编译、测试、打包等过程,极大地提高了开发效率。Apache Ant作为Java项目中最受欢迎的构建...
《Ant Contrib R170.jar.zip:Apache Ant的扩展库详解》 Apache Ant是一个Java库和命令行工具,其任务是驱动构建过程。它的工作原理是通过XML来定义任务,这些任务可以包括编译、创建JAR文件、复制文件、执行单元...
例如,Ant-contrib包含了像foreach、if、switch这样的控制结构,使得在Ant脚本中可以实现更复杂的逻辑。这对于自动化构建过程中的条件判断和循环操作非常有用。 在Ant的官方网站上,你可以找到最新版本的Ant以及Ant...
标题中的"ant-contrib-0.2.jar.zip"是一个压缩文件,它包含了一个名为"ant-contrib-0.2.jar"的Java归档(JAR)文件和一个名为"ant.license.txt"的文本文件。这个压缩包主要与Apache Ant工具有关,Ant是一个广泛使用...
**jstl-api-1.2.jar** 包含了JSTL的接口定义,定义了各种标签的API,比如`<c:forEach>`、`<fmt:formatDate>`等。这个jar文件通常被添加到项目的编译类路径(classpath)中,这样编译器就可以识别JSTL相关的代码,并...
标题中的"jakarta.servlet.jsp.jstl-api-2.0.0.jar"是一个重要的Java Web开发组件,它属于JavaServer Pages(JSP)标准标签库(JSTL)的一部分,用于提供一套标准的标签来简化HTML或XML文档的生成。JSTL的主要目标是...
除了`for`宏,`ant-contrib`还提供了其他有用的宏,如`foreach`、`if`、`unless`等,它们分别对应于迭代、条件判断等功能,使得Ant脚本可以处理更复杂的逻辑。 "使用说明.txt"文件则详细介绍了如何将`ant-contrib`...
例如,`<c:forEach>`、`<fmt:formatDate>`等,这些都是通过API接口实现的。 2. **jstl-impl-1.2.jar**: 这个jar文件是JSTL的具体实现,包含了JSTL API的实际实现类和相关的库。当JSP页面在服务器上运行时,会调用这...
《Ant Launcher 1.6.jar:构建自动化利器详解》 在Java开发领域,Apache Ant是一个不可或缺的工具,它是一款基于Java的构建工具,用于管理软件项目的构建、部署和依赖关系。而`ant-launcher-1.6.jar`是Apache Ant...
总的来说,`jstl-1.2.jar`和`standard-1.1.2.jar`是Java Web开发中不可或缺的两个库,它们为开发者提供了丰富的标签功能,使得JSP页面编写更加高效和整洁。通过合理的使用,可以大大提高项目的质量和开发效率。
<pathelement location="path/to/ant-contrib-1.0b2.jar"/> ``` 然后我们可以在构建脚本中使用`for`任务: ```xml **/*.java"/> <echo>Processing @{file} <!-- 其他处理每个文件的操作 --> ...
ant的扩展包,实现foreach等操作