Search code examples
antmacrodef

How to replace three calls to a macrodef by only one?


How to replace three calls to "myMacro":

<myMacro value="value 1"/>
<myMacro value="value 2"/>
<myMacro value="value 3"/>

By only one call who would use a list of three elements: value 1, value 2, value 3


Solution

  • You could make use of the For task from the 3rd party Ant-Contribs tasks. It makes use of the Ant MacroDef task, so combining this with your earlier question you could replace your macro and three macro calls with:

    <for list="1,2,3" param="value">
        <sequential>
            <exec executable="cmd">
                <arg value="/c"/>
                <arg value="value @{value}"/>
            </exec>
        </sequential>
    </for>