Browse Source

Add FTPConfigurator class so as to avoid forcing users to upgrade to version 1.4.0 of commons-net.


			
			master
		
Steven M. Cohen 20 years ago
parent
commit
813c248227
3 changed files with 139 additions and 38 deletions
  1. +3
    -1
      docs/manual/install.html
  2. +48
    -37
      src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
  3. +88
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/net/FTPConfigurator.java

+ 3
- 1
docs/manual/install.html View File

@@ -425,7 +425,9 @@ you need jakarta-oro 2.0.1 or later, and <a href="#commons-net">commons-net</a><
<td><a name="commons-net">commons-net.jar</td> <td><a name="commons-net">commons-net.jar</td>
<td>ftp, rexec and telnet tasks<br> <td>ftp, rexec and telnet tasks<br>
jakarta-oro 2.0.1 or later is required in any case together with commons-net.<br> jakarta-oro 2.0.1 or later is required in any case together with commons-net.<br>
For all users, a minimum version of commons-net of 1.4.0 is now required.
For all users, a minimum version of commons-net of 1.4.0 is recommended. Earlier
versions did not support the full range of configuration options, and 1.4.0 is needed
to compile Ant.
</td> </td>
<td><a href="http://jakarta.apache.org/commons/net/index.html" <td><a href="http://jakarta.apache.org/commons/net/index.html"
target="_top">http://jakarta.apache.org/commons/net/index.html</a></td> target="_top">http://jakarta.apache.org/commons/net/index.html</a></td>


+ 48
- 37
src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java View File

@@ -17,7 +17,6 @@
package org.apache.tools.ant.taskdefs.optional.net; package org.apache.tools.ant.taskdefs.optional.net;


import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPClientConfig;
import org.apache.commons.net.ftp.FTPFile; import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply; import org.apache.commons.net.ftp.FTPReply;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
@@ -1322,12 +1321,48 @@ public class FTP
} }




/**
* @return Returns the systemKeyConfig.
*/
String getSystemKeyConfig() {
return systemKeyConfig;
}
/**
* @return Returns the defaultDateFormatConfig.
*/
String getDefaultDateFormatConfig() {
return defaultDateFormatConfig;
}
/**
* @return Returns the recentDateFormatConfig.
*/
String getRecentDateFormatConfig() {
return recentDateFormatConfig;
}
/**
* @return Returns the serverLanguageCodeConfig.
*/
String getServerLanguageCodeConfig() {
return serverLanguageCodeConfig;
}
/**
* @return Returns the serverTimeZoneConfig.
*/
String getServerTimeZoneConfig() {
return serverTimeZoneConfig;
}
/**
* @return Returns the shortMonthNamesConfig.
*/
String getShortMonthNamesConfig() {
return shortMonthNamesConfig;
}
/** /**
* Checks to see that all required parameters are set. * Checks to see that all required parameters are set.
* *
* @throws BuildException if the configuration is not valid. * @throws BuildException if the configuration is not valid.
*/ */
protected void checkConfiguration() throws BuildException {
protected void checkAttributes() throws BuildException {
if (server == null) { if (server == null) {
throw new BuildException("server attribute must be set!"); throw new BuildException("server attribute must be set!");
} }
@@ -1352,6 +1387,15 @@ public class FTP
throw new BuildException("chmod attribute must be set for chmod " throw new BuildException("chmod attribute must be set for chmod "
+ "action!"); + "action!");
} }
if (this.isConfigurationSet) {
try {
Class.forName("org.apache.commons.net.ftp.FTPClientConfig");
} catch (ClassNotFoundException e) {
throw new BuildException(
"commons-net.jar >= 1.4.0 is required for at least one of the attributes specified.");
}
}
} }




@@ -2025,40 +2069,7 @@ public class FTP


