scohen 2005/05/28 20:01:10
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
Log:
convert serverLanguageCodeConfig attribute to use EnumeratedAttribute pattern
Revision Changes Path
1.18 +21 -5
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.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- FTPTest.java 28 May 2005 17:05:44 -0000 1.17
+++ FTPTest.java 29 May 2005 03:01:10 -0000 1.18
@@ -25,6 +25,7 @@
import org.apache.commons.net.ftp.FTPClient;
import org.apache.tools.ant.BuildEvent;
+import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildFileTest;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.DirectoryScanner;
@@ -661,7 +662,7 @@
*/
public void testConfiguration1() {
int[] expectedCounts = {
- 1,1,0,1,0,0
+ 1,1,0,1,0,0,0
};
performConfigTest("configuration.1", expectedCounts);
@@ -672,7 +673,7 @@
*/
public void testConfiguration2() {
int[] expectedCounts = {
- 1,0,0,1,1,0
+ 1,0,0,1,1,0,0
};
performConfigTest("configuration.2", expectedCounts);
@@ -683,17 +684,31 @@
*/
public void testConfiguration3() {
int[] expectedCounts = {
- 1,0,1,0,0,1
+ 1,0,1,0,0,1,0
};
performConfigTest("configuration.3", expectedCounts);
}
+
+ public void testConfigurationLang() {
+ int[] expectedCounts = {
+ 1,1,0,0,0,0,1
+ };
+ performConfigTest("configuration.lang.good", expectedCounts);
+
+ try {
+ performConfigTest("configuration.lang.bad", expectedCounts);
+ fail("BuildException Expected");
+ } catch (Exception bx) {
+ assertTrue(bx instanceof BuildException);
+ }
+ }
/**
* Tests the systemTypeKey attribute.
*/
public void testConfigurationNone() {
int[] expectedCounts = {
- 0,0,0,0,0,0
+ 0,0,0,0,0,0,0
};
performConfigTest("configuration.none", expectedCounts);
@@ -706,7 +721,8 @@
"custom config: system key = UNIX",
"custom config: server time zone ID = " +
getProject().getProperty("ftp.server.timezone"),
"custom config: system key = WINDOWS",
- "custom config: default date format = yyyy/MM/dd HH:mm"
+ "custom config: default date format = yyyy/MM/dd HH:mm",
+ "custom config: server language code = de"
};
LogCounter counter = new LogCounter();
1.76 +42 -7
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.75
retrieving revision 1.76
diff -u -r1.75 -r1.76
--- FTP.java 28 May 2005 17:05:44 -0000 1.75
+++ FTP.java 29 May 2005 03:01:10 -0000 1.76
@@ -16,9 +16,6 @@
*/
package org.apache.tools.ant.taskdefs.optional.net;
-import org.apache.commons.net.ftp.FTPClient;
-import org.apache.commons.net.ftp.FTPFile;
-import org.apache.commons.net.ftp.FTPReply;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
@@ -29,16 +26,22 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
-import java.util.Hashtable;
import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.Vector;
+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.FTPReply;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
@@ -118,7 +121,7 @@
private FTPSystemType systemTypeKey = FTPSystemType.getDefault();
private String defaultDateFormatConfig = null;
private String recentDateFormatConfig = null;
- private String serverLanguageCodeConfig = null;
+ private LanguageCode serverLanguageCodeConfig =
LanguageCode.getDefault();
private String serverTimeZoneConfig = null;
private String shortMonthNamesConfig = null;
private Granularity timestampGranularity = Granularity.getDefault();
@@ -1316,7 +1319,7 @@
* null or empty string, in which case ignored.
* @see org.apache.commons.net.ftp.FTPClientConfig
*/
- public void setServerLanguageCodeConfig(String serverLanguageCode) {
+ public void setServerLanguageCodeConfig(LanguageCode serverLanguageCode)
{
if (serverLanguageCode != null && !serverLanguageCode.equals(""))
{
this.serverLanguageCodeConfig = serverLanguageCode;
@@ -1379,7 +1382,7 @@
* @return Returns the serverLanguageCodeConfig.
*/
String getServerLanguageCodeConfig() {
- return serverLanguageCodeConfig;
+ return serverLanguageCodeConfig.getValue();
}
/**
* @return Returns the serverTimeZoneConfig.
@@ -2358,5 +2361,37 @@
return ftpst;
}
}
+ public static class LanguageCode extends EnumeratedAttribute {
+
+
+ private static final String[] VALID_LANGUAGE_CODES =
+ getValidLanguageCodes();
+
+ private static final String[] getValidLanguageCodes() {
+ Collection c = FTPClientConfig.getSupportedLanguageCodes();
+ String[] ret = new String[c.size() + 1];
+ int i = 0;
+ ret[i++] = "";
+ for (Iterator it = c.iterator(); it.hasNext(); i++) {
+ ret[i] = (String) it.next();
+ }
+ return ret;
+ }
+
+
+ /*
+ * @return the list of valid system types.
+ */
+ public String[] getValues() {
+ return VALID_LANGUAGE_CODES;
+ }
+
+ static final LanguageCode getDefault() {
+ LanguageCode lc = new LanguageCode();
+ lc.setValue("");
+ return lc;
+ }
+ }
+
}
1.12 +26 -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.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ftp.xml 28 May 2005 17:05:44 -0000 1.11
+++ ftp.xml 29 May 2005 03:01:10 -0000 1.12
@@ -234,6 +234,32 @@
<fileset dir="${tmp.local}"/>
</ftp>
</target>
+ <target name="configuration.lang.good">
+ <ftp action="list"
+ server="${ftp.host}"
+ userid="${ftp.user}"
+ password="${ftp.password}"
+ separator="${ftp.filesep}"
+ remotedir="${tmp.remote}"
+ serverLanguageCodeConfig="de"
+ listing="${ftp.listing.file}"
+ >
+ <fileset dir="${tmp.local}"/>
+ </ftp>
+ </target>
+ <target name="configuration.lang.bad">
+ <ftp action="list"
+ server="${ftp.host}"
+ userid="${ftp.user}"
+ password="${ftp.password}"
+ separator="${ftp.filesep}"
+ remotedir="${tmp.remote}"
+ serverLanguageCodeConfig="QQ"
+ listing="${ftp.listing.file}"
+ >
+ <fileset dir="${tmp.local}"/>
+ </ftp>
+ </target>
<target name="configuration.none">
<ftp action="list"
server="${ftp.host}"
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]