Pathconvert with relative file names
Asked Answered
S

3

6

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!

Sioux answered 28/11, 2011 at 12:32 Comment(0)
A
8

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>
Appel answered 28/11, 2011 at 14:19 Comment(1)
You may also obtain the absolute path with location instead of value: <property name="src.dir" location="${src-folder}" />Sextans
C
2

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>
Cycad answered 3/8, 2012 at 14:52 Comment(0)
S
0

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 =)

Sapowith answered 28/11, 2011 at 13:29 Comment(1)
Unfortunately none of these works. I cannot use the first alternative because the nuber "N" is not constant in my builds. And the second alternative strips all folders and leave my with just a list of Java files. So I end up with: A.java,B.java,C.java which is not what I want.Sioux

© 2022 - 2024 — McMap. All rights reserved.