如何将列表的每个元素分配给任务 Ant 的参数? [英] How to distribute each element of a list to argument of a task Ant?

查看:26
本文介绍了如何将列表的每个元素分配给任务 Ant 的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将已定义任务的参数值放入(值)列表中,而不必为每个参数值重写任务?

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 ?

示例:我想避免为了回显三个不同的值(值 1、值 2、值 3)而必须重写三次相同的任务:

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>

谢谢

推荐答案

您可以使用 MacroDef 任务 抽象你的任务的公共部分:

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 的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