ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Amerige <Steve.Amer...@sas.com>
Subject Please Help Me Finish This For Loop Code
Date Fri, 02 Dec 2011 01:01:10 GMT
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

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