Search code examples
ant

Ant Zip Task, many excludefiles in subdirectories


I'm looking to use Ant to build a project, everything into a .zip file.

Ant's Zip task has an excludefiles attribute - but I was looking for functionality more similar to the .gitignore file in that it collects more excludes as it is copying from subdirectories.

For example, if I had the following structure

toBuild
|--a
|  |--.ignores
|  |--File1.txt
|  |--File2.txt
|  +--File3.txt
|--b
|  |--.ignores
|  |--File1.txt
|  |--File2.txt
|  +--File3.txt
|--.ignores
|--File1.txt
|--File2.txt
+--File3.txt

With:

  • a/.ignores = File1.txt
  • b/.ignores = File2.txt
  • .ignores = File3.txt

Then the output would be

builtZip
|--a
|  +--File2.txt
|--b
|  +--File1.txt
|--File1.txt
+--File2.txt

What would be the best approach to something similar to this?


Solution

  • Sounds like a good use case for custom selectors:

    http://ant.apache.org/manual/Types/selectors.html#customselect

    You'll probably need to write your own selector as explained here:

    http://ant.apache.org/manual/Types/selectors-program.html