You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2001/08/01 11:08:56 UTC

cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/types FileSetTest.java PatternSetTest.java

bodewig     01/08/01 02:08:56

  Modified:    .        WHATSNEW
               docs/manual dirtasks.html
               docs/manual/CoreTypes fileset.html patternset.html
               src/main/org/apache/tools/ant/taskdefs MatchingTask.java
               src/main/org/apache/tools/ant/types FileSet.java
                        PatternSet.java
               src/testcases/org/apache/tools/ant/types FileSetTest.java
                        PatternSetTest.java
  Log:
  Add <includesfile>/<excludesfile> elements to <patternset> and friends,
  thus allowing for more than one file of each type.
  
  Submitted by:	Mark Womack <mw...@bevocal.com>
  
  Add pointer to "Directory Based Tasks" in the documentation of
  patternsets where patterns are actually defined.
  
  Revision  Changes    Path
  1.135     +4 -0      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.134
  retrieving revision 1.135
  diff -u -r1.134 -r1.135
  --- WHATSNEW	2001/07/27 09:14:58	1.134
  +++ WHATSNEW	2001/08/01 09:08:55	1.135
  @@ -131,6 +131,10 @@
     defaults to true.  If set to false, files that are newer than the
     files in the archive will not be replaced.
   
  +* <patternset> and <fileset> now support nested <in/excludesfile>
  +  elements - using these you can have more than one in/excludes file
  +  per <patternset>. 
  +
   Fixed bugs:
   -----------
   
  
  
  
  1.7       +1 -1      jakarta-ant/docs/manual/dirtasks.html
  
  Index: dirtasks.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/manual/dirtasks.html,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- dirtasks.html	2001/07/20 14:01:48	1.6
  +++ dirtasks.html	2001/08/01 09:08:55	1.7
  @@ -28,7 +28,7 @@
   nested elements and via external files. Each line of the external file
   is taken as a pattern that is added to the list of include or exclude 
   patterns.</p>
  -<h3>Patterns</h3>
  +<h3><a name="patterns">Patterns</a></h3>
   <p>As described earlier, patterns are used for the inclusion and exclusion.
   These patterns look very much like the patterns used in DOS and UNIX:</p>
   <p>'*' matches zero or more characters, '?' matches one character.</p>
  
  
  
  1.4       +6 -5      jakarta-ant/docs/manual/CoreTypes/fileset.html
  
  Index: fileset.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTypes/fileset.html,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- fileset.html	2001/03/09 08:54:35	1.3
  +++ fileset.html	2001/08/01 09:08:55	1.4
  @@ -15,11 +15,12 @@
   that support this feature or at the same level as <code>target</code>
   - i.e., as children of <code>project</code>.</p>
   <p>PatternSets can be specified as nested
  -<code>&lt;patternset&gt;</code> 
  -elements. In addition, FileSet holds an implicit PatternSet and
  -supports the nested <code>&lt;include&gt;</code> and
  -<code>&lt;exclude&gt;</code> elements of PatternSet directly, as well
  -as PatternSet's attributes.</p>
  +<code>&lt;patternset&gt;</code> elements. In addition, FileSet holds
  +an implicit PatternSet and supports the nested
  +<code>&lt;include&gt;</code>, <code>&lt;includesfile&gt;</code>,
  +<code>&lt;exclude&gt;</code> and <code>&lt;excludesfile&gt;</code>
  +elements of PatternSet directly, as well as PatternSet's
  +attributes.</p>
   <table border="1" cellpadding="2" cellspacing="0">
     <tr>
       <td valign="top"><b>Attribute</b></td>
  
  
  
  1.3       +46 -15    jakarta-ant/docs/manual/CoreTypes/patternset.html
  
  Index: patternset.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTypes/patternset.html,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- patternset.html	2001/02/13 12:31:54	1.2
  +++ patternset.html	2001/08/01 09:08:55	1.3
  @@ -8,15 +8,17 @@
   <body>
   
   <h2><a name="patternset">PatternSet</a></h2>
  -<p>Patterns can be grouped to sets and later be referenced by their
  -<code>id</code>
  -attribute. They are defined via a <code>patternset</code> element,
  -which can appear nested into a <a href="fileset.html">FileSet</a> or a
  -directory-based task that constitutes an implicit FileSet. In addition,
  -<code>patternset</code>s can be defined at the same level as
  -<code>target</code> &#151; i.e., as children of <code>project</code>.</p>
  -<p>Patterns can be specified by nested <code>&lt;include&gt;</code> or
  -<code>&lt;exclude&gt;</code> elements or the following attributes.</p>
  +<p><a href="../dirtasks.html#patterns">Patterns</a> can be grouped to
  +sets and later be referenced by their <code>id</code> attribute. They
  +are defined via a <code>patternset</code> element, which can appear
  +nested into a <a href="fileset.html">FileSet</a> or a directory-based
  +task that constitutes an implicit FileSet. In addition,
  +<code>patternset</code>s can be defined as a stand alone element at
  +the same level as <code>target</code> &#151; i.e., as children of
  +<code>project</code> as well as as children of
  +<code>target</code>.</p> <p>Patterns can be specified by nested
  +<code>&lt;include&gt;</code>, or <code>&lt;exclude&gt;</code> elements
  +or the following attributes.</p>
   <table border="1" cellpadding="2" cellspacing="0">
     <tr>
       <td valign="top"><b>Attribute</b></td>
  @@ -30,7 +32,8 @@
     <tr>
       <td valign="top">includesfile</td>
       <td valign="top">the name of a file; each line of this file is
  -      taken to be an include pattern.</td>
  +      taken to be an include pattern. You can specify more than one
  +      include file by using a nested includesfile elements.</td>
     </tr>
     <tr>
       <td valign="top">excludes</td>
  @@ -40,7 +43,8 @@
     <tr>
       <td valign="top">excludesfile</td>
       <td valign="top">the name of a file; each line of this file is
  -      taken to be an exclude pattern.</td>
  +      taken to be an exclude pattern. You can specify more than one
  +      exclude file by using a nested excludesfile elements.</td>
     </tr>
   </table>
   
  @@ -61,9 +65,9 @@
   multiple elements separated by commas or spaces, the nested
   &lt;include&gt; and &lt;exclude&gt; elements expect their name
   attribute to hold a single pattern.</p>
  -<p>The nested &lt;include&gt; and &lt;exclude&gt; elements allow you to use
  -if and unless arguments to specify that the element should only be used if a 
  -property is set, or that it should be used only if a property is not set.</p>
  +<p>The nested elements allow you to use if and unless arguments to
  +specify that the element should only be used if a property is set, or
  +that it should be used only if a property is not set.</p>
   <p>For example</p>
   <blockquote><pre>
   &lt;patternset id=&quot;sources&quot; &gt;
  @@ -74,7 +78,34 @@
   </pre></blockquote>
   <p>will only include the files in the sub-directory <em>prof</em> if the property
   <em>professional</em> is set to some value.</p>
  -
  +<p>If you want to list the files to include or exclude external to
  +your build file, you should use the includesfile/excludesfile
  +attributes or elements.  Using the attribute, you can only specify a
  +single file of each type, while the nested elements can be specified
  +more than once - the nested elements also support if/unless attributes
  +you can use to test the existance of a property. For example:</p>
  +<blockquote><pre>
  +&lt;patternset includesfile=&quot;some-file&quot; /&gt;
  +</pre></blockquote>
  +<p>and</p>
  +<blockquote><pre>
  +&lt;patternset&gt;
  +  &lt;includesfile name=&quot;some-file&quot; /&gt; 
  +&lt;patternset/&gt;
  +</pre></blockquote>
  +<p>are identical.  The include patterns will be read from the file
  +<code>some-file</code>, one pattern per line.</p>
  +<blockquote><pre>
  +&lt;patternset&gt;
  +  &lt;includesfile name=&quot;some-file&quot; /&gt; 
  +  &lt;includesfile name=&quot;${some-other-file}&quot; 
  +                if=&quot;some-other-file&quot;
  +  /&gt; 
  +&lt;patternset/&gt;
  +</pre></blockquote>
  +<p>will also read include patterns from the file the property
  +<code>some-other-file</code> points to, if a property of that name has
  +been defined.</p>
   <hr>
   <p align="center">Copyright &copy; 2000,2001 Apache Software Foundation. All rights
   Reserved.</p>
  
  
  
  1.15      +14 -0     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java
  
  Index: MatchingTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- MatchingTask.java	2001/01/03 14:18:30	1.14
  +++ MatchingTask.java	2001/08/01 09:08:55	1.15
  @@ -84,12 +84,26 @@
       }
       
       /**
  +     * add a name entry on the include files list
  +     */
  +    public PatternSet.NameEntry createIncludesFile() {
  +        return fileset.createIncludesFile();
  +    }
  +    
  +    /**
        * add a name entry on the exclude list
        */
       public PatternSet.NameEntry createExclude() {
           return fileset.createExclude();
       }
   
  +    /**
  +     * add a name entry on the include files list
  +     */
  +    public PatternSet.NameEntry createExcludesFile() {
  +        return fileset.createExcludesFile();
  +    }
  +    
       /**
        * add a set of patterns
        */
  
  
  
  1.17      +20 -0     jakarta-ant/src/main/org/apache/tools/ant/types/FileSet.java
  
  Index: FileSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/FileSet.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- FileSet.java	2001/07/23 03:56:12	1.16
  +++ FileSet.java	2001/08/01 09:08:55	1.17
  @@ -146,6 +146,16 @@
       }
       
       /**
  +     * add a name entry on the include files list
  +     */
  +    public PatternSet.NameEntry createIncludesFile() {
  +        if (isReference()) {
  +            throw noChildrenAllowed();
  +        }
  +        return defaultPatterns.createIncludesFile();
  +    }
  +    
  +    /**
        * add a name entry on the exclude list
        */
       public PatternSet.NameEntry createExclude() {
  @@ -155,6 +165,16 @@
           return defaultPatterns.createExclude();
       }
   
  +    /**
  +     * add a name entry on the include files list
  +     */
  +    public PatternSet.NameEntry createExcludesFile() {
  +        if (isReference()) {
  +            throw noChildrenAllowed();
  +        }
  +        return defaultPatterns.createExcludesFile();
  +    }
  +    
       /**
        * Sets the set of include patterns. Patterns may be separated by a comma
        * or a space.
  
  
  
  1.8       +66 -41    jakarta-ant/src/main/org/apache/tools/ant/types/PatternSet.java
  
  Index: PatternSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/PatternSet.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- PatternSet.java	2001/07/23 03:56:12	1.7
  +++ PatternSet.java	2001/08/01 09:08:55	1.8
  @@ -79,9 +79,8 @@
   public class PatternSet extends DataType {
       private Vector includeList = new Vector();
       private Vector excludeList = new Vector();
  -    
  -    private File incl = null;
  -    private File excl = null;
  +    private Vector includesFileList = new Vector();
  +    private Vector excludesFileList = new Vector();
   
       /**
        * inner class to hold a name on list.  "If" and "Unless" attributes
  @@ -122,23 +121,18 @@
               return true;
           }
   
  -	public String toString()
  -	{
  -	    StringBuffer buf = new StringBuffer();
  -	    buf.append( name );
  -	    if ((ifCond != null) || (unlessCond != null))
  -	    {
  +	public String toString() {
  +	    StringBuffer buf = new StringBuffer(name);
  +	    if ((ifCond != null) || (unlessCond != null)) {
   		buf.append(":");
   		String connector = "";
   		
  -		if (ifCond != null)
  -		{
  +		if (ifCond != null) {
   		    buf.append("if->");
   		    buf.append(ifCond);
   		    connector = ";";
   		}
  -		if (unlessCond != null)
  -		{
  +		if (unlessCond != null) {
   		    buf.append(connector);
   		    buf.append("unless->");
   		    buf.append(unlessCond);
  @@ -176,6 +170,16 @@
           }
           return addPatternToList(includeList);
       }
  +
  +    /**
  +     * add a name entry on the include files list
  +     */
  +    public NameEntry createIncludesFile() {
  +        if (isReference()) {
  +            throw noChildrenAllowed();
  +        }
  +        return addPatternToList(includesFileList);
  +    }
       
       /**
        * add a name entry on the exclude list
  @@ -186,6 +190,16 @@
           }
           return addPatternToList(excludeList);
       }
  +    
  +    /**
  +     * add a name entry on the exclude files list
  +     */
  +    public NameEntry createExcludesFile() {
  +        if (isReference()) {
  +            throw noChildrenAllowed();
  +        }
  +        return addPatternToList(excludesFileList);
  +    }
   
       /**
        * Sets the set of include patterns. Patterns may be separated by a comma
  @@ -235,33 +249,25 @@
       /**
        * Sets the name of the file containing the includes patterns.
        *
  -     * @param incl The file to fetch the include patterns from.  
  +     * @param includesFile The file to fetch the include patterns from.  
        */
  -     public void setIncludesfile(File incl) throws BuildException {
  +     public void setIncludesfile(File includesFile) throws BuildException {
            if (isReference()) {
                throw tooManyAttributes();
            }
  -         if (!incl.exists()) {
  -             throw new BuildException("Includesfile "+incl.getAbsolutePath()
  -                                      +" not found.");
  -         }
  -         this.incl = incl;
  +         createIncludesFile().setName(includesFile.getAbsolutePath());
        }
   
       /**
        * Sets the name of the file containing the excludes patterns.
        *
  -     * @param excl The file to fetch the exclude patterns from.  
  +     * @param excludesFile The file to fetch the exclude patterns from.  
        */
  -     public void setExcludesfile(File excl) throws BuildException {
  +     public void setExcludesfile(File excludesFile) throws BuildException {
            if (isReference()) {
                throw tooManyAttributes();
  -         }
  -         if (!excl.exists()) {
  -             throw new BuildException("Excludesfile "+excl.getAbsolutePath()
  -                                      +" not found.");
            }
  -         this.excl = excl;
  +         createExcludesFile().setName(excludesFile.getAbsolutePath());
        }
       
       /**
  @@ -345,7 +351,7 @@
        * helper for FileSet.
        */
       boolean hasPatterns() {
  -        return incl != null || excl != null
  +        return includesFileList.size() > 0 || excludesFileList.size() > 0 
               || includeList.size() > 0 || excludeList.size() > 0;
       }
   
  @@ -390,23 +396,42 @@
       }
           
       /**
  -     * Read includefile ot excludefile if not already done so.
  +     * Read includesfile ot excludesfile if not already done so.
        */
       private void readFiles(Project p) {
  -        if (incl != null) {
  -            readPatterns(incl, includeList, p);
  -            incl = null;
  -        }
  -        if (excl != null) {
  -            readPatterns(excl, excludeList, p);
  -            excl = null;
  +        if (includesFileList.size() > 0) {
  +            Enumeration e = includesFileList.elements();
  +            while (e.hasMoreElements()) {
  +            	NameEntry ne = (NameEntry)e.nextElement();
  +            	String fileName = ne.evalName(p);
  +            	if (fileName != null) {
  +                    File inclFile = p.resolveFile(fileName);
  +                    if (!inclFile.exists())
  +                        throw new BuildException("Includesfile "
  +                                                 + inclFile.getAbsolutePath()
  +                                                 + " not found.");
  +                    readPatterns(inclFile, includeList, p);
  +            	}
  +            }
  +            includesFileList.clear();
           }
  -    }
   
  -    public String toString()
  -    {
  -        return "patternSet{ includes: " + includeList + 
  -            " excludes: " + excludeList + " }";
  +        if (excludesFileList.size() > 0) {
  +            Enumeration e = includesFileList.elements();
  +            while (e.hasMoreElements()) {
  +            	NameEntry ne = (NameEntry)e.nextElement();
  +            	String fileName = ne.evalName(p);
  +            	if (fileName != null) {
  +                    File exclFile = p.resolveFile(fileName);
  +                    if (!exclFile.exists())
  +                        throw new BuildException("Excludesfile "
  +                                                 + exclFile.getAbsolutePath()
  +                                                 + " not found.");
  +                    readPatterns(exclFile, excludeList, p);
  +            	}
  +            }
  +            excludesFileList.clear();
  +        }
       }
   
   }
  
  
  
  1.4       +14 -0     jakarta-ant/src/testcases/org/apache/tools/ant/types/FileSetTest.java
  
  Index: FileSetTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/types/FileSetTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FileSetTest.java	2001/05/23 16:58:36	1.3
  +++ FileSetTest.java	2001/08/01 09:08:56	1.4
  @@ -166,6 +166,20 @@
                            be.getMessage());
           }
           try {
  +            f.createIncludesFile();
  +            fail("Can add nested includesfile in FileSet that is a reference.");
  +        } catch (BuildException be) {
  +            assertEquals("You must not specify nested elements when using refid",
  +                         be.getMessage());
  +        }
  +        try {
  +            f.createExcludesFile();
  +            fail("Can add nested excludesfile in FileSet that is a reference.");
  +        } catch (BuildException be) {
  +            assertEquals("You must not specify nested elements when using refid",
  +                         be.getMessage());
  +        }
  +        try {
               f.createPatternSet();
               fail("Can add nested patternset in FileSet that is a reference.");
           } catch (BuildException be) {
  
  
  
  1.4       +14 -0     jakarta-ant/src/testcases/org/apache/tools/ant/types/PatternSetTest.java
  
  Index: PatternSetTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/types/PatternSetTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PatternSetTest.java	2001/01/03 14:18:51	1.3
  +++ PatternSetTest.java	2001/08/01 09:08:56	1.4
  @@ -141,6 +141,20 @@
               assertEquals("You must not specify nested elements when using refid",
                            be.getMessage());
           }
  +        try {
  +            p.createIncludesFile();
  +            fail("Can add nested includesfile in PatternSet that is a reference.");
  +        } catch (BuildException be) {
  +            assertEquals("You must not specify nested elements when using refid",
  +                         be.getMessage());
  +        }
  +        try {
  +            p.createExcludesFile();
  +            fail("Can add nested excludesfile in PatternSet that is a reference.");
  +        } catch (BuildException be) {
  +            assertEquals("You must not specify nested elements when using refid",
  +                         be.getMessage());
  +        }
       }
   
       public void testCircularReferenceCheck() {