ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruce Atherton <br...@callenish.com>
Subject Re: Dirset selectors?
Date Wed, 29 Oct 2003 07:06:25 GMT
Adam Mlodzinski wrote:
> 
> Unfortunately, my original question (how do you get a <dirset> of
> directories based on the presence of a file (or other directory) within
> that directory?) still stands.

I'm afraid the answer is that you need a new selector, a combination of 
a type selector and a filename selector. It should be fairly 
straightforward, though. A simple version (assuming you are using the 
new custom mechanism in 1.6 Beta) would look something like this:

   <fileset dir="src">
     <parentdir file="*.java" />
   </fileset>

and the selector code something like:

     public boolean isSelected(File basedir, String filename,
             File file) {
         validate();
         if (file.isDirectory()) {
             String[] filelist = file.list();
             for (int i = 0; i < filelist.length; i++) {
                 if (SelectorUtils.match(filelist[i], targetfile)) {
                     return true;
                 }
             }
         }
         return false;
     }

I haven't compiled this but it should give you an idea. If you wanted to 
play around with patterns that contained "**" (so that you get ancestor 
directories rather than just parents) you would substitute "match()" 
with "matchPath()".

See 
http://ant.apache.org/manual-1.6beta/CoreTypes/selectors-program.html 
and 
http://ant.apache.org/manual-1.6beta/CoreTypes/custom-programming.html#customselectors 
for more instructions on how to write a custom selector and use it in 
your build scripts.



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message