我有一个path如下所示:
<path refid="myjarlocation"/>现在,我想迭代这个路径,对于路径中的每个值,我想调用一个宏,该值作为marcodef中要使用的属性之一。
在目标情况下,我们可以很容易地做到以下几点:
<foreach target="mytarget" param="jarloc">
<path refid="myjarlocation"/>
</foreach>因为我需要传递多个参数,所以我不能使用每个参数,所以我使用的是宏。因此,如何在路径上迭代,调用宏and而不是目标,是一个问题。
发布于 2016-11-02 15:06:39
通过使用ant-cont肋骨的for任务迭代路径并将path元素传递给宏,我做了一些类似的工作。
在您的项目中先获得ant-cont肋骨-请参阅http://ant-contrib.sourceforge.net/
接下来,在ant中定义您的宏define,不管您想要包含哪些属性,这些属性将接受path元素。例:
<macrodef name="awesome-macro">
<attribute name="path-to-deal-with"/>
<attribute name="unrelated-attribute"/>
<sequential>
...
</sequential>
</macrodef>然后,使用for任务将路径迭代到路径元素中,并调用宏:
<for param="path.element">
<fileset dir="${jars.dir}">
<include name="*.jar"/>
</fileset>
<sequential>
<awesome-macro path-to-deal-with="@{path.element}" unrelated-attribute="whatever"/>
</sequential>
</for>注意在for循环中使用@{path.element}而不是${path.element}来引用循环参数!
https://stackoverflow.com/questions/40381282
复制相似问题