Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant: Two questions about dirsets

Tags:

java

apache

ant

I have two questions about the dirset type in Apache Ant.

  • Is a dirset really a set, with no order guaranteed, or does it preserves the input order? I want to use ant:contrib to iterate over a set of directories and order matters, so if Ant's dirset does not preserve insertion-order, what alternatives do I have?
  • How can I test if a certain dir is included within a dirset?
like image 704
Jan Gräfen Avatar asked Mar 15 '12 17:03

Jan Gräfen


1 Answers

[Edit]

If you look at the dirset source It looks like it uses java File.list(), whose documentation states that there is no gauranteed order. So no you can't count on that absolutely. However, before returning it calls Arrays.sort(files); See Line 1572.


As per preserving order I couldn't say, I would hazard that there is no guarantee but that it usually just happens to preserve the file systems order.

As to testing, I presume you want, do action if this file exists or something similar, using ant contrib,

<for param="directory">
<dirset dir="dirIneedtoexist">
</dirset>
<sequential>
     <!-- Stuff to do if it exists. -->          
</sequential>
</for>

If there is nothing in the dirset if won't do anything.

like image 180
Andrew Avatar answered Sep 27 '22 23:09

Andrew