Ant: two questions about dirsets

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

  • Is a dirset really a set without a guaranteed order, or does it preserve the input order? I want to use ant: to contribute to the iteration over a set of directories and order, so if Ant dirset does not preserve the insertion order, what are my alternatives?
  • How to check if any catalog is included in the compass?
+6
source share
4 answers

[change]

If you look at the source of dirset, it looks like it uses java File.list() , whose, it says that there is no ordering. So you cannot count on it absolutely. However, before returning, it calls Arrays.sort(files); See line 1572.


According to the preservation order, I could not say that I would jeopardize that there is no guarantee, but usually the order of the file systems is preserved.

As for testing, I assume that you want to do the 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 circus, if you do nothing.

+3
source

There is not much information on dirset in the Ant documentation.

If you use patternset , there is no guarantee of order.

If you use include , listing individual directories rather than templates, dirset should keep order. Of course I would experience it.

Edited to add: if I am mistaken, you can write your own Ant custom task to preserve the order of the included directories.

+1
source

According to this page

dirset Adds a set of directories to the implicit build path. Note that directories will be added to the build path in a specific order, so if the order is significant, use a list of files instead!

Here is a link on how to use FileList

+1
source

No, he does not keep order.

The content of dirset is based on what its parent class provides through DirectoryScanner . This scanner approaches the file system and does not do this in any particular order.

It also uses File.list , which is a source of non-determinism of order:

There is no guarantee that name strings in the resulting array will be displayed in any particular order; they, in particular, are not guaranteed in alphabetical order.

0
source

Source: https://habr.com/ru/post/910833/


All Articles