ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gle...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Delete.java
Date Mon, 22 Jan 2001 22:18:03 GMT
glennm      01/01/22 14:18:01

  Modified:    docs     index.html
               src/main/org/apache/tools/ant/taskdefs Delete.java
  Log:
  Fixed problem with quiet flag preventing
  deletes.
  
  Reported by:		Martin van den Bemt
  
  Fixed double delete message with verbose
  flag.
  
  Reported by:		Jason Rosenburg
  
  Added ability to remove empty directories
  when using the implicit or nested filesets.
  Off by default for now, as that is the
  current behaviour.  If there is enough
  agreement, we probably want to turn this
  on by default.
  
  Requested by:		Lots of people. :-)
  
  Revision  Changes    Path
  1.194     +17 -3     jakarta-ant/docs/index.html
  
  Index: index.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/index.html,v
  retrieving revision 1.193
  retrieving revision 1.194
  diff -u -r1.193 -r1.194
  --- index.html	2001/01/21 15:35:45	1.193
  +++ index.html	2001/01/22 22:17:50	1.194
  @@ -34,7 +34,7 @@
   
   <center>
   <p>Version: @VERSION@<br>
  -$Id: index.html,v 1.193 2001/01/21 15:35:45 conor Exp $</p>
  +$Id: index.html,v 1.194 2001/01/22 22:17:50 glennm Exp $</p>
   </center>
   
   <hr>
  @@ -2075,7 +2075,8 @@
   <h3>Description</h3>
   <p>Deletes either a single file, all files in a specified directory and its 
   sub-directories, or a set of files specified by one or more <a href="#fileset">FileSet</a>s.
  -When specifying a set of files, empty directories are <i>not</i> removed.</p>
  +When specifying a set of files, empty directories are <i>not</i> removed by
default.
  +To remove empty directories, use the <em>includeEmptyDirs</em> atribute.</p>
   <h3>Parameters</h3>
   <table border="1" cellpadding="2" cellspacing="0">
     <tr>
  @@ -2110,6 +2111,12 @@
       <td align="center" valign="top">No</td>
     </tr>
     <tr>
  +    <td valign="top">includeEmptyDirs</td>
  +    <td valign="top">Set to &quot;true&quot; to delete empty directores when
  +    using filesets.  Default is &quot;false&quot;.</td>
  +    <td align="center" valign="top">No</td>
  +  </tr>
  +  <tr>
       <td valign="top">includes</td>
       <td valign="top"><i>Deprecated.</i>  Comma separated list of patterns
