Browse Source

Some miscellaneous updates given that JDK 1.4 can be assumed.

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-ffa450edef68
master
Jesse N. Glick 16 years ago
parent
commit
028ba47c82
13 changed files with 47 additions and 127 deletions
  1. +2
    -1
      src/main/org/apache/tools/ant/RuntimeConfigurable.java
  2. +23
    -44
      src/main/org/apache/tools/ant/launch/Locator.java
  3. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/Execute.java
  4. +5
    -29
      src/main/org/apache/tools/ant/taskdefs/Parallel.java
  5. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/condition/IsReachable.java
  6. +5
    -5
      src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
  7. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/net/SetProxy.java
  8. +5
    -5
      src/main/org/apache/tools/ant/types/RegularExpression.java
  9. +1
    -8
      src/main/org/apache/tools/ant/util/FileUtils.java
  10. +1
    -9
      src/tests/junit/org/apache/tools/ant/launch/LocatorTest.java
  11. +1
    -5
      src/tests/junit/org/apache/tools/ant/taskdefs/AntTest.java
  12. +0
    -8
      src/tests/junit/org/apache/tools/ant/taskdefs/ManifestClassPathTest.java
  13. +0
    -9
      src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java

+ 2
- 1
src/main/org/apache/tools/ant/RuntimeConfigurable.java View File

@@ -69,13 +69,14 @@ public class RuntimeConfigurable implements Serializable {
* exact order. The following code is copied from AttributeImpl.
* We could also just use SAX2 Attributes and convert to SAX1 ( DOM
* 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
* refid. A number of datatypes check if refid is set
* when other attributes are set. This check will not
* work if the build script has the other attribute before
* the "refid" attribute, so now (ANT 1.7) the refid
* 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;



+ 23
- 44
src/main/org/apache/tools/ant/launch/Locator.java View File

@@ -165,7 +165,7 @@ public final class Locator {
*
* <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>
*
* 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
*/
public static String fromURI(String uri) {
return fromURIJava13(uri);
// #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.
* @param uri
* @return null if a conversion was not possible
*/
/* currently unused:
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
// 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
// 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 {
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
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) {
// Reflection problems? Should not happen, debug.
// Unexpected exception? Should not happen.
e.printStackTrace();
}
}
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
* @return the decoded URI
* @since Ant1.7.1
*/
public static String fromURIJava13(String uri) {
private static String fromURIJava13(String uri) {
// Fallback method for Java 1.3 or earlier.

URL url = null;
@@ -409,7 +388,7 @@ public final class Locator {
* Convert a File to a URL.
* File.toURL() does not encode characters like #.
* 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
* Implemented this way.
* File.toURL() adds file: and changes '\' to '/' for dos OSes


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/Execute.java View File

@@ -1146,7 +1146,7 @@ public class Execute {

/**
* 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
* JAVA$FORK_SUPPORT_CHDIR needs to be set to TRUE.
* @param project the Ant project.


+ 5
- 29
src/main/org/apache/tools/ant/taskdefs/Parallel.java View File

@@ -153,10 +153,8 @@ public class Parallel extends Task
/**
* Dynamically generates the number of threads to execute based on the
* 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
* processor.
*
@@ -170,7 +168,7 @@ public class Parallel extends Task
* simultaneously. If there are less tasks than threads then all will be
* executed at once, if there are more then only <code>threadCount</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
*
* @param numThreads total number of threads.
@@ -213,10 +211,8 @@ public class Parallel extends Task
*/
private void updateThreadCounts() {
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);
}

/**
* 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
*/


+ 2
- 2
src/main/org/apache/tools/ant/taskdefs/condition/IsReachable.java View File

@@ -46,7 +46,7 @@ import java.net.UnknownHostException;
* 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.
* <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.
*
* @since Ant 1.7
@@ -194,7 +194,7 @@ public class IsReachable extends ProjectComponent implements Condition {
reachable = false;
}
} catch (NoSuchMethodException e) {
//java1.4 or earlier
//java1.4
log("Not found: InetAddress." + METHOD_NAME, Project.MSG_VERBOSE);
log(MSG_NO_REACHABLE_TEST);
reachable = true;


+ 5
- 5
src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java View File

@@ -56,16 +56,16 @@ import org.apache.tools.ant.util.regexp.Regexp;
* requires the Jakarta Oro Package).
*
* <pre>
* For jdk &lt;= 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
*
* org.apache.tools.ant.util.regexp.JakartaRegexpRegexp
* Requires the jakarta-regexp package
*
* For jdk &gt;= 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:
*


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/optional/net/SetProxy.java View File

@@ -47,7 +47,7 @@ import org.apache.tools.ant.util.ProxySetup;
* stop using the socks server.
* <p>
* 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.
* </p>
* @see <a href="http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html">


+ 5
- 5
src/main/org/apache/tools/ant/types/RegularExpression.java View File

@@ -31,16 +31,16 @@ import org.apache.tools.ant.util.regexp.RegexpFactory;
* that will be used.
*
* <pre>
* For jdk &lt;= 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
*
* org.apache.tools.ant.util.regexp.JakartaRegexpRegexp
* Based on the jakarta-regexp package
*
* For jdk &gt;= 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>


+ 1
- 8
src/main/org/apache/tools/ant/util/FileUtils.java View File

@@ -1550,14 +1550,7 @@ public class FileUtils {
public static String[] getPathStack(String path) {
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("/");
}

/**


+ 1
- 9
src/tests/junit/org/apache/tools/ant/launch/LocatorTest.java View File

@@ -54,14 +54,6 @@ public class LocatorTest extends TestCase {
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
* @param uri uri to parse
@@ -70,7 +62,7 @@ public class LocatorTest extends TestCase {
* @return the resolved string
*/
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, expectedDos, result, windows);
return result;


+ 1
- 5
src/tests/junit/org/apache/tools/ant/taskdefs/AntTest.java View File

@@ -315,11 +315,7 @@ public class AntTest extends BuildFileTest {
// Cf. #42263
executeTarget("sub-show-ant.core.lib");
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 {


+ 0
- 8
src/tests/junit/org/apache/tools/ant/taskdefs/ManifestClassPathTest.java View File

@@ -141,19 +141,11 @@ public class ManifestClassPathTest
"../../resources/dsp-void/");
}
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");
expectLogContaining("run-two-jars", "beta alpha");
}
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")) {
executeTarget("international-hebrew");
expectLogContaining("run-two-jars", "beta alpha");


+ 0
- 9
src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java View File

@@ -470,15 +470,6 @@ public class FileUtilsTest extends TestCase {
if (Os.isFamily("dos") || Os.isFamily("netware")) {
dosRoot = System.getProperty("user.dir")
.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
{


Loading…
Cancel
Save