ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rebhan, Gilbert" <Gilbert.Reb...@huk-coburg.de>
Subject RE: AW: Reversing a list
Date Wed, 05 Aug 2009 13:45:21 GMT
 
P.S. :

using $attributes.get('in').split(',') because i assumed
your list is given comma separated, f.e. like being set via

<property name="mylist" value="name1,name2,ant,forum,nabble"/>

Regards, Gilbert


-----Original Message-----
From: Rebhan, Gilbert 
Sent: Wednesday, August 05, 2009 3:42 PM
To: 'Ant Users List'
Subject: RE: AW: Reversing a list

 

-----Original Message-----
From: Raagu [mailto:rknilekani2005@gmail.com] 
Sent: Wednesday, August 05, 2009 3:17 PM
To: user@ant.apache.org
Subject: Re: AW: Reversing a list


/*

[..]

How can i access the the newlist here (outside <groovy> task)
I tried             ${list}
But it is giving old values .. which is set initially..
please do reply.

*/


using ruby as scripting language, but it's similar for any scripting
running with BSF, means simply use the ant api.
So for using your newlist outside your script task you have to set
a new property with its value for further processing in your ant script

example with ruby =

<scriptdef name="mylistutil" language="ruby">
  <attribute name="in"/>
  <attribute name="out"/>
  <attribute name="filter"/>
  if $attributes.get('filter').nil?
    $project.setProperty $attributes.get('out') ,
      $attributes.get('in').split(',').reverse.join(',').to_s
  else
    $project.setProperty $attributes.get('out') ,
      $attributes.get('in').split(',').
       reject!{|i| i =~ /#{$attributes.get('filter')}/}.reverse.join(',').to_s
   end
</scriptdef>


and then if filtering (filter attribute takes a regex) wanted just use scriptdef
with filter attribute, f.e. =

<mylistutil in="${mylist}" out="newlist" filter="2$"/>

filters all elements ending with 2 and gives newlist =
nabble,forum,ant,name1

<mylistutil in="${mylist}" out="newlist"/>

runs without filtering and gives newlist =
nabble,forum,ant,name2,name1


*** if you want to overwrite your property mylist, then use mylist in out attribute
and ${mylist} (which is immutable normally) will get overwritten, f.e.

<mylistutil in="${mylist}" out="mylist"/>


Regards, Gilbert


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message