ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alan Peng" <>
Subject RE: [SUBMIT] Iterate Task
Date Thu, 08 Nov 2001 22:57:27 GMT
Here is the attached source and docs.

-----Original Message-----
From: Alan Peng []
Sent: 08 November 2001 22:54
To: Ant Developers List
Subject: [SUBMIT] Iterate Task

I would like to submit a task that allows you to repeatedly call a target
passing different values from a list.

Ant does not support iteration or loop mechanisms that allows you to repeat
certain processes. Without such a mechanism, repeat processes have to be
hard coded, one entry in the build script per occurrence. This is less than
desirable because as it requires the modification of the build script each
time the project changes.

An iteration Java task has been developed which better supports the repeat
processes in the build.


Note: We had to use the standard Ant package names because the custom task
requires access to certain protected functions in classes in the Ant

This new task repeatedly calls a target passing different values from a
delimited string.

For example:
<project name="Ant_Extensions" default="main" basedir=".">
   <taskdef name="iterate" classname="">

   <target name="main">
     <iterate target="hello" itemList="1,3,5" id="iterate.value" >

   <target name="hello">
     <echo message="${iterate.value}" />

The above example will call the hello target three times, each time passing
a value from the item list. In this case the hello target will echo 1, then
3 and then 5.

A more useful example is the ability to compile multiple source directories
into multiple jar files.

For example:
 <target name="build" depends="init">

   <!-- iterate through the ${build.modules} variable, compiling each module
specified -->
   <iterate target="javac" itemList="myModule,myModule/mySubModule"

 <target name="javac" depends="checkSource, cleanBuild, prepareBuild"

   <javac  srcdir="${iterate.module}/src" destdir="${iterate.module}/build">
     <include name="**\/*.java"/>

   <!-- create a jar file for each module-->
   <mkdir dir="${iterate.module}/lib"/>

   <jar jarfile="${iterate.module}/lib/classes.jar">
     <fileset dir="${iterate.module}/build"/>

 The above example does the following:

·               Compiles the myModule/src directory into
·               Compiles the myModule/mySubModule/src directory into

I have included the source, classes and a example build script that calls
the new task.


View raw message