ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/net FTP.java
Date Mon, 23 Sep 2002 16:01:43 GMT
bodewig     2002/09/23 09:01:43

  Modified:    .        WHATSNEW
               docs/manual/OptionalTasks ftp.html
               src/main/org/apache/tools/ant/taskdefs/optional/net FTP.java
  Log:
  New <ftp> action rmdir.
  
  PR: 12765
  Submitted by:   Gabriele Garuglieri <gabriele.garuglieri at infoblu.it>
  
  Revision  Changes    Path
  1.288     +5 -0      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.287
  retrieving revision 1.288
  diff -u -r1.287 -r1.288
  --- WHATSNEW	23 Sep 2002 10:37:31 -0000	1.287
  +++ WHATSNEW	23 Sep 2002 16:01:43 -0000	1.288
  @@ -68,6 +68,11 @@
     "unknown" for Test implementations that don't extend TestCase but have
     a public String getName() method.
   
  +* <ftp> now has a preservelastmodified attribute to preserve the
  +  timestamp of a downloaded file.
  +
  +* new rmdir action for <ftp> that removes directories from a fileset.
  +
   Changes from Ant 1.5beta3 to Ant 1.5
   ====================================
   
  
  
  
  1.14      +51 -1     jakarta-ant/docs/manual/OptionalTasks/ftp.html
  
  Index: ftp.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/manual/OptionalTasks/ftp.html,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ftp.html	23 Sep 2002 15:47:55 -0000	1.13
  +++ ftp.html	23 Sep 2002 16:01:43 -0000	1.14
  @@ -66,7 +66,8 @@
       <td valign="top">action</td>
       <td valign="top">the ftp action to perform, defaulting to &quot;send&quot;.
 
                        Currently supports &quot;put&quot;, &quot;get&quot;,
  -                     &quot;del&quot;, &quot;list&quot;, &quot;chmod&quot;
and &quot;mkdir&quot;.</td>
  +                     &quot;del&quot;, &quot;list&quot;, &quot;chmod&quot;,
  +                     &quot;mkdir&quot; and &quot;rmdir&quot;.</td>
       <td valign="top" align="center">No</td>
     </tr>
     <tr>
  @@ -269,6 +270,55 @@
   <p>This creates the directory <code>some/remote/dir</code> beneath the
