-->

How to distribute each element of a list to argume

2020-03-24 07:52发布

问题:

How to take the values of argument for a defined task into a list (of values) without to have to rewrite the task for each value of argument ?

Example: I want to avoid to have to rewrite three time the same task for echoing three different values (value 1, value 2, value 3):

<exec executable="cmd">
    <arg value="/c"/>
    <arg value="value 1"/>
</exec>

<exec executable="cmd">
    <arg value="/c"/>
    <arg value="value 2"/>
</exec>

<exec executable="cmd">
    <arg value="/c"/>
    <arg value="value 3"/>
</exec>

Thanks

回答1:

You could use the MacroDef task to abstract the common part of your task:

<macrodef name="myMacro">
    <attribute name="value"/>
    <sequential>
         <exec executable="cmd">
             <arg value="/c"/>
             <arg value="@{value}"/>
         </exec>
    </sequential>
</macrodef>

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


标签: ant macrodef