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!
I think a "pure Ant" solution might be a bit contorted, but you could use a script task as you suggest.
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.
Create a variable ("var" type in Ant Contrib) to store the path elements in the reverse order.
Then, use a for loop with your path as a nested path, use "equals" in a condition to check whether your variable is empty or not.
After that, if it is, just copy the value of the for loop parameter into your variable, otherwise copy the value of the for loop parameter into your variable followed by the delimiter and the value of variable (i.e make a concatenation).
Finally, you can just use the created variable in a for loop by using the "list" attribute and the "delimiter" attribute.
You can see what I mean in my own source code here.
精彩评论