I have a tree like this
path/a
path/b
path/c
path/d/da
path/d/db
path/d/dc
Now in my javac task i want to
path/
path/d/
path/d/db/
Like this:
path/a
path/b
path/c
path/d/db
I played with include/exclude and patternset but i couldn't achieve what i need. Is there a way to do this?
The <difference>
and <union>
set operations will be handy for what you need.
The following Ant script shows how to combine several <fileset>
elements into one:
<project name="ant-javac-include-and-exclude" default="run" basedir=".">
<target name="run">
<fileset id="all-files" dir="path">
<include name="**"/>
</fileset>
<fileset id="files-under-d" dir="path">
<include name="d/**"/>
</fileset>
<fileset id="files-under-d-db" dir="path">
<include name="d/db/**"/>
</fileset>
<!-- Matches all files under a, b, c -->
<difference id="all-files-NOT-under-d">
<fileset refid="all-files"/>
<fileset refid="files-under-d"/>
</difference>
<!-- Combine all files under a, b, c and under d/db -->
<union id="files-to-compile">
<difference refid="all-files-NOT-under-d"/>
<fileset refid="files-under-d-db"/>
</union>
<!-- Convert the absolute paths in "files-to-compile" to relative-->
<!-- paths. Also, "includes" of <javac> requires a comma-separated -->
<!-- list of files. -->
<pathconvert property="union-path" pathsep=",">
<union refid="files-to-compile"/>
<map from="${basedir}/" to=""/>
</pathconvert>
<javac
srcdir="."
includes="${union-path}"
includeantruntime="false"
/>
</target>
</project>
The above steps can be combined into the following:
<pathconvert property="union-path" pathsep=",">
<union>
<difference>
<fileset dir="path">
<include name="**"/>
</fileset>
<fileset dir="path">
<include name="d/**"/>
</fileset>
</difference>
<fileset dir="path">
<include name="d/db/**"/>
</fileset>
</union>
<map from="${basedir}/" to=""/>
</pathconvert>
<javac
srcdir="."
includes="${union-path}"
includeantruntime="false"
/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.