How can I exclude files from the reference path in Ant?

In the project, we have several source paths, so we defined a reference path for them:

<path id="de.his.path.srcpath"> <pathelement path="${de.his.dir.src.qis.java}"/> <pathelement path="${de.his.dir.src.h1.java}"/> ... </path> 

Using help works fine in the <javac> tag:

 <src refid="de.his.path.srcpath" /> 

In the next step, we need to copy files other than java to the pathpath folder:

 <copy todir="${de.his.dir.bin.classes}" overwrite="true"> <fileset refid="de.his.path.srcpath"> <exclude name="**/*.java" /> </fileset> </copy> 

Unfortunately, this does not work because the "refid" and nested elements may not mix.

Is there a way to get a collection of all non-java files in the source path without copying the list of source paths into separate file sets?

+6
ant
source share
1 answer

Here is an option. First, use the pathconvert task to create a template suitable for creating a set of files:

 <pathconvert pathsep="/**/*," refid="de.his.path.srcpath" property="my_fileset_pattern"> <filtermapper> <replacestring from="${basedir}/" to="" /> </filtermapper> </pathconvert> 

Then make a set of files from all the files on the paths except for java sources. Note that the final wildcard /**/* needed to convert the path contains only the wildcards in the list, and not the one you need at the end:

 <fileset dir="." id="my_fileset" includes="${my_fileset_pattern}/**/*" > <exclude name="**/*.java" /> </fileset> 

Then your copy task:

 <copy todir="${de.his.dir.bin.classes}" overwrite="true" > <fileset refid="my_fileset" /> </copy> 

For portability, instead of hard coding, the unix /**/* wildcard you can use something like:

 <property name="wildcard" value="${file.separator}**${file.separator}*" /> 
+3
source share

All Articles