ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Jan.Mate...@rzf.fin-nrw.de>
Subject AW: New iterating task
Date Thu, 18 Dec 2008 10:37:47 GMT
Sound very like <antcontrib:foreach> ...

Jan 

>-----Urspr√ľngliche Nachricht-----
>Von: Martin Holst Swende [mailto:martin.holst_swende@msc.se] 
>Gesendet: Donnerstag, 18. Dezember 2008 10:16
>An: Ant Developers List
>Betreff: New iterating task
>
>Hi all,
>
>I have a little utility-task that I wrote because I did not find any 
>better alternative - but maybe I missed something obvious. So 
>I thought 
>I would contribute it, if there is any interest.
>
>Anyway, it is a kind of file iterator meant to be used on 
>tasks that are 
>not written to handle multiple files. Also a few other uses, such as 
>manipulating and/or preserve paths and filenames in the process . Here 
>is how I use it :
>
>    <taskdef resource="antutilstasks" classpath="jar/antutils.jar" />
>
>    <target name="testiterate">
>        <iterate target="myecho">
>            <fileset dir="." includes="**\*.java" />
>            <param name="test" value="Works fine" />
>        </iterate>
>    </target>
>
>    <target name="myecho">
>        <echo>
>                Dir : ${dir}
>                Path  : ${path}
>                Filename:${filename}
>                Extension:${extension}
>                Extra-param: ${test}
>                </echo>
>    </target>
>
>
>What it does is, for each entry in the fileset, it calls the target 
>(myecho), and sets these properties : dir, path, filename, 
>extension and 
>any supplied extra parameters. It just lists files, so far.
>
>The fully qualified path is created in this manner :
>
>dir + path + filename + "." + extension
>
>
>One way of using it is if I have a dir-structure, say a photoalbum, 
>where thumbnails have already been generated in the same 
>structure. If I 
>want to copy all thumbnails, but keep their directory 
>structure, normal 
>file-copy will not suffice (since it will copy all to same directory). 
>But I can do this :
>
>    <target name="copythumbs">
>        <iterate target="mycopy">
>            <fileset dir="photos" includes="**\*_thumb.jpeg" />
>        </iterate>
>    </target>
>    <target name="mycopy">   
>        <copy file="${dir}${path}${filename}.${extension}" 
>todir="thumbs/${path}"/>
>    </target>
>
>The todir will retain path, and copy files into e.g 
>"thumbs/2008/01/21/img01_thumb.jpg" .
>
>And if I have a task that scales images, I could set it up like this :
>
>    <target name="createthumbs">
>        <iterate target="mythumbgenerator">
>            <fileset dir="photos" includes="**\*.jpeg" />
>            <param name="size" value="100x100" />
>        </iterate>
>    </target>
>  <target name="mythumbgenerator">   
>        <rescale file="${dir}${path}${filename}.${extension}" 
>outfile="thumbs/${path}${filename}_thumb.${extension}" size="${size}"/>
>   </target>
>
>This way, I can iterate a task not built for it (in this case 
>"rescale") 
>and be pretty flexible with the input parameters to that task.
>
>So, have I re-invented the wheel?
>
>Regards,
>Martin Holst Swende
>
>-- 
>Martin Holst Swende ................. MSC Konsult AB
>tel: +46(0)70 9519098 ............... Vasagatan 52
>martin.holst_swende@msc.se .......... 111 20 Stockholm
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>For additional commands, e-mail: dev-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message