Ant: Convert comma-delimited list of relative paths to path

拈花ヽ惹草 提交于 2020-01-05 12:30:38

问题


I have a comma-delimited list of directories:

foo,bar,baz,qux

I want to convert it to an Ant path containing (something like) the following:

${basedir}/build/foo/classes
${basedir}/build/bar/classes
${basedir}/build/baz/classes
${basedir}/build/qux/classes

It seems like there should be a way to do this with <pathconvert>, but it's not obvious to me what it would be. Suggestions?


回答1:


You might be able to use a dirset to hold your list of directories, then feed that into pathconvert. Something like:

<property name="dirs" value="foo,bar,baz,qux" />
<dirset id="dir_list" dir="${basedir}" includes="${dirs}" />

<pathconvert refid="dir_list" property="dirs_prop">
    <regexpmapper from="(${basedir})/(.*)" to="\1/build/\2/classes" />
</pathconvert>

Then the property ${dirs_prop} will hold the path you want... or almost. The problem with dirset is that the order of directories is not defined. To retain the order of the original list, use a filelist in place of the dirlist:

<filelist id="dir_list" dir="${basedir}" files="${dirs}" />


来源:https://stackoverflow.com/questions/9025602/ant-convert-comma-delimited-list-of-relative-paths-to-path

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