I'm trying to discard @WebService annotated classes in my Ant build using not and contains keywords. However, it isn't working and still includes classes annotated with @WebService. Here is the task used to copy sources to the working build directory:
<copy todir="${compile.dir}">
<fileset dir="${src.dir}">
<include name="**/*" />
<exclude name="**/*.class" />
<exclude name="log4j.properties" />
<exclude name="log4j.properties.*" />
<exclude name="log4j.xml" />
<exclude name="log4j.xml.*" />
<exclude name="*.jocl" />
<not>
<contains text="@WebService(" casesensitive="true" />
</not>
</fileset>
</copy>
However, it seems like the not section is ignored, and those classes are still copied. Why isn't this working? Is the syntax wrong? Also, how do I add a condition, so that the restriction concerns only .java files?
I'm using Apache Ant(TM) version 1.9.6 compiled on July 8 2015.
(Perhaps this will guide you, it works for me, but I'm not quite sure I've fully understood your requirement.)
Try this fileset:
A few explanatory comments:
There's no need to specify
<include name="**/*" />this is implicit in a fileset.When you include a nested selector inside a fileset (like
<not>...<contains>...</not>) this is implicitly ANDed with the patternsets (which are implicitly ORed with each other). See<fileset>docs:The upshot of this is that you need to use an
<or>selector container with two negative selectors. In other words, "select the file if it's not a java file OR it doesn't match the text string".The selector container could equivalently be written this way if you prefer: