Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 625
Piyush Avatar asked Feb 02 '23 14:02

Piyush


1 Answers

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.

like image 53
martin clayton Avatar answered Feb 12 '23 23:02

martin clayton