tags:

views:

31

answers:

1

I have a Path collection in Ant, and I need to loop through it in reverse order. I use AntContrib's for loop, like this:

<for param="foo">
   <path refid="bar" />
   <sequential> ... </sequantial>
</for>

I need to loop through the elements of bar in reverse order. I can't change how the Path got created in the first place. I could always write a custom Ant task in Java, but my build currently runs without any custom tasks, and I'd rather avoid that for such a seemingly simple task.

Would Ant JavaScript be able to do this ? (and if so, how?)

Any help would be appreciated!

+1  A: 

I think a "pure ant" solution might be a bit contorted, but you didn't exclude the possibility of using a script task.

This will set a property baz that contains the reverse of the path with reference id bar.

<script language="javascript"><![CDATA[
    project.setProperty( "baz", project.getReference( "bar" )
        .toString().split( ":" ).reverse( ).join( ":" ) );
]]></script>

Hopefully can be adapted to your precise needs.

martin clayton
Worked like a charm! All I had to do is convert my for loop from iterating over a path, to iterating over a delimited list in the resulting property. Thanks!
mycroft