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: AW: New iterating task
Date Thu, 18 Dec 2008 12:57:10 GMT
Ok, but these property names are fixed. What about
  <property name="dir" value="someValue"/>
  <iterate ...>

The file informations could also retrieved via <basename> and <dirname>. Together
with <antcontrib:var name="..." unset="true"/> these properties could be eliminated
during each loop.

Your task is more comfortable to use if you need the file information. But I think it should
be more generic and support resource collections. Maybe only file resources. The use of a
<sequential> container is also more performant than reusing <ant> or <antcall>.
    <iterate>
        <!-- Resource Collection to iterate -->
        <path ... />
        <!-- Use java.io.File methods -->
        <param name="parent" method="getParent()"/>
        <param name="name" method="getName()"/>
        <!-- Use org.apache.tools.ant.types.resources.FileResource -->
        <param name="size" method="getSize()"/>
        <sequential>
            <echo>
                The size of file '@{name}' in directory '@{parent}' is @{size} Bytes.
            </echo>
        <sequential>
    </iterate>


http://svn.apache.org/repos/asf/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/FileResource.java
http://svn.apache.org/repos/asf/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/FileProvider.java



Jan

>-----Urspr√ľngliche Nachricht-----
>Von: Martin Holst Swende [mailto:martin.holst_swende@msc.se] 
>Gesendet: Donnerstag, 18. Dezember 2008 12:45
>An: Ant Developers List
>Betreff: Re: AW: New iterating task
>
>Yes, it does.
>
>However, the foreach-task, to my understanding, cannot as 
>easily be used 
>in the examples I provided, since it does not provide parametrized 
>file-information (basedir, path, name and extension). Otherwise, it is 
>very similar.
>
>/Martin
>
>Jan.Materne@rzf.fin-nrw.de wrote:
>> 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
>>
>>   
>
>
>-- 
>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