Hi Manik, I have developed an Iterate task that allows you to iterate (loop). I've submitted it to the project, but haven't got a reply yet...
Here is the email that I sent to the development group. 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. . org.apache.tools.ant.taskdefs.Iterate.java 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 package. 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="org.apache.tools.ant.taskdefs.myTest"> <target name="main"> <iterate target="hello" itemList="1,3,5" id="iterate.value" > </iterate> </target> <target name="hello"> <echo message="${iterate.value}" /> </target> </project> 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" id="iterate.module"/> </target> <target name="javac" depends="checkSource, cleanBuild, prepareBuild" if="compile.source.exist"> <javac srcdir="${iterate.module}/src" destdir="${iterate.module}/build"> <include name="**\/*.java"/> </javac> <!-- create a jar file for each module--> <mkdir dir="${iterate.module}/lib"/> <jar jarfile="${iterate.module}/lib/classes.jar"> <fileset dir="${iterate.module}/build"/> </jar> </target> ... The above example does the following: . Compiles the myModule/src directory into myModule/lib/classes.jar . Compiles the myModule/mySubModule/src directory into myModule/mySubModule/lib/classes.jar I have included the source, classes and a example build script that calls the new task. Cheers, Alan -----Original Message----- From: Manik Surtani [mailto:[EMAIL PROTECTED]] Sent: 12 November 2001 15:04 To: [EMAIL PROTECTED] Subject: Looping in ANT Hello, all. I have noticed a problem with ant, and that is performing loops. If I want a set of tasks to repeat several times based on a set of properties, the only way I can do this is using the <script> tags, and perform the loops in javascript. Also, it is not possible to use the <script> tags to envelope a set of tasks to loop through, such as: <script language="javascript"> for (i=0; i<10; i++) { </script> <echo message="This is my task to be repeated" /> <script language="javascript"> } </script> Instead, I have to create and execute the task in Javascript, which really takes away from the whole ANT XML build script thing. My current J2EE build script runs almost everything in a loop, so this means almost the entire build.xml is just Javascript!! Is there an alternate way to do this? Also, who is the maintainer of the <script> tasks? I am keen to know if such functionality (as described above) could be possible - I am volunteering to help develop the <script> task, but I need to get more famniliar with the task first. Cheers, -- Manik Surtani Chief Technology Officer Silk Road Limited Telephone: 07786 702 706 Email: [EMAIL PROTECTED] Web: http://www.silkroad.co.uk -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>