10
votes

If I have a fileset like this:

<fileset dir=".">
  <exclude name="classes/*"/>
  <include name="**/zar.class"/>   
</fileset>

The exclude takes precedence over the include and I don't end up with any classes. [since for this hypothetical example, zar.class is in the classes dir] I would like to include the zar file, even though it is in the classes dir.

I banged my head against this one for a while, reading about selectors, patternsets, filesets, trying to combine filesets, etc. but could not get it working.

Anyone know how to do this?

3

3 Answers

4
votes

Why do you need the exclude element ?

<fileset dir=".">
  <include name="**/zar.class"/>   
</fileset>

should give you the exact set of files you are after: zar.class, and none of the other .class files in classes/.


Just put this in community wiki mode, because I am not sure, on second thought, that it is actually what you are after:
you may want everything, including classes/.../zar.class, except classes/....

My solution would only give you zar.class.

Please leave a comment: if this is not a good solution, I will remove it.

2
votes

I'm not sure exactly what you want but I think you were on the right track looking at pattersets: How about:

<patternset id="a">
  <exclude name="classes/*"/>
</patternset>

<patternset id="b">
  <include name="**/zar.class"/>  
</patternset>

<fileset dir=".">
  <patternset refid="a" />
  <patternset refid="b" />
</fileset>
2
votes

Which version of Ant was used in the original question?

With Ant 1.8.2, the stanza does produce the desired result!?

<fileset dir="." id="some.fileset">
    <exclude name="build/classes/*" />
    <include name="**/A.class" />
</fileset>

<target name="test">
    <pathconvert pathsep="${line.separator}" property="listed.fileset" refid="some.fileset"/>
    <echo message="${listed.fileset}" />
</target>

Path and name slightly different, but this does show A.class, and does not show B.class, which is right next to it.