Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ant

In a 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 the reference works fine in the <javac> tag:

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

In the next step, we have to copy non-java files to the classpath 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 "refid" and nested elements may not be mixed.

Is there a way I can get a set of all non-java files in my source path without copying the list of source paths into individual filesets?

like image 209
Hendrik Brummermann Avatar asked Oct 01 '10 13:10

Hendrik Brummermann


1 Answers

Here's an option. First, use the pathconvert task to make a pattern suitable for generating a fileset:

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

Next make the fileset from all the files in the paths, except the java sources. Note the trailing wildcard /**/* needed as pathconvert only does the wildcards within the list, not the one needed at the end:

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

Then your copy task would be:

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

For portability, instead of hard-coding the unix wildcard /**/* you might consider using something like:

<property name="wildcard" value="${file.separator}**${file.separator}*" />
like image 87
martin clayton Avatar answered Sep 23 '22 20:09

martin clayton