private void configure(FTPClient ftp) { private void configure(FTPClient ftp) {
if (this.isConfigurationSet) { if (this.isConfigurationSet) {
FTPClientConfig config;
if (this.systemKeyConfig != null) {
config = new FTPClientConfig(this.systemKeyConfig);
log("custom config: system key = "
+ this.systemKeyConfig, Project.MSG_VERBOSE);
} else {
config = new FTPClientConfig();
}
if (this.defaultDateFormatConfig != null) {
config.setDefaultDateFormatStr(this.defaultDateFormatConfig);
log("custom config: default date format = "
+ this.defaultDateFormatConfig, Project.MSG_VERBOSE);
}
if (this.recentDateFormatConfig != null) {
config.setRecentDateFormatStr(this.recentDateFormatConfig);
log("custom config: recent date format = "
+ this.recentDateFormatConfig, Project.MSG_VERBOSE);
}
if (this.serverLanguageCodeConfig != null) {
config.setServerLanguageCode(this.serverLanguageCodeConfig);
log("custom config: server language code = "
+ this.serverLanguageCodeConfig, Project.MSG_VERBOSE);
}
if (this.serverTimeZoneConfig != null) {
config.setServerTimeZoneId(this.serverTimeZoneConfig);
log("custom config: server time zone ID = "
+ this.serverTimeZoneConfig, Project.MSG_VERBOSE);
}
if (this.shortMonthNamesConfig != null) {
config.setShortMonthNames(this.shortMonthNamesConfig);
log("custom config: short month names = "
+ this.shortMonthNamesConfig, Project.MSG_VERBOSE);
}
ftp.configure(config);
FTPConfigurator.configure(ftp, this);
} }
} }


@@ -2069,7 +2080,7 @@ public class FTP
* correctly. * correctly.
*/ */
public void execute() throws BuildException { public void execute() throws BuildException {
checkConfiguration();
checkAttributes();


FTPClient ftp = null; FTPClient ftp = null;




+ 88
- 0
src/main/org/apache/tools/ant/taskdefs/optional/net/FTPConfigurator.java View File

@@ -0,0 +1,88 @@
/*
* Copyright 2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.tools.ant.taskdefs.optional.net;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPClientConfig;
import org.apache.tools.ant.Project;

/**
* The sole purpose of this class is (note that it is package-private
* is to serve as a separate, static compilation unit for importing
* FTPClientConfig, to enable users who wish to use the FTP task
* without using its new features to avoid the need to
* upgrade to jakarta-commons-net 1.4.0, where FTPClientConfig was
* introduced.
*/
class FTPConfigurator {
/**
* configures the supplied FTPClient with the various
* attributes set in the supplied FTP task.
* @param client the FTPClient to be configured
* @param task the FTP task whose attributes are used to
* configure the client
* @return the client as configured.
*/
static FTPClient configure(FTPClient client, FTP task) {
FTPClientConfig config;
String systemKeyConfig = task.getSystemKeyConfig();
if (systemKeyConfig != null) {
config = new FTPClientConfig(systemKeyConfig);
task.log("custom config: system key = "
+ systemKeyConfig, Project.MSG_VERBOSE);
} else {
config = new FTPClientConfig();
}
String defaultDateFormatConfig = task.getDefaultDateFormatConfig();
if (defaultDateFormatConfig != null) {
config.setDefaultDateFormatStr(defaultDateFormatConfig);
task.log("custom config: default date format = "
+ defaultDateFormatConfig, Project.MSG_VERBOSE);
}
String recentDateFormatConfig = task.getRecentDateFormatConfig();
if (recentDateFormatConfig != null) {
config.setRecentDateFormatStr(recentDateFormatConfig);
task.log("custom config: recent date format = "
+ recentDateFormatConfig, Project.MSG_VERBOSE);
}
String serverLanguageCodeConfig = task.getServerLanguageCodeConfig();
if (serverLanguageCodeConfig != null) {
config.setServerLanguageCode(serverLanguageCodeConfig);
task.log("custom config: server language code = "
+ serverLanguageCodeConfig, Project.MSG_VERBOSE);
}
String serverTimeZoneConfig = task.getServerTimeZoneConfig();
if (serverTimeZoneConfig != null) {
config.setServerTimeZoneId(serverTimeZoneConfig);
task.log("custom config: server time zone ID = "
+ serverTimeZoneConfig, Project.MSG_VERBOSE);
}
String shortMonthNamesConfig = task.getShortMonthNamesConfig();
if (shortMonthNamesConfig != null) {
config.setShortMonthNames(shortMonthNamesConfig);
task.log("custom config: short month names = "
+ shortMonthNamesConfig, Project.MSG_VERBOSE);
}
client.configure(config);
return client;
}
}

Loading…
Cancel
Save