ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Scot P. Floess" <flo...@mindspring.com>
Subject Re: For loop question
Date Fri, 29 Jun 2007 15:38:20 GMT
Interesting question...  I actually had a need to iterate over a list 
(using for loop construct) but needed the previous, current and next 
elements in the list - certainly similar functionality.  Here is my 
macro def:

    <macrodef
        name = "process-list"
        description = "Allows one to iterate over a list/files and for 
each element in the list know the previous, current and next values."
        uri         = "http://jplate.sourceforge.net/utility">

        <attribute name = "list"      default = ""   description = "The 
list to process."/>
        <attribute name = "delimiter" default = ","  description = "The 
delimiter for @{list}."/>
        <attribute name = "previous"  default = 
"jplate-utility.PREVIOUS"  description = "Name of property to hold 
previous value in list."/>
        <attribute name = "current"   default = 
"jplate-utility.CURRENT"   description = "Name of property to hold 
current value in list."/>
        <attribute name = "next"      default = 
"jplate-utility.NEXT"      description = "Name of property to hold next 
value in list."/>

        <element name = "path"     optional = "true"  description = 
"Files to process."/>
        <element name = "process"  description = "When iterating over 
@{list}/@{path}, process the contents contained here."/>

        <sequential>
            <!--

                Initial settings...

            -->
            <ant-contrib:var  name = "@{previous}"  value = ""/>
            <ant-contrib:var  name = "@{current}"   value = ""/>
            <ant-contrib:var  name = "@{next}"      value = ""/>

            <!--

                Iterate over files and/or the list, calling process
                for each item.  First iteration we skip as we want
                to ensure we always have a previous, current and next.

            -->
            <ant-contrib:for  list = "@{list}"  delimiter = 
"@{delimiter}"  param = "processlist">
                <ant-contrib:path>
                    <path/>
                </ant-contrib:path>

                <ant-contrib:sequential>
                    <ant-contrib:switch  value = "${@{current}}">
                        <ant-contrib:case  value = "">
                            <ant-contrib:var  name = "@{current}"  value 
= "@{processlist}"/>
                        </ant-contrib:case>

                        <ant-contrib:default>
                            <ant-contrib:var  name = "@{next}"  value = 
"@{processlist}"/>

                            <process/>

                            <ant-contrib:var  name = "@{previous}"  
value = "${@{current}}"/>
                            <ant-contrib:var  name = "@{current}"   
value = "@{processlist}"/>
                        </ant-contrib:default>
                    </ant-contrib:switch>
                   
                </ant-contrib:sequential>
            </ant-contrib:for>

            <!--

                Need to call process with an empty next - meaning end of 
list.

            -->
            <ant-contrib:var  name = "@{next}"  value = ""/>

            <process/>
        </sequential>
   </macrodef>




broken connection wrote:
> Hi Friends,
> I have a simple "for" task question. I use this for task from 
> ant-contrib:
>
>        <for list="${pass1.property},${pass2.property},${pass3.property}"
> param="argvalue">
>        <sequential>
>
>        <exec  executable="${ext}" >
>            <arg value="/c"/>
>            <arg value="execute.bat @{argvalue}"/>
>            <redirector outputproperty="result.property" />
>         </exec>
>
>        </sequential>
>        </for>
>
> I want to pass in 3 values and store the output in 3 different 
> properties .
> Is there anyway to do this??
>
> Rite now, the output of all the 3 parameters gets overritten in "
> result.property"
>
> Your help would be greatly appreciated.
> Thanks
>

-- 
Scot P. Floess
27 Lake Royale
Louisburg, NC  27549

252-478-8087 (Home)
919-392-6730 (Work)

Chief Architect JPlate  http://sourceforge.net/projects/jplate
Chief Architect JavaPIM http://sourceforge.net/projects/javapim


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


Mime
View raw message