ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Amerige <Steve.Amer...@sas.com>
Subject Re: Please Help Me Finish This For Loop Code
Date Fri, 02 Dec 2011 19:05:52 GMT
Hi Matt,

Thanks for your reply, but the macrodef as written will only go down 1-level deep because
of the line:

    <istrue value="@{setup}"/>

Again, please understand that the <for><propertyset.../></for> solution
will not work for me and
that I'm trying to understand the technique of passing an element via a script as described.
Let's not try to solve a "problem" but to focus on the technique of how an element is passed.

I've looked at MacroInstance:

     http://api.dpml.net/ant/1.7.0/index.html?org/apache/tools/ant/taskdefs/MacroInstance.html

And, I'm trying to understand how createDynamicElement might help out (even though
it is deprecated).  Or, maybe one of the other methods in MacroInstance will be the
right one for the technique of passing an element from a script.

Best regards,
Steve Amerige
SAS Institute, Deployment Software Development

On 12/2/2011 1:52 PM, Matt Benson wrote:
> On Fri, Dec 2, 2011 at 12:31 PM, Steve Amerige<Steve.Amerige@sas.com>  wrote:
>> Hi all,
>>
>> Of course, I have to say it... sometimes I need to iterate the list forwards
>> and sometimes backwards.  Also, is there a guarantee that iteration will
>> happen in numerical order?  And, I have other issues that make the reply not
>> satisfactory to my needs that I haven't spelled out because the details are
>> confidential.
>>
>> I sometimes hate to say what the "purpose" of a request is because then the
>> responses get off the path that I need them to be.  In my case, this
>> solution will not work.  There are reasons I can't go into detail on.
>>
>> So, I'd like to focus merely on the technique, not the problem space.  So,
>> I'm still looking for the technique to pass the element via a script, likely
>> with MacroInstance methods.
>>
>> Thanks for any ideas as to refining this technique.
> Well, the first thing you need to do is redo your design such that
> your macrodef isn't self-referential.  More likely you just need a
> macrodef for the "body" of your loop, and a scriptdef or simple inline
> script to handle calling it.
>
> As for the ordering issue with the<for><propertyset.../></for>
> solution, the propertyset is a resource collection.  If you want to
> sort it, wrap it in a<sort>  resourcecollection.
>
> Matt
>
>> Enjoy,
>>
>> Steve Amerige
>> SAS Institute, Deployment Software Development
>>
>> On 12/2/2011 12:41 PM, Matt Benson wrote:
>>> On Fri, Dec 2, 2011 at 11:38 AM, Vimil Saju<vimilsaju@yahoo.com>    wrote:
>>>> You can do something as follows
>>>>
>>>> <propertyset id="arrayProperties1">
>>>> <propertyref regex="a\.b\.c\.[0-9]+x\.y"/>
>>>> </propertyset>
>>>>
>>>> <for list="${toString:arrayProperties1}" param="arrayProperty">
>>>> <!-- your processsing logic goes here -->
>>>> </for>
>>>>
>>>> <propertyset id="arrayProperties2">
>>>> <propertyref regex="a\.b\.c\.[0-9]+p\.q"/>
>>>> </propertyset>
>>>>
>>>> <for list="${toString:arrayProperties2}" param="arrayProperty">
>>>> <!-- your processsing logic goes here -->
>>>> </for>
>>>>
>>>> <propertyset id="arrayProperties3">
>>>> <propertyref regex="a\.b\.c\.[0-9]+s\.t"/>
>>>> </propertyset>
>>>>
>>>> <for list="${toString:arrayProperties3}" param="arrayProperty">
>>>> <!-- your processsing logic goes here -->
>>>> </for>
>>>>
>>>>
>>>> The 'for' task is from antcontrib.
>>>>
>>> Actually, I really like this approach.  You actually don't even need
>>> to specify these propertysets using list="${toString:...}"; it should
>>> be perfectly feasible to specify these as nested elements in<for>.
>>> Hats off to Vimil!  :)
>>>
>>> Matt
>>>
>>>> ________________________________
>>>>   From: Steve Amerige<Steve.Amerige@sas.com>
>>>> To: user@ant.apache.org
>>>> Sent: Friday, December 2, 2011 8:58 AM
>>>> Subject: Re: Please Help Me Finish This For Loop Code
>>>>
>>>> Hi Matt, Scot, and all,
>>>>
>>>>> Do you really need to iterate over numbers?  What practical concern
>>>>> are you trying to address?
>>>> Yes, I really do.  :-)
>>>>
>>>> I'm iterating over "array" data where you have properties of the form:
>>>>
>>>>       a.b.c.1.x.y, a.b.c.1.p.q, a.b.c.1.s.t
>>>>       a.b.c.2.x.y, a.b.c.2.p.q, a.b.c.2.s.t
>>>>       a.b.c.3.x.y, a.b.c.3.p.q, a.b.c.3.s.t
>>>>       ...
>>>>       a.b.c.N.x.y, a.b.c.N.p.q, a.b.c.N.s.t
>>>>
>>>> And I'm doing various different kinds of processing depending on what the
>>>> x.y, p.q, and s.t property values are.  These properties
>>>> come from a property file that are generated by some script and can
>>>> contain potentially tens of thousands of entries.
>>>>
>>>> I don't have a choice as to using some other language.  Yes, this need is
>>>> more suited to Java, C, Groovy, etc.  But, as they say, it
>>>> is what it is.  So, I'm looking for a solution.
>>>>
>>>> So, I've nearly got a solution and am hoping to hear from anyone about
>>>> how elements can be set in the script portion below (whether
>>>> JavaScript or Groovy).  Or if you can think of some other way to
>>>> implement a for loop that will not have problems no matter how many
>>>> iterations are needed, I'd love to hear your ideas and give you kudos!
>>>>
>>>> I'm hoping that some of the developers can share just how MacroInstance
>>>> methods are supposed to be used by completing the example
>>>> below.  I'm sure the Ant community will be grateful!
>>>>
>>>> Many thanks,
>>>> Steve Amerige
>>>> SAS Institute, Deployment Software Development
>>>>
>>>> On 12/2/2011 11:43 AM, Matt Benson wrote:
>>>>> On Fri, Dec 2, 2011 at 10:34 AM, Scot P. Floess<sfloess@nc.rr.com>
>>>>> wrote:
>>>>>> Oops, you said Ant contrib is fine ;)
>>>>>>
>>>>>> Let me give this some thought - I may be able to help.  I thought
I had
>>>>>> some
>>>>>> code I wrote to do a "for" - I did and it used recursion...and just
>>>>>> like you
>>>>>> mention, craps out around 300 iterations...  At one time I had figured
>>>>>> out
>>>>>> how to do this...but have no idea where I put the code or if I even
>>>>>> implemented it....
>>>>>>
>>>>>>
>>>>>>
>>>>>>     On Thu, 1 Dec 2011, Steve Amerige wrote:
>>>>>>
>>>>>>> Hi all,
>>>>>>>
>>>>>>> I'm looking to implement a for loop in Ant (antcontrib,
>>>>>>> javascript/groovy
>>>>>>> scripts are okay).
>>>>>>>
>>>>>>> <target name="test-forloop">
>>>>>>> <forloop start="1" end="1000">
>>>>>>> <echo message="i = ${i}"/>
>>>>>>> </forloop>
>>>>>>> </target>
>>>>>>>
>>>>>>> <macrodef name="forloop">
>>>>>>> <attribute name="i"      default=""/>
>>>>>>> <attribute name="start"  default=""/>
>>>>>>> <attribute name="end"    default=""/>
>>>>>>> <attribute name="setup"  default="true"/>
>>>>>>> <element name="forbody"  implicit="true"/>
>>>>>>> <sequential>
>>>>>>> <if>
>>>>>>> <istrue value="@{setup}"/>
>>>>>>> <then>
>>>>>>> <script language="javascript">
>>>>>>> <![CDATA[
>>>>>>>                 var start=@{start};
>>>>>>>                 var end=@{end};
>>>>>>>                 for (i = start; i<= end; i++) {
>>>>>>>                    macrotask = project.createTask("forloop");
>>>>>>>                    macrotask.setDynamicAttribute("i", i);
>>>>>>>                    macrotask.setDynamicAttribute("setup", "false");
>>>>>>>                    macrotask.perform();
>>>>>>>                 }
>>>>>>>              ]]>
>>>>>>> </script>
>>>>>>> </then>
>>>>>>> <else>
>>>>>>> <echo message="forbody iteration # @{i}:"/>
>>>>>>> <!--<forbody/>     -->
>>>>>>> </else>
>>>>>>> </if>
>>>>>>> </sequential>
>>>>>>> </macrodef>
>>>>>>>
>>>>>>> I'm looking to implement a for loop in Ant that acts on an element.
>>>>>>>   Ant
>>>>>>> 1.7, Antcontrib, javascript/groovy scripts are okay.
>>>>>>>
>>>>>>> The above code works, but it doesn't call the<forbody/>.
 I'm using
