Define a list or a set of variables in ant

强颜欢笑 提交于 2019-12-10 17:21:50

问题


I'd like to define a list of variables in ant build file in order to use for loop with this list in my tasks. How can I do that?

p.s.: It should be something like the following:

<varlist name="mylist"> <!-- Actually, there is no such tag in Ant -->
    <item>someThing</item>
    <item>anotherThing</item>
</varlist>

...

<for param="item" list="${mylist}">
    <sequential>
        <echo>@{item}</echo>
    </sequential>
</for>

回答1:


Not sure if this is what you meant:

<echo message="The first five letters of the alphabet are:"/>
<for list="a,b,c,d,e" param="letter">
  <sequential>
    <echo>Letter @{letter}</echo>
  </sequential>
</for>



回答2:


<!-- "For" task is supported by Ant-Contrib Tasks 
http://ant-contrib.sourceforge.net/tasks/tasks/index.html -->
<taskdef resource="net/sf/antcontrib/antlib.xml">
  <classpath>
    <pathelement location="ant-contrib-1.0b3.jar"/>
  </classpath>
</taskdef>

<property name="someThing" value="Hello"/>
<property name="anotherThing" value="World!"/>

<target name="loop">
    <for param="item" list="${someThing},${anotherThing}">
        <sequential>
            <echo>@{item}</echo>
        </sequential>
    </for>
</target>



回答3:


Ant Addon Flaka has a very flexible for task. You may use your own property foobar=item1,item2,.. or any existing csv like property, f.e. some property provided by ant path/fileset/dirset like ${ant.refid:whatever} or ${toString:whatever} or the result of an EL function provided by Flaka like split() or list() .. or another list of objects/items to iterate over, see Flaka manual, Flaka examples for more details and examples.



来源:https://stackoverflow.com/questions/10030190/define-a-list-or-a-set-of-variables-in-ant

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!