开发者

Ant: use include and exclude together

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/**"/&g开发者_Go百科t;
    <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.


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.


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>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