of files that must be
         deleted. All files are in the current directory 
  @@ -2145,13 +2152,20 @@
   <pre>  &lt;delete file=&quot;/lib/ant.jar&quot;/&gt;</pre>
   <p>deletes the file <code>/lib/ant.jar</code>.</p>
   <pre>  &lt;delete dir=&quot;lib&quot;/&gt;</pre>
  -<p>deletes all files in the <code>/lib</code> directory.</p>
  +<p>deletes the <code>lib</code> directory, including all files 
  +and subdirectories of <code>lib</code>.</p>
   <pre>  &lt;delete&gt;
       &lt;fileset dir=&quot;.&quot; includes=&quot;**/*.bak&quot;/&gt;
     &lt;/delete&gt;
   </pre>
   <p>deletes all files with the extension &quot;<code>.bak</code>&quot
from the current directory 
   and any sub-directories.</p>
  +<pre>  &lt;delete includeEmptyDirs=&quot;true&quot; &gt;
  +    &lt;fileset dir=&quot;build&quot; /&gt;
  +  &lt;/delete&gt;
  +</pre>
  +<p>deletes all files and subdirectories of <code>build</code>, but not
  +<code>build</code> itself.<p>
   <hr>
   <h2><a name="deltree">Deltree</a></h2>
   <h3><i>Deprecated</i></h3>
  
  
  
  1.14      +49 -9     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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Delete.java	2001/01/03 14:18:29	1.13
  +++ Delete.java	2001/01/22 22:17:58	1.14
  @@ -79,6 +79,7 @@
       protected File dir = null;
       protected Vector filesets = new Vector();
       protected boolean usedMatchingTask = false;
  +    protected boolean includeEmpty = false;	// by default, remove matching empty dirs
   
       private int verbosity = Project.MSG_VERBOSE;
       private boolean quiet = false;
  @@ -128,6 +129,13 @@
       } 
   
       /**
  +     * Used to delete empty directories.
  +     */
  +    public void setIncludeEmptyDirs(boolean includeEmpty) {
  +        this.includeEmpty = includeEmpty;
  +    }
  +
  +   /**
        * Adds a set of files (nested fileset attribute).
        */
       public void addFileset(FileSet set) {
  @@ -234,7 +242,7 @@
                   } else {
                       log("Deleting: " + file.getAbsolutePath());
     
  -                    if (!quiet && !file.delete()) {
  +                    if (!file.delete() && !quiet) {
                           throw new BuildException("Unable to delete file " + file.getAbsolutePath());
                       } 
                   } 
  @@ -245,7 +253,15 @@
   
           // delete the directory
           if (dir != null && dir.exists() && dir.isDirectory() &&
!usedMatchingTask) {
  -            log("Deleting directory " + dir.getAbsolutePath());
  +            /*
  +               If verbosity is MSG_VERBOSE, that mean we are doing regular logging
  +               (backwards as that sounds).  In that case, we want to print one 
  +               message about deleting the top of the directory tree.  Otherwise, 
  +               the removeDir method will handle messages for _all_ directories.
  +             */
  +            if (verbosity == Project.MSG_VERBOSE) {
  +                log("Deleting directory " + dir.getAbsolutePath());
  +            }
               removeDir(dir);
           }
   
  @@ -254,14 +270,16 @@
               FileSet fs = (FileSet) filesets.elementAt(i);
               DirectoryScanner ds = fs.getDirectoryScanner(project);
               String[] files = ds.getIncludedFiles();
  -            removeFiles(fs.getDir(project), files);
  +            String[] dirs = ds.getIncludedDirectories();
  +            removeFiles(fs.getDir(project), files, dirs);
           }
   
           // delete the files from the default fileset
           if (usedMatchingTask && dir != null) {
               DirectoryScanner ds = super.getDirectoryScanner(dir);
  -            String [] files = ds.getIncludedFiles();
  -            removeFiles(dir, files);
  +            String[] files = ds.getIncludedFiles();
  +            String[] dirs = ds.getIncludedDirectories();
  +            removeFiles(dir, files, dirs);
           }
       } 
   
  @@ -279,26 +297,48 @@
                   removeDir(f);
               } else {
                   log("Deleting " + f.getAbsolutePath(), verbosity);
  -                if (!quiet && !f.delete()) {
  +                if (!f.delete() && !quiet) {
                       throw new BuildException("Unable to delete file " + f.getAbsolutePath());
                   }
               }
           }
           log("Deleting directory " + d.getAbsolutePath(), verbosity);
  -        if (!quiet && !d.delete()) {
  +        if (!d.delete() && !quiet) {
               throw new BuildException("Unable to delete directory " + dir.getAbsolutePath());
           }
       }
   
  -    protected void removeFiles(File d, String[] files) {
  +    protected void removeFiles(File d, String[] files, String[] dirs) {
           if (files.length > 0) {
               log("Deleting " + files.length + " files from " + d.getAbsolutePath());
               for (int j=0; j<files.length; j++) {
                   File f = new File(d, files[j]);
                   log("Deleting " + f.getAbsolutePath(), verbosity);
  -                if (!quiet && !f.delete()) {
  +                if (!f.delete() && !quiet) {
                       throw new BuildException("Unable to delete file " + f.getAbsolutePath());
                   }
  +            }
  +        }
  +
  +        if (dirs.length > 0 && includeEmpty) {
  +            int dirCount = 0;
  +            for (int j=0; j<dirs.length; j++) {
  +                File dir = new File(d, dirs[j]);
  +                String[] dirFiles = dir.list();
  +                if (dirFiles == null || dirFiles.length == 0) {
  +                    log("Deleting " + dir.getAbsolutePath(), verbosity);
  +                    if (!dir.delete() && !quiet) {
  +                        throw new BuildException("Unable to delete directory " + dir.getAbsolutePath());
  +                    } else {
  +                        dirCount++;
  +                    }
  +                }
  +            }
  +
  +            if (dirCount > 0) {
  +                log("Deleted " + dirCount + " director" + 
  +                    (dirCount==1 ? "y" : "ies") + 
  +                    " from " + d.getAbsolutePath());
               }
           }
       }
  
  
  

Mime
View raw message