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 2003/05/09 14:10:37 UTC

cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs DefaultExcludesTest.java

bodewig     2003/05/09 05:10:36

  Modified:    .        WHATSNEW
               docs/manual coretasklist.html dirtasks.html
               src/main/org/apache/tools/ant DirectoryScanner.java
               src/main/org/apache/tools/ant/taskdefs defaults.properties
  Added:       docs/manual/CoreTasks defaultexcludes.html
               src/etc/testcases/taskdefs defaultexcludes.xml
               src/main/org/apache/tools/ant/taskdefs DefaultExcludes.java
               src/testcases/org/apache/tools/ant/taskdefs
                        DefaultExcludesTest.java
  Log:
  A new task that allows users to modify the list of default excludes.
  
  PR: 12700
  Submitted by:	Gus Heck <gus dot heck at olin dot edu>
  
  Revision  Changes    Path
  1.410     +3 -0      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.409
  retrieving revision 1.410
  diff -u -r1.409 -r1.410
  --- WHATSNEW	6 May 2003 15:19:15 -0000	1.409
  +++ WHATSNEW	9 May 2003 12:10:35 -0000	1.410
  @@ -302,6 +302,9 @@
     in <vajload> by using special wildcard characters.  Also fixes
     Bugzilla Report 2236.
   
  +* Users can now modify the list of default excludes using the new
  +  defaultexcludes task.  Bugzilla Report 12700.
  +
   Changes from Ant 1.5.2 to Ant 1.5.3
   ===================================
   
  
  
  
  1.47      +1 -0      ant/docs/manual/coretasklist.html
  
  Index: coretasklist.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/coretasklist.html,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- coretasklist.html	21 Apr 2003 06:36:46 -0000	1.46
  +++ coretasklist.html	9 May 2003 12:10:35 -0000	1.47
  @@ -36,6 +36,7 @@
   <a href="CoreTasks/changelog.html">CvsChangeLog</a><br>
   <a href="CoreTasks/cvspass.html">CVSPass</a><br>
   <a href="CoreTasks/cvstagdiff.html">CvsTagDiff</a><br>
  +<a href="CoreTasks/defaultexcludes.html">Defaultexcludes</a><br>
   <a href="CoreTasks/delete.html">Delete</a><br>
   <a href="CoreTasks/deltree.html"><i>Deltree</i></a><br>
   <a href="CoreTasks/dependset.html">Dependset</a><br>
  
  
  
  1.19      +8 -2      ant/docs/manual/dirtasks.html
  
  Index: dirtasks.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/dirtasks.html,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- dirtasks.html	4 Feb 2003 17:29:10 -0000	1.18
  +++ dirtasks.html	9 May 2003 12:10:35 -0000	1.19
  @@ -261,8 +261,14 @@
        **/.svn/**
        **/.DS_Store
   </pre>
  -<p>If you do not want these default excludes applied, you may disable them
  -with the <code>defaultexcludes=&quot;no&quot;</code> attribute.</p>
  +<p>If you do not want these default excludes applied, you may disable
  +them with the <code>defaultexcludes=&quot;no&quot;</code>
  +attribute.</p>
  +
  +<p>This is the default list, note that you can modify the list of
  +default excludes by using the <a
  +href="CoreTasks/defaultexcludes.html">defaultexcludes</a> task.</p>
  +
   <hr>
   <p align="center">Copyright &copy; 2000-2003 Apache Software Foundation. All
   rights Reserved.</p>
  
  
  
  1.1                  ant/docs/manual/CoreTasks/defaultexcludes.html
  
  Index: defaultexcludes.html
  ===================================================================
  <html>
  
  <head>
  <meta http-equiv="Content-Language" content="en-us">
  <title>DefaultExcludes Task</title>
  </head>
  
  <body>
  
  <h2><a name="echo">DefaultExcludes</a></h2>
  
  <p><em>since Ant 1.6</em></p>
  
  <h3>Description</h3>
  <p>Alters the default excludes for all subsequent processing in the
  build, and prints out the current default excludes if desired.
  
  <h3>Parameters</h3>
  <table border="1" cellpadding="2" cellspacing="0">
    <tr>
      <td valign="top"><b>Attribute</b></td>
      <td valign="top"><b>Description</b></td>
      <td align="center" valign="top"><b>Required</b></td>
    </tr>
    <tr>
      <td valign="top">echo</td>
      <td valign="top">whether or not to print out the default excludes.(defaults to false)</td>
      <td valign="top" align="center">atribute "true" required if no 
                                      other argument specified</td>
    </tr>
    <tr>
      <td valign="top">add</td>
      <td valign="top">the pattern to add to the default excludes</td>
      <td valign="top" align="center">if no other atribute is specified</td>
    </tr>
    <tr>
      <td valign="top">remove</td>
      <td valign="top">remove the specified pattern from the default excludes</td>
      <td valign="top" align="center">if no other atribute is specified</td>
    </tr>
  </table>
  
  <h3>Examples</h3>
  
  <p>Print out the default excludes</p>
  
  <pre>  &lt;defaultexcludes echo=&quot;true&quot;/&gt;</pre>
  
  <p>Print out the default excludes and exclude all *.bak files in
  <strong>all</strong> further processing</p>
  
  <pre>  &lt;defaultexcludes echo=&quot;true&quot; add=&quot;**/*.bak&quot;/&gt;</pre>
  
  <p>Silently allow several fileset based tasks to operate on emacs
  backup files and then restore normal behavior</p>
  
  <pre>
    &lt;defaultexcludes remove=&quot;**/*~&quot;/&gt;
  
    (do several fileset based tasks here)
  
    &lt;defaultexcludes add=&quot;**/*~&quot;/&gt;
  </pre>
  
  
  <hr>
  
  <p align="center">Copyright &copy; 2003 Apache Software Foundation. All rights
  Reserved.</p>
  
  </body>
  </html>
  
  
  
  
  1.1                  ant/src/etc/testcases/taskdefs/defaultexcludes.xml
  
  Index: defaultexcludes.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <project name="echo-test" basedir="." default="test1">
  
    <target name="test1">
      <defaultexcludes echo="true"/>
    </target>
  
    <target name="test2">
      <defaultexcludes add="foo" echo="true"/>
      <defaultexcludes remove="foo" echo="false"/>
    </target>
  
    <target name="test3">
      <defaultexcludes remove="**/CVS" echo="true"/>
      <defaultexcludes add="**/CVS" echo="false"/>
    </target>
  
  </project>
  
  
  
  1.40      +71 -31    ant/src/main/org/apache/tools/ant/DirectoryScanner.java
  
  Index: DirectoryScanner.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/DirectoryScanner.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- DirectoryScanner.java	14 Apr 2003 14:47:41 -0000	1.39
  +++ DirectoryScanner.java	9 May 2003 12:10:36 -0000	1.40
  @@ -155,38 +155,34 @@
   public class DirectoryScanner 
          implements FileScanner, SelectorScanner, ResourceFactory {
   
  +
       /**
        * Patterns which should be excluded by default.
        *
        * @see #addDefaultExcludes()
        */
  -    protected static final String[] DEFAULTEXCLUDES = {
  -        // Miscellaneous typical temporary files
  -        "**/*~",
  -        "**/#*#",
  -        "**/.#*",
  -        "**/%*%",
  -        "**/._*",
  -
  -        // CVS
  -        "**/CVS",
  -        "**/CVS/**",
  -        "**/.cvsignore",
  -
  -        // SCCS
  -        "**/SCCS",
  -        "**/SCCS/**",
  -
  -        // Visual SourceSafe
  -        "**/vssver.scc",
  -
  -        // Subversion
  -        "**/.svn",
  -        "**/.svn/**",
  -
  -        // Mac
  -        "**/.DS_Store"
  -    };
  +    private static Vector defaultExcludes = new Vector();  
  +
  +    static {
  +        defaultExcludes.add("**/*~");
  +        defaultExcludes.add("**/#*#");
  +        defaultExcludes.add("**/.#*");
  +        defaultExcludes.add("**/%*%");
  +        defaultExcludes.add("**/._*");
  +
  +        defaultExcludes.add("**/CVS");
  +        defaultExcludes.add("**/CVS/**");
  +        defaultExcludes.add("**/.cvsignore");
  +
  +        defaultExcludes.add("**/SCCS");
  +        defaultExcludes.add("**/SCCS/**");
  +
  +        defaultExcludes.add("**/vssver.scc");
  +
  +        defaultExcludes.add("**/.svn");
  +        defaultExcludes.add("**/.svn/**");
  +        defaultExcludes.add("**/.DS_Store");
  +    }
   
       /** The base directory to be scanned. */
       protected File basedir;
  @@ -381,6 +377,48 @@
           return SelectorUtils.match(pattern, str, isCaseSensitive);
       }
   
  +
  +    /**
  +     * Get the list of patterns that should be excluded by default.
  +     *
  +     * @return An array of <code>String</code> based on the current 
  +     *         contents of the <code>defaultExcludes</code> 
  +     *         <code>Vector</code>.
  +     */
  +    public static String[] getDefaultExcludes() {
  +        return (String[]) defaultExcludes.toArray(new String[defaultExcludes.size()]);
  +    }
  +
  +    /**
  +     * Add a pattern to the default excludes unless it is already a 
  +     * default exclude.
  +     *
  +     * @param s   A string to add as an exclude pattern.
  +     * @return    <code>true</code> if the string was added 
  +     *            <code>false</code> if it already
  +     *            existed.
  +     */
  +    public static boolean addDefaultExclude(String s){
  +        if (defaultExcludes.indexOf(s) == -1) {
  +            defaultExcludes.add(s);
  +            return true;
  +        }
  +        return false;
  +    }
  +
  +    /**
  +     * Remove a string if it is a default exclude.
  +     *
  +     * @param s   The string to attempt to remove.
  +     * @return    <code>true</code> if <code>s</code> was a default 
  +     *            exclude (and thus was removed),
  +     *            <code>false</code> if <code>s</code> was not
  +     *            in the default excludes list to begin with
  +     */
  +    public static boolean removeDefaultExclude(String s) {
  +        return defaultExcludes.remove(s);
  +    }
  +
       /**
        * Sets the base directory to be scanned. This is the directory which is
        * scanned recursively. All '/' and '\' characters are replaced by
  @@ -938,13 +976,15 @@
       public void addDefaultExcludes() {
           int excludesLength = excludes == null ? 0 : excludes.length;
           String[] newExcludes;
  -        newExcludes = new String[excludesLength + DEFAULTEXCLUDES.length];
  +        newExcludes = new String[excludesLength + defaultExcludes.size()];
           if (excludesLength > 0) {
               System.arraycopy(excludes, 0, newExcludes, 0, excludesLength);
           }
  -        for (int i = 0; i < DEFAULTEXCLUDES.length; i++) {
  -            newExcludes[i + excludesLength] = DEFAULTEXCLUDES[i].replace('/',
  -                    File.separatorChar).replace('\\', File.separatorChar);
  +        String[] defaultExcludesTemp = getDefaultExcludes();
  +        for (int i = 0; i < defaultExcludesTemp.length; i++) {
  +            newExcludes[i + excludesLength] = defaultExcludesTemp[i].
  +                replace('/', File.separatorChar).
  +                replace('\\', File.separatorChar);
           }
           excludes = newExcludes;
       }
  
  
  
  1.146     +1 -0      ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties
  
  Index: defaults.properties
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties,v
  retrieving revision 1.145
  retrieving revision 1.146
  diff -u -r1.145 -r1.146
  --- defaults.properties	21 Apr 2003 16:48:25 -0000	1.145
  +++ defaults.properties	9 May 2003 12:10:36 -0000	1.146
  @@ -75,6 +75,7 @@
   whichresource=org.apache.tools.ant.taskdefs.WhichResource
   subant=org.apache.tools.ant.taskdefs.SubAnt
   sync=org.apache.tools.ant.taskdefs.Sync
  +defaultexcludes=org.apache.tools.ant.taskdefs.DefaultExcludes
   
   # optional tasks
   image=org.apache.tools.ant.taskdefs.optional.image.Image
  
  
  
  1.1                  ant/src/main/org/apache/tools/ant/taskdefs/DefaultExcludes.java
  
  Index: DefaultExcludes.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "Ant" and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.tools.ant.taskdefs;
  
  import org.apache.tools.ant.Task;
  import org.apache.tools.ant.Project;
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.DirectoryScanner;
  import org.apache.tools.ant.types.EnumeratedAttribute;
  /**
   * Alters the default excludes for the <strong>entire</strong> build..
   *
   * @author Gus Heck &lt;gus.heck@olin.edu&gt;
   *
   * @since Ant 1.6
   *
   * @ant.task category="utility"
   */
  public class DefaultExcludes extends Task {
      private String add = "";    
      private String remove = "";
  
      private boolean echo = false;
      
      // by default, messages are always displayed
      private int logLevel = Project.MSG_WARN;   
      
      /**
       * Does the work.
       *
       * @exception BuildException if someting goes wrong with the build
       */
      public void execute() throws BuildException {
          if (add.equals("") && remove.equals("") && (echo == false)) {
              throw new BuildException("<defaultexcludes> task must set "+
                                       "at least one atribute (echo=\"false\""+
                                       " doesn't count since that is the "+
                                       "default");
          }
          if (!add.equals("")) {
              DirectoryScanner.addDefaultExclude(add);
          }
          if (!remove.equals("")) {
              DirectoryScanner.removeDefaultExclude(remove);
          }
          if (echo == true) {
              StringBuffer message = new StringBuffer("Current Default "+
                                                      "Excludes:\n");
              String[] excludes = DirectoryScanner.getDefaultExcludes();
              for (int i=0;i<excludes.length;i++) {
                  message.append("  " + excludes[i] + "\n");
              }
              log(message.toString(), logLevel);
          }
      }
  
      /**
       * Pattern to add to the default excludes
       *
       * @param add Sets the value for the pattern to exclude.
       */
      public void setAdd(String add) {
          this.add = add;
      }
  
       /**
       * Pattern to remove from the default excludes.
       *
       * @param msg Sets the value for the pattern that 
       *            should nolonger be excluded.
       */
      public void setRemove(String remove) {
          this.remove = remove;
      }
  
      /**
       * If true, echo the default excludes.
       *
       * @param echo whether or not to echo the contents of
       *             the default excludes.
       */
      public void setEcho(boolean echo) {
          this.echo = echo;
      }
  
  
  }
  
  
  
  1.1                  ant/src/testcases/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java
  
  Index: DefaultExcludesTest.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "Ant" and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.tools.ant.taskdefs;
  
  import org.apache.tools.ant.BuildFileTest;
  
  /**
   * @author Gus Heck <gu...@olin.edu> 
   */
  public class DefaultExcludesTest extends BuildFileTest { 
      
      public DefaultExcludesTest(String name) { 
          super(name);
      }    
      
      public void setUp() { 
          configureProject("src/etc/testcases/taskdefs/defaultexcludes.xml");
      }
      
      // Output the default excludes
      public void test1() { 
          expectLog("test1", "Current Default Excludes:\n"+
                    "  **/*~\n"+
                    "  **/#*#\n"+
                    "  **/.#*\n"+
                    "  **/%*%\n"+
                    "  **/._*\n"+
                    "  **/CVS\n"+
                    "  **/CVS/**\n"+
                    "  **/.cvsignore\n"+
                    "  **/SCCS\n"+
                    "  **/SCCS/**\n"+
                    "  **/vssver.scc\n"+
                    "  **/.svn\n"+
                    "  **/.svn/**\n"+
                    "  **/.DS_Store\n");          
      }
      
      // adding something to the excludes'
      public void test2() { 
          expectLog("test2", "Current Default Excludes:\n"+
                    "  **/*~\n"+
                    "  **/#*#\n"+
                    "  **/.#*\n"+
                    "  **/%*%\n"+
                    "  **/._*\n"+
                    "  **/CVS\n"+
                    "  **/CVS/**\n"+
                    "  **/.cvsignore\n"+
                    "  **/SCCS\n"+
                    "  **/SCCS/**\n"+
                    "  **/vssver.scc\n"+
                    "  **/.svn\n"+
                    "  **/.svn/**\n"+
                    "  **/.DS_Store\n"+
                    "  foo\n");             // foo added
      }
  
      // removing something from the defaults
      public void test3() { 
          expectLog("test3", "Current Default Excludes:\n"+
                    "  **/*~\n"+
                    "  **/#*#\n"+
                    "  **/.#*\n"+
                    "  **/%*%\n"+
                    "  **/._*\n"+
                    //CVS missing
                    "  **/CVS/**\n"+
                    "  **/.cvsignore\n"+
                    "  **/SCCS\n"+
                    "  **/SCCS/**\n"+
                    "  **/vssver.scc\n"+
                    "  **/.svn\n"+
                    "  **/.svn/**\n"+
                    "  **/.DS_Store\n");
      }
  }