tags:

views:

1284

answers:

2

How can I create an ant fileset which excludes certain directories based on the contents of the directory?

I use ant to create a distribution jar which has each localization in separate directories, some of which are incomplete and should not be released.

I would like to add something to the directory (for example a file named incomplete.flag) so that ant excludes the directory. Then I can delete the file when translation is complete, and include it in the build without modifying build.xml.

Given this directory structure:

proj
+ locale
  + de-DE
  + en-US
  + fr-FR

This fileset excludes all incompelte.flag files, but how can I exclude the entire directories that contain them?

  <fileset dir="${basedir}">
    <include name="locale/"/>
    <exclude name="locale/*/incomplete.flag">
  </fileset>

I can write an ant task if need be, but I'm hoping the fileset can handle this use case.

A: 

Here's an alternative, instead of adding an incomplete.flag file to every dir you want to exclude, generate a file that contains a listing of all the directories you want to exclude and then use the excludesfile attribute. Something like this:

<fileset dir="${basedir}" excludesfile="FileWithExcludedDirs.properties">
  <include name="locale/"/>
  <exclude name="locale/*/incomplete.flag">
</fileset>

Hope it helps.

Alonso
This crossed my mind, but I couldn't think of a way to create that excludesfile - any suggestions? I suspect that the same mechanism could just be used to create a fileset. Thoughts?
Chadwick
I see the problem. I think it depends on the criteria to include or exclude the files. I think you might be able to write a little script to generate the file, but you'll have to go outside ant.
Alonso
I just realized about ant selects. These can be used in filesets. Check it out http://ant.apache.org/manual/CoreTypes/selectors.html
Alonso
A: 
Hi guys,

This is possible by using "**" pattern as following.



<exclude name="maindir/**/incomplete.flag"/>

the above 'exclude' will exclude all directories completely which contains incomplete.flag file.

lakhdeep