10

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?

martin clayton
  • 76,436
  • 32
  • 213
  • 198
user41762
  • 661
  • 2
  • 8
  • 9

3 Answers3

5

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
2

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>
Brian Fisher
  • 23,519
  • 15
  • 78
  • 82
2

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.

mgaert
  • 2,338
  • 21
  • 27