ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Karr, David" <>
Subject RE: Is it possible to run a target for each file in a fileset?
Date Tue, 24 Jun 2008 15:39:24 GMT
It might be possible to mix in the capabilities of the "xmltask"
library.  This has the ability to call a target for every occurrence of
a particular xpath result value.  If you could find a way to generate an
xml doc with one element for each file name (perhaps using xmltask
itself), you could then use xmltask to implicitly iterate through the

> -----Original Message-----
> From: Andy Stevens [] 
> Sent: Tuesday, June 24, 2008 4:40 AM
> To:
> Subject: Is it possible to run a target for each file in a fileset?
> Hi,
> I'm trying to include jslint in the build script for one of 
> our web apps, using Rhino to run the jslint.js javascript file.
> Initially, I used
>         <java classname=""
> failonerror="true" fork="true">
>             <arg value="lib/test/jslint.js"/>
>             <arg value="${build.web.dir}/javascript/main.js"/>
>             <classpath path="lib/test/rhinojs-1.7r1.jar"/>
>         </java>
> (an earlier target copies main.js from the original source 
> folder to the build directory ${build.web.dir}, applying some 
> token substitution).  This worked just fine.
> However, but we have more javascript files than just main.js 
> and jslint only appears to expect one argument for the file 
> to check.  So I need to run the above on each of our files in 
> turn.  Since this didn't appear to be possible with <java> 
> alone I turned to
>         <apply executable="java" verbose="true">
>             <arg value="-classpath"/>
>             <arg value="lib/test/rhinojs-1.7r1.jar"/>
>             <arg value=""/>
>             <arg value="lib/test/jslint.js"/>
>             <fileset dir="${build.web.dir}/javascript" 
> includes="**/*.js"/>
>         </apply>
> Not ideal, but so long as there's a java executable on the 
> path I guess it'll work.  I'd rather have used <java> for the 
> various classpath etc. settings, but it'll do.  Perhaps one 
> day some of this behaviour might be included in the java 
> task, or someone will come up with an <applyjava> task that 
> combines the two, or maybe the <apply> task could be changed 
> to specify/nest another target or task instead of the executable...
> The only problem with the above is that jslint.js doesn't 
> output the filename of the file it's processing, so if more 
> than one javascript file produces warnings, all I get is a 
> bunch of line & column numbers with no clue as to which of 
> the problems are in which file(s) :-(  So before it runs 
> jslint each time I want to print the filename.  I suppose I 
> could create a batch file to do this (containing an echo and 
> the above java command, each with %1 in their arguments) and 
> have <apply> call that, but I'd rather do it in the Ant 
> script if possible.
>  I haven't found a way to combine the echo & java commands 
> into a single command line (separating them with ; just makes 
> it ignore the second command) so I'm wondering if it's 
> possible to loop over the fileset and call a separate target 
> (containing <echo> and <java>
> tasks) for each one in turn, passing the filename in a 
> property/parameter?  Kind of like a cross between the <apply> 
> and <ant>/<antcall> tasks.
> Is that possible, or is the batch file going to be the 
> easiest way to do what I need?  Or can anyone suggest another 
> way I've not thought of?
> TIA,
> Andy.
> --
>  Open source java sudoku solver
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: For 
> additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message