Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pathconvert with relative file names

Tags:

ant

mapper

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!

like image 943
Liz Avatar asked Nov 28 '11 12:11

Liz


2 Answers

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>
like image 138
sudocode Avatar answered Nov 03 '22 05:11

sudocode


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>
like image 26
igor Avatar answered Nov 03 '22 05:11

igor