问题
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