How can I use something like an array or list in Ant?

泄露秘密 提交于 2020-01-22 15:12:10

问题


I have a list of strings (e.g. "piyush,kumar") in an Ant script for which I want to assign piyush to var1 like <var name="var1" value="piyush"/> and kumar to var2 like <var name="var2" value="kumar"/>.

So far, I'm using a buildfile like the following:

<?xml version="1.0"?>
<project name="cutter" default="cutter">
<target name="cutter">
<for list="piyush,kumar" param="letter">
  <sequential>
    <echo>var1 @{letter}</echo>
  </sequential>
</for>
</target>
</project>

I'm not sure how to progress this - any suggestions?


回答1:


Here's an example using an ant-contrib variable and the math task:

<var name="index" value="1"/>
<for list="piyush,kumar" param="letter">
  <sequential>
    <property name="var${index}" value="@{letter}" />
    <math result="index" operand1="${index}" operation="+" operand2="1" datatype="int" />
  </sequential>
</for>

<echoproperties prefix="var" />

Output:

[echoproperties] var1=piyush
[echoproperties] var2=kumar

This is all very un-Ant like though - once you've set these what are you going to do with them?

You might consider using an Ant script task instead for this sort of non-declarative processing.



来源:https://stackoverflow.com/questions/7308517/how-can-i-use-something-like-an-array-or-list-in-ant

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