如何在 Ant 中使用数组或列表之类的东西? [英] How can I use something like an array or list in Ant?

查看:31
本文介绍了如何在 Ant 中使用数组或列表之类的东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Ant 脚本中有一个字符串列表(例如piyush,kumar"),我想将 piyush 分配给 var1,例如 <var name="var1" value="piyush"/>kumar 到 var2 就像 <var name="var2" value="kumar"/>.

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?

推荐答案

这是一个使用 ant-contrib 的例子 variablemath 任务:

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" />

输出:

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

这一切都非常不像 Ant——一旦你设置了这些,你将如何处理它们?

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

您可能会考虑使用 Ant script 任务 来代替此类非声明性处理.

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

这篇关于如何在 Ant 中使用数组或列表之类的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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