1

OK, this seems like it should be really simple. I'm using Apache Ant 1.8, and I have a target which does:

<delete file="output/program.tar.bz2"/>
<tar basedir="input" destfile="output/program.tar.bz2" compression="bzip2">
  <tarfileset dir="input">
    <include name="goodfolder1/**"/>
    <include name="goodfolder2/**"/>
    <exclude name="**/badfile"/>
    <exclude name="**/*.badext"/>
  </tarfileset>
</tar>

I want it to make a .tar.bz2 of input/goodfolder1 and input/goodfolder2, excluding files named "badfile", and excluding files with extension ".badext". It's giving me a .tar.bz2, but it's including badfile and *.badext -- the excludes seem to be ignored.

The order of include/exclude doesn't seem to make a difference. I tried wrapping the includes/excludes in a (the docs say it's implicit?), but it made no difference.

I'm sure there's something simple I'm missing, since the manual has a very similar example, though in a somewhat different context.

EDIT: It looks like it could be related to the dir="input" attribute: it's adding everything in "input", and then adding everything in the tarfileset to that. Files I want appear twice in the program.tar.bz2, but files that are excluded only appear once. But dir is mandatory, and I don't see how this is different from the examples in the manual.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Ken
  • 593
  • 1
  • 6
  • 8

2 Answers2

2

Ah, the <tarfileset> itself is what was causing my problem.

If I remove that, and put the includes/excludes directly inside the <tar>, it works fine.

Ken
  • 593
  • 1
  • 6
  • 8
0

I think you will need to use two <tarfileset> elements. The <include> and <exclude> elements are for files only. Not for directories. Example:

<tar basedir="input" destfile="output/program.tar.bz2" compression="bzip2"> <tarfileset dir="goodfolder1"> <exclude name="**/badfile"/> <exclude name="**/*.badext"/> </tarfileset> <tarfileset dir="goodfolder2"> <exclude name="**/badfile"/> <exclude name="**/*.badext"/> </tarfileset> </tar>

Robert Greathouse
  • 1,024
  • 1
  • 10
  • 18
  • `include` and `exclude` patterns can be used for either files or folders. You may be thinking of `includesfile` and `excludesfile`. – Mads Hansen Jan 07 '11 at 22:36