You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by ru...@locus.apache.org on 2000/06/16 03:46:14 UTC

cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Delete.java

rubys       00/06/15 18:46:13

  Modified:    docs     index.html
               src/main/org/apache/tools/ant/taskdefs Delete.java
  Log:
  Make Delete a matchingTask
  Submitted by: Tom Dimock <ta...@cornell.edu>
  
  Revision  Changes    Path
  1.22      +67 -9     jakarta-ant/docs/index.html
  
  Index: index.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/index.html,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- index.html	2000/06/01 06:54:52	1.21
  +++ index.html	2000/06/16 01:46:12	1.22
  @@ -12,12 +12,13 @@
   <!-- Names are in alphabetical order, on last name -->
   <ul>
     <li>James Duncan Davison (<a href="mailto:duncan@x180.com">duncan@x180.com</a>)</li>
  +  <li>Tom Dimock (<a href="mailto:tad1@cornell.edu">tad1@cornell.edu</a>)</li>
     <li>Arnout J. Kuiper (<a href="mailto:ajkuiper@wxs.nl">ajkuiper@wxs.nl</a>)</li>
     <li>Stefano Mazzocchi (<a href="mailto:stefano@apache.org">stefano@apache.org</a>)</li>
     <li>Sam Ruby (<a href="mailto:rubys@us.ibm.com">rubys@us.ibm.com</a>)</li>
   </ul>
   
  -<p>Version 1.0.8 - 2000/03/04</p>
  +<p>Version 1.0.8.1 - 2000/06/13</p>
   
   <hr>
   <h2>Table of Contents</h2>
  @@ -443,6 +444,18 @@
   <p>This copies all files in directories called &quot;images&quot;, that are
   located in the directory tree &quot;${src}&quot; to the destination &quot;${dist}&quot;,
   but excludes all &quot;*.gif&quot; files from the copy.</p>
  +<h3>Default Excludes</h3>
  +<p>There are a set of definitions which are excluded by default from all directory based tasks.
  +They are:
  +<pre>        &quot;**/*~&quot;,
  +        &quot;**/#*#&quot;,
  +        &quot;**/%*%&quot;,
  +        &quot;**/CVS&quot;,
  +        &quot;**/CVS/*&quot;,
  +        &quot;**/.cvsignore&quot;
  +</pre>
  +If you do not want these default excludes applied, you may disable them with the 
  +<code>defaultexcludes=&quot;no&quot;</code> attribute.</p>
   <hr>
   <h2><a name="tasks">Built in tasks</a></h2>
   <ul>
  @@ -521,7 +534,7 @@
   <hr>
   <h2><a name="available">Available</a></h2>
   <h3>Description</h3>
  -<p>Sets a property is a resource is available at runtime. This resource can be a
  +<p>Sets a property if a resource is available at runtime. This resource can be a
   file resource, a class in classpath or a JVM system resource.</p>
   <p>The value part of the properties being set is <i>true</i> if the resource is
   present, otherwise, the property is not set.</p>
  @@ -753,9 +766,20 @@
   <p>checks out the package/module &quot;jakarta-tools&quot; from the CVS
   repository pointed to by the cvsRoot attribute, and stores the files in &quot;${ws.dir}&quot;.</p>
   <hr>
  -<h2><a name="delete">Delete</a></h2>
  +    <td valign="top">comma separated list of filenam<h2><a name="delete">Delete</a></h2>
   <h3>Description</h3>
  -<p>Deletes a single file.</p>
  +<p>Deletes either a single file or
  +all files in a specified directory and its sub-directories.</p>
  +<p>It is possible to refine the set of files that are being deleted. This can be
  +done with the <i>includes</i>, <i>excludes</i> and <i>defaultexcludes</i>
  +attributes. With the <i>includes</i> attribute you specify the files you want to
  +have included in the deletion process by using patterns. The <i>exclude</i> attribute is used to specify
  +the files you want to have excluded from the deletion process. This is also done with patterns. And
  +finally with the <i>defaultexcludes</i> attribute, you can specify whether you
  +want to use default exclusions or not. See the section on <a
  +href="#directorybasedtasks">directory based tasks</a>, on how the
  +inclusion/exclusion of files works, and how to write patterns. The patterns are
  +relative to the <i>dir</i> directory.</p>
   <h3>Parameters</h3>
   <table border="1" cellpadding="2" cellspacing="0">
     <tr>
  @@ -765,16 +789,49 @@
     </tr>
     <tr>
       <td valign="top">file</td>
  -    <td valign="top">the file to delete.</td>
  -    <td valign="top" align="center">Yes</td>
  +    <td valign="top">The file to delete.</td>
  +    <td align="center" valign="middle" rowspan="2">at least one of the two</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">dir</td>
  +    <td valign="top">The directory to delete files from.</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">includes</td>
  +    <td valign="top">Comma separated list of patterns of files that must be
  +      deleted. All files are in the current directory 
  +      and any sub-directories are deleted when omitted.</td>
  +    <td valign="top" align="center">No</td>
     </tr>
  +  <tr>
  +    <td valign="top">excludes</td>
  +    <td valign="top">Comma separated list of patterns of files that must be
  +      excluded from the deletion list. No files (except default excludes) are excluded when omitted.</td>
  +    <td valign="top" align="center">No</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">defaultexcludes</td>
  +    <td valign="top">Indicates whether default excludes should be used or not
  +      (&quot;yes&quot;/&quot;no&quot;). Default excludes are used when omitted.</td>
  +    <td valign="top" align="center">No</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">verbose</td>
  +    <td valign="top">Show name of each deleted file (&quot;true&quot;/&quot;false&quot;). Default is "false" when omitted.</td>
  +    <td align="center" valign="top">No</td>
  +  </tr>
   </table>
   <h3>Examples</h3>
   <pre>  &lt;delete file=&quot;/lib/ant.jar&quot; /&gt;</pre>
   <p>deletes the file <code>/lib/ant.jar</code>.</p>
  -<pre>  &lt;delete file=&quot;${ant}&quot; /&gt;</pre>
  -<p>deletes the file <code>${ant}</code>.</p>
  -<hr>
  +<pre>  &lt;delete dir=&quot;lib&quot; /&gt;</pre>
  +<p>deletes all files in the <code>/lib</code> directory.</p>
  +<pre>  &lt;delete dir=&quot;.&quot;
  +          include=&quot;**/*.bak&quot;
  +  /&gt;
  +</pre>
  +<p>deletes all files with the extension &quot;<code>.bak</code>&quot from the current directory 
  +and any sub-directories.</p>
   <h2><a name="deltree">Deltree</a></h2>
   <h3>Description</h3>
   <p>Deletes a directory with all its files and subdirectories.</p>
  @@ -2632,3 +2689,4 @@
   </body>
   
   </html>
  +
  
  
  
  1.3       +82 -14    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Delete.java
  
  Index: Delete.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Delete.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Delete.java	2000/02/28 02:17:57	1.2
  +++ Delete.java	2000/06/16 01:46:13	1.3
  @@ -51,36 +51,104 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  -
   package org.apache.tools.ant.taskdefs;
   
   import org.apache.tools.ant.*;
  +
   import java.io.*;
   
   /**
  - * Deletes a single file.
  + * Deletes a single file or a set of files defined by a pattern.
    *
    * @author stefano@apache.org
  + * @author Tom Dimock <a href="mailto:tad1@cornell.edu">tad1@cornell.edu</a>
    */
  +public class Delete extends MatchingTask {
   
  -public class Delete extends Task {
  +  private File delDir = null;
  +  private int verbosity = project.MSG_VERBOSE;
  +  private File f = null;
  +
  +  /**
  +   * Set the name of a single file to be removed.
  +   *
  +   * @param file the file to be deleted
  +   */
  +  public void setFile(String file) {
  +    f = project.resolveFile(file);
  +  }
  +
  +  /**
  +   * Set the directory from which files are to be deleted
  +   *
  +   * @param dir the directory path.
  +   */
  +  public void setDir(String dir) {
  +    delDir = project.resolveFile(dir);
  +  }
  +
  +  /**
  +   * Used to force listing of all names of deleted files.
  +   *
  +   * @param verbose "true" or "on"
  +   */
  +  public void setVerbose(String verbose) {
   
  -    private File f;
  +    if ("true".equalsIgnoreCase(verbose.trim()) || "on".equalsIgnoreCase(verbose.trim())) {
  +      this.verbosity = project.MSG_INFO;
  +    }
  +    else {
  +      this.verbosity = project.MSG_VERBOSE;
  +    }
  +  }
   
  -    public void setFile(String File) {
  -        f = project.resolveFile(File);
  +  /**
  +   * Make it so.  Delete the file(s).
  +   *
  +   * @throws BuildException
  +   */
  +  public void execute() throws BuildException {
  +
  +    if (f == null && delDir == null) {
  +      throw new BuildException("<file> or <dir> attribute must be set!");
       }
  +
  +    // old <delete> functionality must still work
  +    if (f != null) {
  +      if (f.exists()) {
  +        if (f.isDirectory()) {
  +          project
  +            .log("Directory: " + f.getAbsolutePath()
  +                 + " cannot be removed with delete.  Use Deltree instead.");
  +        }
  +        else {
  +          project.log("Deleting: " + f.getAbsolutePath());
  +          f.delete();
  +        }
  +      }
  +    }
  +
  +    // now we'll do the fancy pattern-driven deletes
  +    if (delDir == null) {
  +      return;
  +    }
  +    if (!delDir.exists()) {
  +      throw new BuildException("dir does not exist!");
  +    }
  +    DirectoryScanner ds    = super.getDirectoryScanner(delDir);
  +    String[]         files = ds.getIncludedFiles();
  +
  +    if (files.length > 0) {
  +      project.log("Deleting " + files.length + " files from " + delDir.getAbsolutePath());
  +      for (int i = 0; i < files.length; i++) {
  +        File f = new File(delDir, files[i]);
   
  -    public void execute() throws BuildException {
           if (f.exists()) {
  -            if (f.isDirectory()) { 
  -                project.log("Directory: " + f.getAbsolutePath() + 
  -                    " cannot be removed with delete.  Use Deltree instead.");
  -            } else {
  -                project.log("Deleting: " + f.getAbsolutePath());
  -                f.delete();
  -            }
  +          project.log("Deleting: " + f.getAbsolutePath(), verbosity);
  +          f.delete();
           }
  +      }
       }
  +  }
   }