如何在 Ant 中从逗号分隔的目录列表创建文件集?
在 Ant 目标中,我获得一个属性,其中包含要包含在进一步操作(复制、过滤等)中的目录列表。它看起来像这样:
directories=dir1, dir2, dir3
我需要一种方法将此列表转换为文件集或模式集,以选择这些目录中的所有文件。
我知道我可以使用脚本生成模式字符串,然后在“包含”或“排除”中使用它,但是有没有办法避免脚本?
In an Ant target I get a property, containing the list of directories to be included in further action (copying, filtering, etc.). It looks like this:
directories=dir1, dir2, dir3
I need a way to convert this list to a fileset or patternset that selects all the files in these directories.
I know I can use a script to generate pattern strings and then use it in the "include" or "exclude", but is there are a way to avoid scripts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请注意,从 Ant 1.9.4 开始,有一个新的构造 提供了该功能,即使目录不是兄弟姐妹:
Note that as of Ant 1.9.4, there is a new construct <multirootfileset> that provides that functionality, even if the dirs are not siblings:
如何使用 antcontrib
propertyregex
任务将逗号分隔的列表转换为适合文件集的通配符?现在我们有了:
可以与进一步的后缀通配符一起使用来获取完整的文件集:(
繁琐的
${wildcard}
是为了确保 unix 和 windows 文件系统之间的可移植性,您可以使用 < code>/**/* 如果你是纯unix。)How about using the antcontrib
propertyregex
task to convert the comma-separated list into wildcards suitable for a fileset?At this point we now have:
That can be used with a further suffixed wildcard to get the full fileset:
(The fiddly
${wildcard}
is to ensure portability between unix and windows filesystems, you could use/**/*
if you're pure unix.)像这样的东西应该可以工作:
是的,
dirset
不是fileset
。但是,这可能就足够了,否则您可以使用 ant-contrib 中的for
或foreach
来迭代目标中的目录。您也许还可以基于 dirset 定义一个 ResourceCollection。了解预期的“进一步行动”可能会有所帮助。不过,感觉这工作量太大了……
Something like this should work:
Yes,
dirset
isn'tfileset
. However, it may be enough, or else you can probably use afor
orforeach
from ant-contrib to iterate over the directories in your target. You might also be able to define a ResourceCollection based around the dirset. It might help to know what the "further action" is expected to be.However, this feels like too much work ...