如何在Ant中使用类似数组或列表的内容? [英] How can I use something like an array or list in Ant?
问题描述
我在Ant脚本中有一个字符串列表(例如 piyush,kumar),我想为其分配 piyush
到var1,例如 < var name = var1 value = piyush />
和 kumar
到var2,例如< var name = var2 value = kumar />
。
到目前为止,我正在使用如下所示的构建文件:
<?xml version = 1.0?>
<项目名称= cutter默认= cutter>
< target name = cutter>
< for list = piyush,kumar param = letter>
< sequential>
< echo> var1 @ {letter}< / echo>
< / sequential>
< / for>
< / target>
< / project>
我不确定如何进行此操作-有任何建议吗?
< var name = index value = 1 />
< for list = piyush,kumar param = letter>
< sequential>
<属性名称= var $ {index} value = @ {letter} />
<数学结果=索引操作数1 = $ {索引}操作= +操作数2 = 1数据类型= int />
< / sequential>
< / for>
< echoproperties prefix = var />
输出:
[echoproperties] var1 = piyush
[echoproperties] var2 = kumar
但是,这全都是非Ant的-设置完这些后,您将如何处理它们?
您可能会考虑使用Ant 脚本
任务,而不是这种非声明性处理。 / p>
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?
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.
这篇关于如何在Ant中使用类似数组或列表的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!