ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aaron Knauf <Aar...@geniesystems.com>
Subject includesfile diff for MatchingTask.java
Date Wed, 24 May 2000 04:10:59 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

This is a diff for MatchingTask.java which adds two attributes: 
'includesfile' and 'excludesfile'.  These attributes specify the name
of a file, which contains a list of path/filename matching patterns
to be added to the includes or excludes lists.  Each line in the list
is treated as a NameEntry, which means the each line can contain a
comma separated list of matching patterns.
 
I also changed createInclude() and createExclude() to use the more
generic addPatternToList() to do their work.  (They still fullfill
the same contract as before.)
 
Some processing was required in the init() method, to do the actual
reading of the pattern files.  This means that any subclasses of
MatchingTask that use the init() method MUST call super.init().  No
tasks currently in CVS fall into this category.
 
I currently use this feature to specify the class files to include in
my jar archives.  Doesn't guarantee that the file actually exists,
but does the trick otherwise.
 
Cheers
 
ADK
 
Index: ./src/main/org/apache/tools/ant/taskdefs/MatchingTask.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Mat
chingTask.java,v
retrieving revision 1.5
diff -r1.5 MatchingTask.java
76a77,78
>     private String includesfile = null;
>     private String excludesfile = null;
78a81,125
>      *  Overrides Task.init().  Provides required
> pre-<code>execute()</code> 
>      *  initialization.
>      *
>      *  At present, this just adds the patterns in any includes or
> excludes files 
>      *  to the appropriate list.
>      *
>      *  XXX - The use of this method here requires anyone
> overriding it in a 
>      *  XXX - subclass to call <code>super.init()</code>.
>      */
>     public void init() throws BuildException {
>       // Add the contents of includesfile and excludesfile to the
> includes and 
>       // excludes lists, respectively.
>       if (includesfile != null) readPatterns(includesfile,
> includeList); 
>       if (excludesfile != null) readPatterns(excludesfile,
> excludeList); 
>     }
>     
>     /**
>      *  Reads path matching patterns from a file and adds them to
> the includes 
>      *  or excludes list (as appropriate).
>      */
>     private void readPatterns(String patternfile, Vector
> patternlist) throws BuildException { 
>       try {
>         // Get a FileReader
>         BufferedReader patternReader = new BufferedReader(new
> FileReader(patternfile)); 
>        
>         // Create one NameEntry in the appropriate pattern list for
> each line 
>         // in the file.
>         String line = patternReader.readLine();
>         while (line != null) {
>           if (line.length() > 0) {
>             addPatternToList(patternlist).setName(line);
>           }
>           line = patternReader.readLine();
>         }
>       } catch(FileNotFoundException fne) {
>           throw new BuildException("Couldn't find file: " +
> patternfile); 
>       } catch(IOException ioe)  {
>           throw new BuildException("An error occured while reading
> from pattern file: " + patternfile); 
>       } catch(NullPointerException npe) {
>         // An npe here is almost certainly a null String given as
> the filename, 
>         // which we can safely ignore.
>       }
>     }
>     
>     /**
105a153,157
>     private NameEntry addPatternToList(Vector list) {
>       NameEntry result = new NameEntry();
>       list.addElement(result);
>       return result;
>     }
110,112c162
<         NameEntry result = new NameEntry();
<         includeList.addElement(result);
<         return result;
- ---
>         return addPatternToList(includeList);
119,121c169
<         NameEntry result = new NameEntry();
<         excludeList.addElement(result);
<         return result;
- ---
>         return addPatternToList(excludeList);
134a183,194
>     
>     /**
>      * Sets the name of the file containing the includes patterns.
>      *
>      * @param includesfile A string containing the filename to
> fetch the include 
>      *  patterns from.
>      */
>     public void setIncludesfile(String includesfile) {
>       if (includesfile != null && includesfile.length() > 0) {
>         this.includesfile = includesfile;        
>       }
>     }
170a231,242
>     }
>     
>     /**
>      * Sets the name of the file containing excludes patterns.
>      *
>      * @param excludesfile A string containing the filename to
> fetch the exclude 
>      *  patterns from.
>      */
>     public void setExcludesfile(String excludesfile) {
>       if (excludesfile != null && excludesfile.length() > 0) {
>         this.excludesfile = excludesfile;        
>       }


-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.2 for non-commercial use <http://www.pgp.com>

iQA/AwUBOSquVdDEY7hlrDuMEQJ+jACg+Ozshy4dLneP66YrMnYl8dQ1uI0AoIpH
EBL7QOhd6pveaIMTCVTx9Dyy
=Wl6Q
-----END PGP SIGNATURE-----

Mime
View raw message