The biggest outstanding JDK 1.3 code is in Locator but I am scared to touch it. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@808156 13f79535-47bb-0310-9956-ffa450edef68master
@@ -69,13 +69,14 @@ public class RuntimeConfigurable implements Serializable { | |||||
* exact order. The following code is copied from AttributeImpl. | * exact order. The following code is copied from AttributeImpl. | ||||
* We could also just use SAX2 Attributes and convert to SAX1 ( DOM | * We could also just use SAX2 Attributes and convert to SAX1 ( DOM | ||||
* attribute Nodes can also be stored in SAX2 Attributes ) | * attribute Nodes can also be stored in SAX2 Attributes ) | ||||
* XXX under JDK 1.4 you can just use a LinkedHashMap for this purpose -jglick | |||||
* The only exception to this order is the treatment of | * The only exception to this order is the treatment of | ||||
* refid. A number of datatypes check if refid is set | * refid. A number of datatypes check if refid is set | ||||
* when other attributes are set. This check will not | * when other attributes are set. This check will not | ||||
* work if the build script has the other attribute before | * work if the build script has the other attribute before | ||||
* the "refid" attribute, so now (ANT 1.7) the refid | * the "refid" attribute, so now (ANT 1.7) the refid | ||||
* attribute will be processed first. | * attribute will be processed first. | ||||
* (Other than treatment of refid, could just use a LinkedHashMap, | |||||
* but peterreilly's rev 452635 includes no regression test.) | |||||
*/ | */ | ||||
private List/*<String>*/ attributeNames = null; | private List/*<String>*/ attributeNames = null; | ||||
@@ -165,7 +165,7 @@ public final class Locator { | |||||
* | * | ||||
* <p>Will be an absolute path if the given URI is absolute.</p> | * <p>Will be an absolute path if the given URI is absolute.</p> | ||||
* | * | ||||
* <p>Prior to Java 1.4, | |||||
* <p>Prior to Java 1.4,<!-- XXX is JDK version actually relevant? --> | |||||
* swallows '%' that are not followed by two characters.</p> | * swallows '%' that are not followed by two characters.</p> | ||||
* | * | ||||
* See <a href="http://www.w3.org/TR/xml11/#dt-sysid">dt-sysid</a> | * See <a href="http://www.w3.org/TR/xml11/#dt-sysid">dt-sysid</a> | ||||
@@ -178,76 +178,55 @@ public final class Locator { | |||||
* @since Ant 1.6 | * @since Ant 1.6 | ||||
*/ | */ | ||||
public static String fromURI(String uri) { | public static String fromURI(String uri) { | ||||
return fromURIJava13(uri); | |||||
// #buzilla8031: first try Java 1.4. | // #buzilla8031: first try Java 1.4. | ||||
String result = null; | |||||
//result = fromUriJava14(uri); | |||||
if (result == null) { | |||||
result = fromURIJava13(uri); | |||||
} | |||||
return result; | |||||
// XXX should use java.net.URI now that we can rely on 1.4... | |||||
// but check for UNC-related regressions, e.g. #42275 | |||||
// (and remember that \\server\share\file -> file:////server/share/file | |||||
// rather than -> file://server/share/file as it should; | |||||
// fixed only in JDK 7's java.nio.file.Path.toUri) | |||||
// return fromUriJava14(uri); | |||||
} | } | ||||
/** | /** | ||||
* Java1.4+ code to extract the path from the URI. | * Java1.4+ code to extract the path from the URI. | ||||
* @param uri | * @param uri | ||||
* @return null if a conversion was not possible | * @return null if a conversion was not possible | ||||
*/ | */ | ||||
/* currently unused: | |||||
private static String fromUriJava14(String uri) { | private static String fromUriJava14(String uri) { | ||||
Class uriClazz = null; | |||||
try { | |||||
uriClazz = Class.forName("java.net.URI"); | |||||
} catch (ClassNotFoundException cnfe) { | |||||
// Fine, Java 1.3 or earlier, do it by hand. | |||||
return null; | |||||
} | |||||
// Also check for properly formed URIs. Ant formerly recommended using | // Also check for properly formed URIs. Ant formerly recommended using | ||||
// nonsense URIs such as "file:./foo.xml" in XML includes. You shouldn't | // nonsense URIs such as "file:./foo.xml" in XML includes. You shouldn't | ||||
// do that (just "foo.xml" is correct) but for compatibility we special-case | // do that (just "foo.xml" is correct) but for compatibility we special-case | ||||
// things when the path is not absolute, and fall back to the old parsing behavior. | // things when the path is not absolute, and fall back to the old parsing behavior. | ||||
if (uriClazz != null && uri.startsWith("file:/")) { | |||||
if (uri.startsWith("file:/")) { | |||||
try { | try { | ||||
java.lang.reflect.Method createMethod | |||||
= uriClazz.getMethod("create", new Class[]{String.class}); | |||||
Object uriObj = createMethod.invoke(null, new Object[]{encodeURI(uri)}); | |||||
java.lang.reflect.Constructor fileConst | |||||
= File.class.getConstructor(new Class[]{uriClazz}); | |||||
File f = (File) fileConst.newInstance(new Object[]{uriObj}); | |||||
File f = new File(URI.create(encodeURI(uri))); | |||||
//bug #42227 forgot to decode before returning | //bug #42227 forgot to decode before returning | ||||
return decodeUri(f.getAbsolutePath()); | return decodeUri(f.getAbsolutePath()); | ||||
} catch (java.lang.reflect.InvocationTargetException e) { | |||||
Throwable e2 = e.getTargetException(); | |||||
if (e2 instanceof IllegalArgumentException) { | |||||
// Bad URI, pass this on. | |||||
// no, this is downgraded to a warning after various | |||||
// JRE bugs surfaced. Hand off | |||||
// to our built in code on a failure | |||||
//throw new IllegalArgumentException( | |||||
// "Bad URI " + uri + ":" + e2.getMessage(), e2); | |||||
e2.printStackTrace(); | |||||
} else { | |||||
// Unexpected target exception? Should not happen. | |||||
e2.printStackTrace(); | |||||
} | |||||
} catch (IllegalArgumentException e) { | |||||
// Bad URI, pass this on. | |||||
// no, this is downgraded to a warning after various | |||||
// JRE bugs surfaced. Hand off | |||||
// to our built in code on a failure | |||||
//throw new IllegalArgumentException( | |||||
// "Bad URI " + uri + ":" + e.getMessage(), e); | |||||
e.printStackTrace(); | |||||
} catch (Exception e) { | } catch (Exception e) { | ||||
// Reflection problems? Should not happen, debug. | |||||
// Unexpected exception? Should not happen. | |||||
e.printStackTrace(); | e.printStackTrace(); | ||||
} | } | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
*/ | |||||
/** | /** | ||||
* This method is public for testing; we may delete it without any warning -it is not part of Ant's stable API. | |||||
* @param uri uri to expand | * @param uri uri to expand | ||||
* @return the decoded URI | * @return the decoded URI | ||||
* @since Ant1.7.1 | * @since Ant1.7.1 | ||||
*/ | */ | ||||
public static String fromURIJava13(String uri) { | |||||
private static String fromURIJava13(String uri) { | |||||
// Fallback method for Java 1.3 or earlier. | // Fallback method for Java 1.3 or earlier. | ||||
URL url = null; | URL url = null; | ||||
@@ -409,7 +388,7 @@ public final class Locator { | |||||
* Convert a File to a URL. | * Convert a File to a URL. | ||||
* File.toURL() does not encode characters like #. | * File.toURL() does not encode characters like #. | ||||
* File.toURI() has been introduced in java 1.4, so | * File.toURI() has been introduced in java 1.4, so | ||||
* ANT cannot use it (except by reflection) | |||||
* Ant cannot use it (except by reflection) <!-- XXX no longer true --> | |||||
* FileUtils.toURI() cannot be used by Locator.java | * FileUtils.toURI() cannot be used by Locator.java | ||||
* Implemented this way. | * Implemented this way. | ||||
* File.toURL() adds file: and changes '\' to '/' for dos OSes | * File.toURL() adds file: and changes '\' to '/' for dos OSes | ||||
@@ -1146,7 +1146,7 @@ public class Execute { | |||||
/** | /** | ||||
* Launches the given command in a new process, in the given working | * Launches the given command in a new process, in the given working | ||||
* directory. Note that under Java 1.3.1, 1.4.0 and 1.4.1 on VMS this | |||||
* directory. Note that under Java 1.4.0 and 1.4.1 on VMS this | |||||
* method only works if <code>workingDir</code> is null or the logical | * method only works if <code>workingDir</code> is null or the logical | ||||
* JAVA$FORK_SUPPORT_CHDIR needs to be set to TRUE. | * JAVA$FORK_SUPPORT_CHDIR needs to be set to TRUE. | ||||
* @param project the Ant project. | * @param project the Ant project. | ||||
@@ -153,10 +153,8 @@ public class Parallel extends Task | |||||
/** | /** | ||||
* Dynamically generates the number of threads to execute based on the | * Dynamically generates the number of threads to execute based on the | ||||
* number of available processors (via | * number of available processors (via | ||||
* <code>java.lang.Runtime.availableProcessors()</code>). Requires a J2SE | |||||
* 1.4 VM, and it will overwrite the value set in threadCount. | |||||
* If used in a 1.1, 1.2, or 1.3 VM then the task will defer to | |||||
* <code>threadCount</code>.; optional | |||||
* <code>java.lang.Runtime.availableProcessors()</code>). | |||||
* Will overwrite the value set in threadCount; optional | |||||
* @param numThreadsPerProcessor Number of threads to create per available | * @param numThreadsPerProcessor Number of threads to create per available | ||||
* processor. | * processor. | ||||
* | * | ||||
@@ -170,7 +168,7 @@ public class Parallel extends Task | |||||
* simultaneously. If there are less tasks than threads then all will be | * simultaneously. If there are less tasks than threads then all will be | ||||
* executed at once, if there are more then only <code>threadCount</code> | * executed at once, if there are more then only <code>threadCount</code> | ||||
* tasks will be executed at one time. If <code>threadsPerProcessor</code> | * tasks will be executed at one time. If <code>threadsPerProcessor</code> | ||||
* is set and the JVM is at least a 1.4 VM then this value is | |||||
* is set then this value is | |||||
* ignored.; optional | * ignored.; optional | ||||
* | * | ||||
* @param numThreads total number of threads. | * @param numThreads total number of threads. | ||||
@@ -213,10 +211,8 @@ public class Parallel extends Task | |||||
*/ | */ | ||||
private void updateThreadCounts() { | private void updateThreadCounts() { | ||||
if (numThreadsPerProcessor != 0) { | if (numThreadsPerProcessor != 0) { | ||||
int numProcessors = getNumProcessors(); | |||||
if (numProcessors != 0) { | |||||
numThreads = numProcessors * numThreadsPerProcessor; | |||||
} | |||||
numThreads = Runtime.getRuntime().availableProcessors() * | |||||
numThreadsPerProcessor; | |||||
} | } | ||||
} | } | ||||
@@ -408,26 +404,6 @@ public class Parallel extends Task | |||||
} while (oneAlive && tries < NUMBER_TRIES); | } while (oneAlive && tries < NUMBER_TRIES); | ||||
} | } | ||||
/** | |||||
* Determine the number of processors. Only effective on Java 1.4+ | |||||
* | |||||
* @return the number of processors available or 0 if not determinable. | |||||
*/ | |||||
private int getNumProcessors() { | |||||
try { | |||||
Class[] paramTypes = {}; | |||||
Method availableProcessors = | |||||
Runtime.class.getMethod("availableProcessors", paramTypes); | |||||
Object[] args = {}; | |||||
Integer ret = (Integer) availableProcessors.invoke(Runtime.getRuntime(), args); | |||||
return ret.intValue(); | |||||
} catch (Exception e) { | |||||
// return a bogus number | |||||
return 0; | |||||
} | |||||
} | |||||
/** | /** | ||||
* thread that execs a task | * thread that execs a task | ||||
*/ | */ | ||||
@@ -46,7 +46,7 @@ import java.net.UnknownHostException; | |||||
* on the floor. Similarly, a host may be detected as reachable with ICMP, but not | * on the floor. Similarly, a host may be detected as reachable with ICMP, but not | ||||
* reachable on other ports (i.e. port 80), because of firewalls. | * reachable on other ports (i.e. port 80), because of firewalls. | ||||
* <p/> | * <p/> | ||||
* Requires Java1.5+ to work properly. On Java1.4 and earlier, if a hostname | |||||
* Requires Java 5+ to work properly. On Java 1.4, if a hostname | |||||
* can be resolved, the destination is assumed to be reachable. | * can be resolved, the destination is assumed to be reachable. | ||||
* | * | ||||
* @since Ant 1.7 | * @since Ant 1.7 | ||||
@@ -194,7 +194,7 @@ public class IsReachable extends ProjectComponent implements Condition { | |||||
reachable = false; | reachable = false; | ||||
} | } | ||||
} catch (NoSuchMethodException e) { | } catch (NoSuchMethodException e) { | ||||
//java1.4 or earlier | |||||
//java1.4 | |||||
log("Not found: InetAddress." + METHOD_NAME, Project.MSG_VERBOSE); | log("Not found: InetAddress." + METHOD_NAME, Project.MSG_VERBOSE); | ||||
log(MSG_NO_REACHABLE_TEST); | log(MSG_NO_REACHABLE_TEST); | ||||
reachable = true; | reachable = true; | ||||
@@ -56,16 +56,16 @@ import org.apache.tools.ant.util.regexp.Regexp; | |||||
* requires the Jakarta Oro Package). | * requires the Jakarta Oro Package). | ||||
* | * | ||||
* <pre> | * <pre> | ||||
* For jdk <= 1.3, there are two available implementations: | |||||
* org.apache.tools.ant.util.regexp.JakartaOroRegexp (the default) | |||||
* Available implementations: | |||||
* | |||||
* org.apache.tools.ant.util.regexp.JakartaOroRegexp (the default if available) | |||||
* Requires the jakarta-oro package | * Requires the jakarta-oro package | ||||
* | * | ||||
* org.apache.tools.ant.util.regexp.JakartaRegexpRegexp | * org.apache.tools.ant.util.regexp.JakartaRegexpRegexp | ||||
* Requires the jakarta-regexp package | * Requires the jakarta-regexp package | ||||
* | * | ||||
* For jdk >= 1.4 an additional implementation is available: | |||||
* org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp | |||||
* Requires the jdk 1.4 built in regular expression package. | |||||
* org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp (fallback default) | |||||
* Uses Java's built-in regular expression package | |||||
* | * | ||||
* Usage: | * Usage: | ||||
* | * | ||||
@@ -47,7 +47,7 @@ import org.apache.tools.ant.util.ProxySetup; | |||||
* stop using the socks server. | * stop using the socks server. | ||||
* <p> | * <p> | ||||
* You can set a username and password for http with the <tt>proxyHost</tt> | * You can set a username and password for http with the <tt>proxyHost</tt> | ||||
* and <tt>proxyPassword</tt> attributes. On Java1.4 and above these can also be | |||||
* and <tt>proxyPassword</tt> attributes. These can also be | |||||
* used against SOCKS5 servers. | * used against SOCKS5 servers. | ||||
* </p> | * </p> | ||||
* @see <a href="http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html"> | * @see <a href="http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html"> | ||||
@@ -31,16 +31,16 @@ import org.apache.tools.ant.util.regexp.RegexpFactory; | |||||
* that will be used. | * that will be used. | ||||
* | * | ||||
* <pre> | * <pre> | ||||
* For jdk <= 1.3, there are two available implementations: | |||||
* org.apache.tools.ant.util.regexp.JakartaOroRegexp (the default) | |||||
* Available implementations: | |||||
* | |||||
* org.apache.tools.ant.util.regexp.JakartaOroRegexp (the default if available) | |||||
* Based on the jakarta-oro package | * Based on the jakarta-oro package | ||||
* | * | ||||
* org.apache.tools.ant.util.regexp.JakartaRegexpRegexp | * org.apache.tools.ant.util.regexp.JakartaRegexpRegexp | ||||
* Based on the jakarta-regexp package | * Based on the jakarta-regexp package | ||||
* | * | ||||
* For jdk >= 1.4 an additional implementation is available: | |||||
* org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp | |||||
* Based on the jdk 1.4 built in regular expression package. | |||||
* org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp (fallback default) | |||||
* Based on the JDK's built-in regular expression package | |||||
* </pre> | * </pre> | ||||
* | * | ||||
* <pre> | * <pre> | ||||
@@ -1550,14 +1550,7 @@ public class FileUtils { | |||||
public static String[] getPathStack(String path) { | public static String[] getPathStack(String path) { | ||||
String normalizedPath = path.replace(File.separatorChar, '/'); | String normalizedPath = path.replace(File.separatorChar, '/'); | ||||
// since Java 1.4 | |||||
//return normalizedPath.split("/"); | |||||
// workaround for Java 1.2-1.3 | |||||
Object[] tokens = StringUtils.split(normalizedPath, '/').toArray(); | |||||
String[] rv = new String[tokens.length]; | |||||
System.arraycopy(tokens, 0, rv, 0, tokens.length); | |||||
return rv; | |||||
return normalizedPath.split("/"); | |||||
} | } | ||||
/** | /** | ||||
@@ -54,14 +54,6 @@ public class LocatorTest extends TestCase { | |||||
unix = Os.isFamily(Os.FAMILY_UNIX); | unix = Os.isFamily(Os.FAMILY_UNIX); | ||||
} | } | ||||
private String resolve(String uri) { | |||||
String j14 = Locator.fromURI(uri); | |||||
String j13 = Locator.fromURIJava13(uri); | |||||
assertEquals("Different fromURI conversion.\nJava1.4=" + j14 + "\nJava1.3=" + j13 + "\n", | |||||
j14, j13); | |||||
return j14; | |||||
} | |||||
/** | /** | ||||
* expect a uri to resolve to strings on different platforms | * expect a uri to resolve to strings on different platforms | ||||
* @param uri uri to parse | * @param uri uri to parse | ||||
@@ -70,7 +62,7 @@ public class LocatorTest extends TestCase { | |||||
* @return the resolved string | * @return the resolved string | ||||
*/ | */ | ||||
private String resolveTo(String uri, String expectedUnix, String expectedDos) { | private String resolveTo(String uri, String expectedUnix, String expectedDos) { | ||||
String result = resolve(uri); | |||||
String result = Locator.fromURI(uri); | |||||
assertResolved(uri, expectedUnix, result, unix); | assertResolved(uri, expectedUnix, result, unix); | ||||
assertResolved(uri, expectedDos, result, windows); | assertResolved(uri, expectedDos, result, windows); | ||||
return result; | return result; | ||||
@@ -315,11 +315,7 @@ public class AntTest extends BuildFileTest { | |||||
// Cf. #42263 | // Cf. #42263 | ||||
executeTarget("sub-show-ant.core.lib"); | executeTarget("sub-show-ant.core.lib"); | ||||
String realLog = getLog(); | String realLog = getLog(); | ||||
assertTrue("found ant.core.lib in: " + realLog, | |||||
// String.matches would be simpler... can we assume JDK 1.4+ yet? | |||||
realLog.indexOf("ant.jar") != -1 || | |||||
realLog.indexOf("build/classes") != 1 || | |||||
realLog.indexOf("build\\classes") != -1); | |||||
assertTrue("found ant.core.lib in: " + realLog, realLog.matches(".*(ant[.]jar|build.classes).*")); | |||||
} | } | ||||
private class BasedirChecker implements BuildListener { | private class BasedirChecker implements BuildListener { | ||||
@@ -141,19 +141,11 @@ public class ManifestClassPathTest | |||||
"../../resources/dsp-void/"); | "../../resources/dsp-void/"); | ||||
} | } | ||||
public void testInternationalGerman() { | public void testInternationalGerman() { | ||||
if (!JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_1_4)) { | |||||
System.out.println("Test with international characters skipped under pre 1.4 jvm."); | |||||
return; | |||||
} | |||||
executeTarget("international-german"); | executeTarget("international-german"); | ||||
expectLogContaining("run-two-jars", "beta alpha"); | expectLogContaining("run-two-jars", "beta alpha"); | ||||
} | } | ||||
public void testInternationalHebrew() { | public void testInternationalHebrew() { | ||||
if (!JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_1_4)) { | |||||
System.out.println("Test with international characters skipped under pre 1.4 jvm."); | |||||
return; | |||||
} | |||||
if (!Os.isFamily("windows")) { | if (!Os.isFamily("windows")) { | ||||
executeTarget("international-hebrew"); | executeTarget("international-hebrew"); | ||||
expectLogContaining("run-two-jars", "beta alpha"); | expectLogContaining("run-two-jars", "beta alpha"); | ||||
@@ -470,15 +470,6 @@ public class FileUtilsTest extends TestCase { | |||||
if (Os.isFamily("dos") || Os.isFamily("netware")) { | if (Os.isFamily("dos") || Os.isFamily("netware")) { | ||||
dosRoot = System.getProperty("user.dir") | dosRoot = System.getProperty("user.dir") | ||||
.substring(0, 3).replace(File.separatorChar, '/'); | .substring(0, 3).replace(File.separatorChar, '/'); | ||||
//preserve case on Cygwin when using 1.4 toURI: | |||||
Class uriClazz = null; | |||||
try { | |||||
uriClazz = Class.forName("java.net.URI"); | |||||
} catch (ClassNotFoundException e) { | |||||
// OK, Java 1.3. | |||||
dosRoot = dosRoot.toUpperCase(); | |||||
} | |||||
} | } | ||||
else | else | ||||
{ | { | ||||