You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by jo...@locus.apache.org on 2000/12/05 04:53:16 UTC

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

jon         00/12/04 19:53:16

  Modified:    src/main/org/apache/tools/ant/taskdefs Delete.java
  Log:
  added setQuiet option to emulate a rm -f
  
  i can't actually test this code since i can't even get Ant to compile.
  
  maybe someone else would like to test it for me?
  
  Revision  Changes    Path
  1.10      +20 -5     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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Delete.java	2000/10/04 09:18:48	1.9
  +++ Delete.java	2000/12/05 03:53:15	1.10
  @@ -68,9 +68,10 @@
    * to provide backwards compatibility for a release.  The future position
    * is to use nested filesets exclusively.</p>
    * 
  - * @author stefano@apache.org
  + * @author Stefano Mazzocchi <a href="mailto:stefano@apache.org">stefano@apache.org</a>
    * @author Tom Dimock <a href="mailto:tad1@cornell.edu">tad1@cornell.edu</a>
    * @author Glenn McAllister <a href="mailto:glennm@ca.ibm.com">glennm@ca.ibm.com</a>
  + * @author Jon S. Stevens <a href="mailto:jon@latchkey.com">jon@latchkey.com</a>
    */
   public class Delete extends MatchingTask {
       protected File file = null;
  @@ -79,6 +80,7 @@
       protected boolean usedMatchingTask = false;
   
       private int verbosity = Project.MSG_VERBOSE;
  +    private boolean quiet = false;
   
       /**
        * Set the name of a single file to be removed.
  @@ -112,6 +114,19 @@
       } 
   
       /**
  +     * If the file does not exist, do not display a diagnostic 
  +     * message or modify the exit status to reflect an error.
  +     * This means that if a file or directory cannot be deleted,
  +     * then no error is reported. This setting emulates the 
  +     * -f option to the Unix &quot;rm&quot; command.
  +     * Default is false meaning things are &quot;noisy&quot;
  +     * @param quiet "true" or "on"
  +     */
  +    public void setQuiet(boolean quiet) {
  +        this.quiet = quiet;
  +    } 
  +
  +    /**
        * Adds a set of files (nested fileset attribute).
        */
       public void addFileset(FileSet set) {
  @@ -218,7 +233,7 @@
                   } else {
                       log("Deleting: " + file.getAbsolutePath());
     
  -                    if (!file.delete()) {
  +                    if (!quiet && !file.delete()) {
                           throw new BuildException("Unable to delete file " + file.getAbsolutePath());
                       } 
                   } 
  @@ -262,13 +277,13 @@
                   removeDir(f);
               } else {
                   log("Deleting " + f.getAbsolutePath(), verbosity);
  -                if (!f.delete()) {
  +                if (!quiet && !f.delete()) {
                       throw new BuildException("Unable to delete file " + f.getAbsolutePath());
                   }
               }
           }
           log("Deleting directory " + d.getAbsolutePath(), verbosity);
  -        if (!d.delete()) {
  +        if (!quiet && !d.delete()) {
               throw new BuildException("Unable to delete directory " + dir.getAbsolutePath());
           }
       }
  @@ -279,7 +294,7 @@
               for (int j=0; j<files.length; j++) {
                   File f = new File(d, files[j]);
                   log("Deleting " + f.getAbsolutePath(), verbosity);
  -                if (!f.delete()) {
  +                if (!quiet && !f.delete()) {
                       throw new BuildException("Unable to delete file " + f.getAbsolutePath());
                   }
               }