>>>>>>> JavaScript to implement the for loop, but I don't know how to
add to
>>>>>>> the
>>>>>>> macrotask the passed-in element so that it gets called on each
loop.
>>>>>>>   I've
>>>>>>> read pages on createDynamicElement (deprecated) and addTask in
>>>>>>> MacroInstance:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> http://javasourcecode.org/html/open-source/ant/ant-1.7.0/org/apache/tools/ant/taskdefs/MacroInstance.html
>>>>>>>
>>>>>>> But no examples are given to help me finish the above example.
 Note
>>>>>>> that
>>>>>>> I did succeed in getting a version to work using recursion.
>>>>>>>   Unfortunately,
>>>>>>> it would only recurse 300 deep before aborting.  The above code
>>>>>>> doesn't have
>>>>>>> any problem with recursion.
>>>>>>>
>>>>>>> Can anyone help finish this code example so that<forbody/>
    can be
>>>>>>> called?
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Steve Amerige
>>>>>>> SAS Institute, Deployment Software Development
>>>>>>>
>>>>>> Scot P. Floess             RHCT  (Certificate Number 605010084735240)
>>>>>> Chief Architect FlossWare  http://sourceforge.net/projects/flossware
>>>>>>                              http://flossware.sourceforge.net
>>>>>>                              https://github.com/organizations/FlossWare
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>>>>>> For additional commands, e-mail: user-help@ant.apache.org
>>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>>>>> For additional commands, e-mail: user-help@ant.apache.org
>>>>>
>>>>>
>>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>>> For additional commands, e-mail: user-help@ant.apache.org
>>>
>>>
>>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
>


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message