ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sco...@apache.org
Subject cvs commit: ant/docs/manual/OptionalTasks ftp.html
Date Mon, 30 May 2005 14:41:34 GMT
scohen      2005/05/30 07:41:34

  Modified:    src/testcases/org/apache/tools/ant/taskdefs/optional/net
                        FTPTest.java
               src/main/org/apache/tools/ant/taskdefs/optional/net FTP.java
               src/etc/testcases/taskdefs/optional/net ftp.xml
               docs/manual/OptionalTasks ftp.html
  Log:
  Add initialSiteCommand and siteCommand attributes.
  PR:34257, 34853
  
  Revision  Changes    Path
  1.21      +26 -0     ant/src/testcases/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java
  
  Index: FTPTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- FTPTest.java	30 May 2005 02:18:39 -0000	1.20
  +++ FTPTest.java	30 May 2005 14:41:34 -0000	1.21
  @@ -866,5 +866,31 @@
               fail("Retry forever specified, but failed.");
           }
       }
  +    
  +    public void testInitialCommand() {
  +        performCommandTest("test-initial-command", new int[] { 1,0 });
  +    }
  +    public void testSiteAction() {
  +        performCommandTest("test-site-action", new int[] { 1,0 });
  +    }
  +    
  +    private void performCommandTest(String target, int[] expectedCounts) {
  +        String[] messages = new String[]{
  +                "Doing Site Command: umask 222",
  +                "Failed to issue Site Command: umask 222",
   
  +        };
  +        LogCounter counter = new LogCounter();
  +        for (int i=0; i < messages.length; i++) {
  +            counter.addLogMessageToSearch(messages[i]);
  +        }
  +            
  +        getProject().addBuildListener(counter);
  +        getProject().executeTarget(target);
  +        for (int i=0; i < messages.length; i++) {
  +            assertEquals("target "+target+":message "+ i, expectedCounts[i], counter.getMatchCount(messages[i]));
  +        }
  +
  +    }
  +    
   }
  
  
  
  1.78      +77 -24    ant/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
  
  Index: FTP.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java,v
  retrieving revision 1.77
  retrieving revision 1.78
  diff -u -r1.77 -r1.78
  --- FTP.java	30 May 2005 00:40:20 -0000	1.77
  +++ FTP.java	30 May 2005 14:41:34 -0000	1.78
  @@ -84,6 +84,7 @@
       protected static final int MK_DIR = 4;
       protected static final int CHMOD = 5;
       protected static final int RM_DIR = 6;
  +    protected static final int SITE_CMD = 7;
       /** return code of ftp - not implemented in commons-net version 1.0 */
       private static final int CODE_521 = 521;
       
  @@ -129,6 +130,8 @@
       private Granularity timestampGranularity = Granularity.getDefault();
       private boolean isConfigurationSet = false;
       private int retriesAllowed = 0;
  +    private String siteCommand = null;
  +    private String initialSiteCommand = null;
   
       protected static final String[] ACTION_STRS = {
           "sending",
  @@ -137,7 +140,8 @@
           "listing",
           "making directory",
           "chmod",
  -        "removing"
  +        "removing",
  +        "site"
           };
   
       protected static final String[] COMPLETED_ACTION_STRS = {
  @@ -147,7 +151,8 @@
           "listed",
           "created directory",
           "mode changed",
  -        "removed"
  +        "removed",
  +        "site command executed"
           };
   
       protected static final String[] ACTION_TARGET_STRS = {
  @@ -157,7 +162,8 @@
           "files",
           "directory",
           "files",
  -        "directories"
  +        "directories",
  +        "site command"
           };
   
   
  @@ -1193,7 +1199,7 @@
   
       /**
        * Sets the FTP action to be taken. Currently accepts "put", "get", "del",
  -     * "mkdir" and "list".
  +     * "mkdir", "chmod", "list", and "site".
        *
        * @deprecated setAction(String) is deprecated and is replaced with
        *      setAction(FTP.Action) to make Ant's Introspection mechanism do the
  @@ -1218,7 +1224,7 @@
   
       /**
        * Sets the FTP action to be taken. Currently accepts "put", "get", "del",
  -     * "mkdir", "chmod" and "list".
  +     * "mkdir", "chmod", "list", and "site".
        *
        * @param action the FTP action to be performed.
        *
  @@ -1268,10 +1274,11 @@
       }
   
       /**
  +     * Sets the systemTypeKey attribute.
        * Method for setting <code>FTPClientConfig</code> remote system key.
        * 
        * @param systemTypeKey the key to be set - BUT if blank 
  -     * the default value of null will be kept.
  +     * the default value of null (which signifies "autodetect") will be kept.
        * @see org.apache.commons.net.ftp.FTPClientConfig
        */
       public void setSystemTypeKey(FTPSystemType systemKey) {
  @@ -1283,9 +1290,7 @@
       }
   
       /**
  -     * Delegate method for
  -     * <code>FTPClientConfig.setDefaultDateFormatStr(String)</code>.
  -     * 
  +     * Sets the defaultDateFormatConfig attribute.
        * @param defaultDateFormatConfig configuration to be set, unless it is
        * null or empty string, in which case ignored.
        * @see org.apache.commons.net.ftp.FTPClientConfig
  @@ -1299,9 +1304,7 @@
       }
   
       /**
  -     * Delegate method for
  -     * <code>FTPClientConfig.setRecentDateFormatStr(String)</code>.
  -     * 
  +     * Sets the recentDateFormatConfig attribute.
        * @param recentDateFormatConfig configuration to be set, unless it is
        * null or empty string, in which case ignored.
        * @see org.apache.commons.net.ftp.FTPClientConfig
  @@ -1315,9 +1318,7 @@
       }
   
       /**
  -     * Delegate method for
  -     * <code>FTPClientConfig.setServerLanguageCode(String)</code>.
  -     * 
  +     * Sets the serverLanguageCode attribute.
        * @param serverLanguageCodeConfig configuration to be set, unless it is
        * null or empty string, in which case ignored.
        * @see org.apache.commons.net.ftp.FTPClientConfig
  @@ -1331,9 +1332,7 @@
       }
   
       /**
  -     * Delegate method for
  -     * <code>FTPClientConfig.setServerTimeZoneId(String)</code>.
  -     * 
  +     * Sets the serverTimeZoneConfig attribute.
        * @param serverTimeZoneConfig configuration to be set, unless it is
        * null or empty string, in which case ignored.
        * @see org.apache.commons.net.ftp.FTPClientConfig
  @@ -1347,8 +1346,7 @@
       }
   
       /**
  -     * Delegate method for
  -     * <code>FTPClientConfig.setShortMonthNames(String)</code>.
  +     * Sets the shortMonthNamesConfig attribute
        * 
        * @param shortMonthNamesConfig configuration to be set, unless it is
        * null or empty string, in which case ignored.
  @@ -1437,6 +1435,7 @@
           return timestampGranularity;
       }
       /**
  +     * Sets the timestampGranularity attribute
        * @param timestampGranularity The timestampGranularity to set.
        */
       public void setTimestampGranularity(Granularity timestampGranularity) {
  @@ -1446,6 +1445,24 @@
           this.timestampGranularity = timestampGranularity;
        }
       /**
  +     * Sets the siteCommand attribute.  This attribute
  +     * names the command that will be executed if the action
  +     * is "site".
  +     * @param siteCommand The siteCommand to set.
  +     */
  +    public void setSiteCommand(String siteCommand) {
  +        this.siteCommand = siteCommand;
  +    }
  +    /**
  +     * Sets the initialSiteCommand attribute.  This attribute
  +     * names a site command that will be executed immediately
  +     * after connection. 
  +     * @param initialSiteCommand The initialSiteCommand to set.
  +     */
  +    public void setInitialSiteCommand(String initialCommand) {
  +        this.initialSiteCommand = initialCommand;
  +    }
  +    /**
        * Checks to see that all required parameters are set.
        *
        * @throws BuildException if the configuration is not valid.
  @@ -1475,6 +1492,11 @@
               throw new BuildException("chmod attribute must be set for chmod "
                    + "action!");
           }
  +        if (action == SITE_CMD && siteCommand == null) {
  +            throw new BuildException("sitecommand attribute must be set for site "
  +                 + "action!");
  +        }
  +
           
           if (this.isConfigurationSet) {
               try {
  @@ -1486,10 +1508,10 @@
           }
       }
       
  -    protected void executeRetryable(RetryHandler h, Retryable r, String filename) 
  +    protected void executeRetryable(RetryHandler h, Retryable r, String descr) 
       throws IOException
       {
  -        h.execute(r, filename);
  +        h.execute(r, descr);
       }
   
   
  @@ -2239,12 +2261,33 @@
                            + "mode: " + ftp.getReplyString());
                   }
               }
  +            
  +            // If an initial command was configured then send it.
  +            // Some FTP servers offer different modes of operation,
  +            // E.G. switching between a UNIX file system mode and
  +            // a legacy file system.
  +            if (this.initialSiteCommand != null) {
  +                RetryHandler h = new RetryHandler(this.retriesAllowed, this);
  +                final FTPClient lftp = ftp;
  +                executeRetryable(h, new Retryable() {
  +                    public void execute() throws IOException {
  +                        doSiteCommand(lftp, FTP.this.initialSiteCommand);
  +                    }
  +                }, "initial site command: "+ this.initialSiteCommand);
  +            }
  +
   
               // For a unix ftp server you can set the default mask for all files
               // created.
   
               if (umask != null) {
  -                doSiteCommand(ftp, "umask " + umask);
  +                RetryHandler h = new RetryHandler(this.retriesAllowed, this);
  +                final FTPClient lftp = ftp;
  +                executeRetryable(h, new Retryable() {
  +                    public void execute() throws IOException {
  +                        doSiteCommand(lftp, "umask " + umask);
  +                    }
  +                }, "umask " + umask);
               }
   
               // If the action is MK_DIR, then the specified remote
  @@ -2258,6 +2301,14 @@
                           makeRemoteDir(lftp, remotedir);
                       }
                   }, remotedir);
  +            } else if (action == SITE_CMD) {
  +                    RetryHandler h = new RetryHandler(this.retriesAllowed, this);
  +                    final FTPClient lftp = ftp;
  +                    executeRetryable(h, new Retryable() {
  +                        public void execute() throws IOException {
  +                            doSiteCommand(lftp, FTP.this.siteCommand);
  +                        }
  +                    }, "Site Command: " + this.siteCommand);
               } else {
                   if (remotedir != null) {
                       log("changing the remote directory", Project.MSG_VERBOSE);
  @@ -2301,7 +2352,7 @@
   
           private static final String[] VALID_ACTIONS = {
               "send", "put", "recv", "get", "del", "delete", "list", "mkdir",
  -            "chmod", "rmdir"
  +            "chmod", "rmdir", "site"
               };
   
   
  @@ -2337,6 +2388,8 @@
                   return MK_DIR;
               } else if (actionL.equals("rmdir")) {
                   return RM_DIR;
  +            } else if (actionL.equals("site")) {
  +                return SITE_CMD;
               }
               return SEND_FILES;
           }
  
  
  
  1.14      +25 -0     ant/src/etc/testcases/taskdefs/optional/net/ftp.xml
  
  Index: ftp.xml
  ===================================================================
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/optional/net/ftp.xml,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ftp.xml	30 May 2005 00:40:20 -0000	1.13
  +++ ftp.xml	30 May 2005 14:41:34 -0000	1.14
  @@ -285,5 +285,30 @@
               <fileset refid="fileset-destination-with-selector"/>
           </ftp>
       </target>
  +    <target name="test-initial-command">
  +        <ftp action="put"
  +            server="${ftp.host}"
  +            userid="${ftp.user}"
  +            password="${ftp.password}"
  +            separator="${ftp.filesep}"
  +            remotedir="${tmp.remote}"
  +            initialSiteCommand="umask 222"
  +            >
  +            <fileset dir="${tmp.local}">
  +                <patternset refid="timed-test-files"/>
  +            </fileset>
  +        </ftp>
  +    </target>
   
  +    <target name="test-site-action">
  +        <ftp action="site"
  +            server="${ftp.host}"
  +            userid="${ftp.user}"
  +            password="${ftp.password}"
  +            separator="${ftp.filesep}"
  +            remotedir="${tmp.remote}"
  +            siteCommand="umask 222"
  +            >
  +        </ftp>
  +    </target>
   </project>
  \ No newline at end of file
  
  
  
  1.38      +13 -1     ant/docs/manual/OptionalTasks/ftp.html
  
  Index: ftp.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/OptionalTasks/ftp.html,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- ftp.html	30 May 2005 00:40:21 -0000	1.37
  +++ ftp.html	30 May 2005 14:41:34 -0000	1.38
  @@ -77,7 +77,7 @@
       <td valign="top">the ftp action to perform, defaulting to "send".
                        Currently supports "put", "get",
                        "del", "list", "chmod",
  -                     "mkdir" and "rmdir".</td>
  +                     "mkdir", "rmdir", and "site".</td>
       <td valign="top" align="center">No</td>
     </tr>
     <tr>
  @@ -200,6 +200,18 @@
       operation will keep trying until it succeeds.</td>
       <td valign="top" align="center">No; defaults to 0</td>
     </tr>
  +  <tr>
  +    <td valign="top">siteCommand</td>
  +    <td valign="top">Set the server-specific SITE command to execute if
  +    the <code>action</code> attribute has been specified as <code>"site"</code>.
  +    <td valign="top" align="center">No</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">initialSiteCommand</td>
  +    <td valign="top">Set a server-specific SITE command to execute immediately
  +    after login.
  +    <td valign="top" align="center">No</td>
  +  </tr>
   
       <tr>
       <td colspan="3">
  
  
  

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


Mime
View raw message