Pathconvert with relative file names

In the src folder, 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 ultimately I have the following meaning:

 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!

+6
source share
3 answers

You can use the map pathconvert parameter for this .

First enter the full path to your src director, adding its path to the value of the basedir property. Then use this 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> 
+8
source

Just in case, if someone needs to get relative paths to resource files and map them to URLs accordingly, that’s why it works on both Windows and the * nix solution:

 <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> 
+2
source

Try either this one:

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

(here N is the number of directories for the strip (must be a positive number))

or this: after part of your code processes the list of files through

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

Hope this help =)

0
source

Source: https://habr.com/ru/post/902549/


All Articles