Pathconvert with relative file names

Liz picture Liz · Nov 28, 2011 · Viewed 10.9k times · Source

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!

Answer

sudocode picture sudocode · Nov 28, 2011

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>