In folder, src, I have a set of subfolders with java source code:

/a/A.java

/a/b/B.java

/a/b/c/C.java

I need a property with the following value:

src/a/A.java,src/a/b/B.java,src/a/b/c/C.java

I tried the following:

<pathconvert property="list-of-files">
  <globmapper from="*" to="src/*"/>
  <fileset dir=${src-folder}/>
</pathconvert>

but I end up with the following value on my property:

src/full/path/to/folder_a/a/A.java,src/full/path/to/folder_a/a/b/B.java,src/full/path/to/folder_a/a/b/c/C.java

How can I accomplish what I want? Any input is appreciated!

有帮助吗?

解决方案

You can use the map parameter of pathconvert for this.

First get the full path to your src dir by appending its path to the value of the basedir property. Then use that as the from attribute of your map.

<property name="src.dir" value="${basedir}${file.separator}${src-folder}"/>
<pathconvert property="list-of-files">
  <map from="${src.dir}" to="src"/>
  <fileset dir="${src-folder}"/>
</pathconvert>

其他提示

Just in case if someone needs to get relative file paths of resources and map them to URL paths accordingly, so it works both on Windows and *nix the solution is:

<pathconvert dirsep="/" pathsep=";" property="css.files.list">
    <map from="${basedir}/" to="" /><!-- This is the trick. Remove slash to make path absolute. -->
    <fileset dir="." includes="${src.dir}/**/*.css" />
</pathconvert>

Try either this one:

<pathconvert property="list-of-files">
  <globmapper from="*" to="src/*"/>
  <cutdirsmapper dirs="N"/>
  <fileset dir=${src-folder}/>
</pathconvert>

(here N - Number of directories to strip (must be a positive number))

or this: after piece of your code treat list-of-files through the

<mapper type="flatten"/>
<flattenmapper/>

Hope this help =)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top