how to do for loop based on a limit in Ant

performanceuser picture performanceuser · Oct 5, 2011 · Viewed 8.3k times · Source

In Ant-contrib, we can do something like:

<for list="a,b,c,d" param="instence">

But if I don't have a list, I only have a limit, e.g. limit=4.

Is there a way to do for loop based on limit, like:

<for limit="4" param="index">

Answer

Rajesh Guptan picture Rajesh Guptan · Mar 27, 2014
<project name="Attachments" default="print">
    <property name="numAttachments" value="20" />
    <target name="generate">
        <script language="javascript"><![CDATA[
            var list = '1';
            var limit = project.getProperty( "numAttachments" );
            for (var i=2;i<limit;i++)
            { 
                list = list + ',' + i;
            }
            project.setNewProperty("list", list);            
        ]]>
        </script>    
    </target>
    <target name="print" depends="generate">
        <for list="${list}" param="letter">
            <sequential>
                <echo>Letter @{letter}</echo>
            </sequential>
        </for>
    </target>
</project>