default root
   directory.  As with all other actions, the directory separator character must be correct
   according to the desires of the FTP server.</p>
  +<h3>Removing Directories</h3>
  +This action uses nested fileset elements to 
  +select the directories to remove from the remote FTP server.  The 
  +filesets are relative to the remote directory, not a local directory. 
  +The dir attribute of the fileset is ignored completely.
  +The directories to be removed must be empty, or contain only
  +other directories that have been also selected to be removed by the filesets
  +patterns, otherwise a BuildException will be thrown.
  +Also, if you don't have permission to remove a directory, a BuildException is 
  +thrown.
  +
  +<pre>
  +  &lt;ftp action=&quot;rmdir&quot;
  +       server=&quot;ftp.apache.org&quot;
  +       userid=&quot;anonymous&quot;
  +       password=&quot;me@myorg.com&quot; 
  +       remotedir=&quot;/somedir&quot; &gt;
  +    &lt;fileset&gt;
  +      &lt;include name=&quot;dira&quot;/&gt;
  +      &lt;include name=&quot;dirb/**&quot;/&gt;
  +    &lt;/fileset&gt;
  +  &lt;/ftp&gt;
  +</pre>
  +<p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code>
and
  +tries to remove <code>/somedir/dira</code> directory and
  +all the directories tree starting at, and including, <code>/somedir/dirb</code>.
  +When removing the <code>/somedir/dirb</code> tree,
  +it will start at the leaves moving up to the root, so that when
  +it tries to remove a directory it is sure all the directories under it are
  +already removed.
  +Obviuosly all the files in the tree must have been already deleted.
  +</p>
  +<p>As an example suppose you want to delete everything contained into 
  +<code>/somedir</code>, so invoke first the <code>&lt;ftp&gt;</code>
task with
  +<code>action=&quot;delete&quot;</code>, then with 
  +<code>action=&quot;rmdir&quot;</code> specifying in both cases
  +<code>remotedir=&quot;/somedir&quot;</code> and
  +
  +<pre>
  +    &lt;fileset&gt;
  +        &lt;include name=&quot;**&quot;/&gt;
  +    &lt;/fileset&gt;
  +</pre>
  +
  +The directory specified in the <code>remotedir</code> parameter is never
  +selected for remove, so if you need to remove it, specify its parent in
  +<code>remotedir</code> parameter and include it in the 
  +<code>&lt;fileset&gt;</code> pattern, like <code>&quot;somedir/**&quot;</code>.
  +</p>
   <hr>
   <p align="center">Copyright &copy; 2000-2002 Apache Software Foundation. All
rights
   Reserved.</p>
  
  
  
  1.28      +64 -10    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
  
  Index: FTP.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- FTP.java	23 Sep 2002 15:47:56 -0000	1.27
  +++ FTP.java	23 Sep 2002 16:01:43 -0000	1.28
  @@ -86,6 +86,8 @@
    *   <li> <strong>del</strong> - delete files from a remote server.</li>
    *   <li> <strong>list</strong> - create a file listing.</li>
    *   <li> <strong>chmod</strong> - change unix file permissions.</li>
  + *   <li> <strong>rmdir</strong> - remove directories, if empty, from
a 
  + *   remote server.</li>
    * </ul>
    * <strong>Note:</strong> Some FTP servers - notably the Solaris server - seem
    * to hold data ports open after a "retr" operation, allowing them to timeout
  @@ -109,6 +111,7 @@
       protected static final int LIST_FILES = 3;
       protected static final int MK_DIR = 4;
       protected static final int CHMOD = 5;
  +    protected static final int RM_DIR = 6;
   
       private String remotedir;
       private String server;
  @@ -139,7 +142,8 @@
           "deleting",
           "listing",
           "making directory",
  -        "chmod"
  +        "chmod",
  +        "removing"
           };
   
       protected static final String[] COMPLETED_ACTION_STRS = {
  @@ -148,7 +152,18 @@
           "deleted",
           "listed",
           "created directory",
  -        "mode changed"
  +        "mode changed",
  +        "removed"
  +        };
  +
  +    protected static final String[] ACTION_TARGET_STRS = {
  +        "files",
  +        "files",
  +        "files",
  +        "files",
  +        "directory",
  +        "files",
  +        "directories"
           };
   
   
  @@ -212,11 +227,11 @@
                               String name = vpath + file.getName();
                               if (isIncluded(name)) {
                                   if (!isExcluded(name)) {
  -                                    dirsIncluded.addElement(name);
                                       if (fast) {
                                           scandir(file.getName(),
                                                   name + File.separator, fast);
                                       }
  +                                    dirsIncluded.addElement(name);
                                   } else {
                                       dirsExcluded.addElement(name);
                                       if (fast && couldHoldIncluded(name)) {
  @@ -486,7 +501,12 @@
               ds.scan();
           }
   
  -        String[] dsfiles = ds.getIncludedFiles();
  +        String[] dsfiles = null;
  +        if (action == RM_DIR) {
  +            dsfiles = ds.getIncludedDirectories();
  +        } else {
  +            dsfiles = ds.getIncludedFiles();
  +        }
           String dir = null;
   
           if ((ds.getBasedir() == null)
  @@ -545,6 +565,12 @@
                           break;
                       }
   
  +                    case RM_DIR:
  +                    {
  +                        rmDir(ftp, dsfiles[i]);
  +                        break;
  +                    }
  +
                       default:
                       {
                           throw new BuildException("unknown ftp action " + action);
  @@ -583,10 +609,12 @@
               }
           }
   
  -        log(transferred + " files " + COMPLETED_ACTION_STRS[action]);
  +        log(transferred + " " + ACTION_TARGET_STRS[action] + " " +
  +                                COMPLETED_ACTION_STRS[action]);
           if (skipped != 0) {
  -            log(skipped + " files were not successfully "
  -                 + COMPLETED_ACTION_STRS[action]);
  +            log(skipped + " " + ACTION_TARGET_STRS[action] + 
  +                                " were not successfully "
  +                + COMPLETED_ACTION_STRS[action]);
           }
       }
   
  @@ -783,6 +811,29 @@
           }
       }
   
  +    /** Delete a directory, if empty, from the remote host.  */
  +    protected void rmDir(FTPClient ftp, String dirname)
  +         throws IOException, BuildException {
  +        if (verbose) {
  +            log("removing " + dirname);
  +        }
  +
  +        if (!ftp.removeDirectory(resolveFile(dirname))) {
  +            String s = "could not remove directory: " + ftp.getReplyString();
  +
  +            if (skipFailedTransfers == true) {
  +                log(s, Project.MSG_WARN);
  +                skipped++;
  +            } else {
  +                throw new BuildException(s);
  +            }
  +        } else {
  +            log("Directory " + dirname + " removed from " + server,
  +                Project.MSG_VERBOSE);
  +            transferred++;
  +        }
  +    }
  +
   
       /**
        * Retrieve a single file to the remote host. <code>filename</code> may
  @@ -991,7 +1042,7 @@
                               ftp.getReplyString());
                       }
                   }
  -                log(ACTION_STRS[action] + " files");
  +                log(ACTION_STRS[action] + " " + ACTION_TARGET_STRS[action]);
                   transferFiles(ftp);
               }
   
  @@ -1013,13 +1064,14 @@
   
       /**
        * an action to perform, one of
  -     * "send", "put", "recv", "get", "del", "delete", "list", "mkdir", "chmod"
  +     * "send", "put", "recv", "get", "del", "delete", "list", "mkdir", "chmod",
  +     * "rmdir"
        */
       public static class Action extends EnumeratedAttribute {
   
           private static final String[] validActions = {
               "send", "put", "recv", "get", "del", "delete", "list", "mkdir",
  -            "chmod"
  +            "chmod", "rmdir"
               };
   
   
  @@ -1046,6 +1098,8 @@
                   return CHMOD;
               } else if (actionL.equals("mkdir")) {
                   return MK_DIR;
  +            } else if (actionL.equals("rmdir")) {
  +                return RM_DIR;
               }
               return SEND_FILES;
           }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message