How do I make a fileset from a comma-separated list of directories in Ant?

限于喜欢 提交于 2019-12-02 01:12:55

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:

<multirootfileset basedirs="${directories}" includes="**/*">

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}" />

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

Something like this should work:

<dirset includes="${directories}"/>

Yes, dirset isn't fileset. However, it may be enough, or else you can probably use a for or foreach 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 ...

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!