简体   繁体   English

Ant:关于dirsets的两个问题

[英]Ant: Two questions about dirsets

I have two questions about the dirset type in Apache Ant. 我有两个关于Apache Ant中dirset类型的问题。

  • Is a dirset really a set, with no order guaranteed, or does it preserves the input order? dirset真的是一套,没有保证订单,还是保留了输入订单? 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? 我想使用ant:contrib来迭代一组目录和命令事项,所以如果Ant的dirset不保留插入顺序,我还有什么替代方案?
  • How can I test if a certain dir is included within a dirset? 如何测试dirset中是否包含某个dir?

[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. 如果你看看dirset 看起来它使用java File.list() ,其文档声明没有gauranteed订单。 So no you can't count on that absolutely. 所以,你绝对不能指望这一点。 However, before returning it calls Arrays.sort(files); 但是,在返回之前调用Arrays.sort(files); See Line 1572. 见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, 至于测试,我认为你想要,如果这个文件存在或类似的东西,使用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. 如果dirset中没有任何东西,如果不做任何事情。

According to this page 根据这个页面

dirset Adds a directory set to the implicit build path. dirset将目录集添加到隐式构建路径。 Note that the directories will be added to the build path in no particular order, so if order is significant, one should use a file list instead! 请注意,目录将以特定顺序添加到构建路径中,因此如果顺序很重要,则应使用文件列表!

Here's link on how to use FileList 这是关于如何使用FileList的链接

There's not much in the Ant documentation about dirset . 关于dirset的Ant文档中没有太多内容。

If you use patternset , there's no guarantee of order. 如果您使用patternset ,则无法保证订单。

If you use include , listing individual directories rather than patterns, dirset should preserve the order. 如果使用include ,列出单个目录而不是模式, dirset应保留顺序。 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. 编辑添加:如果我错了,您可以编写自己的Ant自定义任务以保留包含目录的顺序。

No it does not preserve order. 不,它不会保留秩序。

A dirset's contents are based on what its parent class exposes via a DirectoryScanner . dirset的内容基于其父类通过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: 它还使用File.list ,它是订单非确定性的来源:

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. 特别是,它们不保证按字母顺序出现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM