I have two questions about the dirset type in Apache Ant.
[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.
There's not much in the Ant documentation about dirset .
If you use patternset
, there's no guarantee of order.
If you use include
, listing individual directories rather than patterns, dirset
should preserve the order. I'd test this though, to be sure.
Edited to add: In the event that I'm wrong, you can write your own Ant custom task to preserve the order of the include directories.
No it does not preserve order.
A dirset's contents are based on what its parent class exposes via a DirectoryScanner
. That scanner walks the file system and does not do so in any particular order.
It also uses File.list
which is a source of order non-determinism:
There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.