我如何从一个逗号分隔的蚂蚁目录列表文件集? [英] How do I make a fileset from a comma-separated list of directories in Ant?

查看:135
本文介绍了我如何从一个逗号分隔的蚂蚁目录列表文件集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ant目标,我得到一个属性,包含的目录列表将包含在采取进一步行动(复制,过滤等)。它看起来是这样的:

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

我需要一种方法来此列表转换为集或patternset一个选择全部在这些目录中的文件。

我知道我可以使用脚本生成模式字符串,然后在使用它包含或排除,但也有以避免脚本的方法?

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?

推荐答案

如何使用antcontrib的 propertyregex ​​ 任务的逗号分隔的列表转换为适合文件集通配符?

How about using the antcontrib propertyregex task to convert the comma-separated list into wildcards suitable for a fileset?

<property name="directories" value="dir1, dir2, dir3" />

<property name="wildcard" value="${file.separator}**${file.separator}*" />
<propertyregex property="my_pattern"
               input="${directories}" 
               regexp=", " 
               replace="${wildcard}," />

在这一点上,我们现在有:

At this point we now have:

my_pattern=dir1/**/*,dir2/**/*,dir3

这可以进一步后缀的通配符被用来获取完整的文件集:

That can be used with a further suffixed wildcard to get the full fileset:

<fileset dir="." id="my_fileset" includes="${my_pattern}${wildcard}" />

(将繁琐的 $ {通配符} 是要确保UNIX和Windows文件系统之间的可移植性,可以使用 / ** / * 如果你是纯UNIX)。

(The fiddly ${wildcard} is to ensure portability between unix and windows filesystems, you could use /**/* if you're pure unix.)

这篇关于我如何从一个逗号分隔的蚂蚁目录列表文件集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