Ant: Convert comma-delimited list of relative path

2019-08-03 08:08发布

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?

标签: ant
1条回答
Melony?
2楼-- · 2019-08-03 08:41

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}" />
查看更多
登录 后发表回答