0

I have a ant parameter with list of values as below.

releases=release1,release2

I use the below for loop to process the values.

<for list="${releases}" param="release">
  <sequential>
    <echo>Processing @{release}</echo>
  </sequential>
<for>

I want to do something like, I want to echo the below statement only when the @{release}=release2

<echo>Processing last release</echo>

I am not quite sure how to get the index of the list items or if it is even possible.

Thanks in advance, Balaji

Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
Balaji
  • 1,687
  • 2
  • 11
  • 10

1 Answers1

2

That's all? And, you're using Ant-Contrib tasks already. Take a look at the PropertyRegEx task. That's the Ant-Contrib task that will do exactly what you want:

<propertyregex property="last.release"
     input="${releases}"
     regexp=".*,(.*)"
     select="\1"/>

This will set ${last.release} to the last release in your string.

Be careful of strings that are null or don't match your regular expression! You can use the Ant-Contrib if task to test for that:

<propertyregex property="last.release"
     input="${releases}"
     regexp=".*,(.*)"
     select="\1"/>
<if>
    <isset property="last.release"/>
    <then>
        <echo>The last release is ${last.release}</echo>
    </then>
    <else>
        <fail>Oops! Something didn't work...</fail>
    </else>
</if>
David W.
  • 105,218
  • 39
  • 216
  • 337