git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@808163 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -373,8 +373,8 @@ href="http://www.cacas.org/~wes/java/" target="_top">gnu.regexp</a> or <a | |||
| href="http://www.crocodile.org/~sts/Rex/" target="_top">gnu.rex</a> with Ant, see <a | |||
| href="http://marc.theaimsgroup.com/?l=ant-dev&m=97550753813481&w=2" target="_top">this</a> | |||
| article.</p> | |||
| <p>This means, you need one of the supported regular expression | |||
| libraries <strong>and</strong> | |||
| <p>If you want to use one of the supported regular expression | |||
| libraries you need to also use | |||
| the corresponding <code>ant-[jakarta-oro, jakarta-regexp, apache-oro, apache-regexp}.jar</code> | |||
| from the Ant release you are using. | |||
| Make sure, both will be loaded from the same | |||
| @@ -392,8 +392,7 @@ following algorithm:</p> | |||
| name of the class implementing | |||
| <code>org.apache.tools.ant.util.regexp.RegexpMatcher</code> that | |||
| should be used.</li> | |||
| <li>If it has not been set, first try the JDK 1.4 classes, then | |||
| jakarta-ORO and finally try jakarta-regexp.</li> | |||
| <li>If it has not been set, uses the JDK 1.4 classes.</li> | |||
| </ul> | |||
| <b>Examples:</b> | |||
| @@ -78,8 +78,7 @@ org.apache.tools.ant.util.regexp.JakartaRegexpRegexp | |||
| </li> | |||
| </ul> | |||
| It can also be another implementation of the interface <code>org.apache.tools.ant.util.regexp.Regexp</code>. | |||
| If <code>ant.regexp.regexpimpl</code> is not defined, ant checks in the order Jdk14Regexp, JakartaOroRegexp, | |||
| JakartaRegexp for the availability of the corresponding library. The first of these 3 which is found will be used.</p> | |||
| If <code>ant.regexp.regexpimpl</code> is not defined, Ant uses Jdk14Regexp as this is always available.</p> | |||
| <p> | |||
| There are cross-platform issues for matches related to line terminator. | |||
| For example if you use $ to anchor your regular expression on the end of a line | |||
| @@ -88,7 +87,7 @@ expression library you use. It is 'highly recommended' that you test your patter | |||
| both Unix and Windows platforms before you rely on it. | |||
| <ul> | |||
| <li>Jakarta Oro defines a line terminator as '\n' and is consistent with Perl.</li> | |||
| <li>Jakarta RegExp uses a system-dependant line terminator.</li> | |||
| <li>Jakarta RegExp uses a system-dependent line terminator.</li> | |||
| <li>JDK 1.4 uses '\n', '\r\n', '\u0085', '\u2028', '\u2029' as a default | |||
| but is configured in the wrapper to use only '\n' (UNIX_LINE)</li> | |||
| </ul> | |||
| @@ -696,7 +696,7 @@ and any error to change permission will not result in a build failure.</p> | |||
| if you are using the | |||
| indicated feature. Note that only one of the regexp libraries is | |||
| needed for use with the mappers | |||
| (and Java 1.4 and higher includes a regexp implementation which | |||
| (and Java includes a regexp implementation which | |||
| Ant will find automatically). | |||
| You will also need to install the particular | |||
| Ant optional jar containing the task definitions to make these | |||
| @@ -343,8 +343,7 @@ org.apache.tools.ant.Executor implementation specified here. | |||
| <tr> | |||
| <td><code>ant.regexp.regexpimpl</code></td> | |||
| <td>classname</td> | |||
| <td>classname for a RegExp implementation; if not set Ant tries to | |||
| find another (JDK14+, Apache Oro...); | |||
| <td>classname for a RegExp implementation; if not set Ant uses JDK 1.4's implementation; | |||
| <a href="CoreTypes/mapper.html#regexp-mapper">RegExp-Mapper</a> | |||
| "Choice of regular expression implementation" | |||
| </td> | |||
| @@ -918,9 +918,8 @@ public class Project implements ResourceFactory { | |||
| setPropertyInternal(MagicNames.ANT_JAVA_VERSION, javaVersion); | |||
| // sanity check | |||
| if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_0) | |||
| || JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)) { | |||
| throw new BuildException("Ant cannot work on Java 1.0 / 1.1"); | |||
| if (!JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_1_4)) { | |||
| throw new BuildException("Ant cannot work on Java prior to 1.4"); | |||
| } | |||
| log("Detected Java version: " + javaVersion + " in: " | |||
| + System.getProperty("java.home"), MSG_VERBOSE); | |||
| @@ -136,11 +136,7 @@ public class Javac extends MatchingTask { | |||
| } | |||
| private String assumedJavaVersion() { | |||
| if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2)) { | |||
| return JAVAC12; | |||
| } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_3)) { | |||
| return JAVAC13; | |||
| } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_4)) { | |||
| if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_4)) { | |||
| return JAVAC14; | |||
| } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_5)) { | |||
| return JAVAC15; | |||
| @@ -98,13 +98,6 @@ public final class CompilerAdapterFactory { | |||
| public static CompilerAdapter getCompiler(String compilerType, Task task, | |||
| Path classpath) | |||
| throws BuildException { | |||
| boolean isClassicCompilerSupported = true; | |||
| //as new versions of java come out, add them to this test | |||
| if (!JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2) | |||
| && !JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_3)) { | |||
| isClassicCompilerSupported = false; | |||
| } | |||
| if (compilerType.equalsIgnoreCase("jikes")) { | |||
| return new Jikes(); | |||
| } | |||
| @@ -114,15 +107,11 @@ public final class CompilerAdapterFactory { | |||
| if (compilerType.equalsIgnoreCase("classic") | |||
| || compilerType.equalsIgnoreCase("javac1.1") | |||
| || compilerType.equalsIgnoreCase("javac1.2")) { | |||
| if (isClassicCompilerSupported) { | |||
| return new Javac12(); | |||
| } else { | |||
| task.log("This version of java does " | |||
| + "not support the classic " | |||
| + "compiler; upgrading to modern", | |||
| Project.MSG_WARN); | |||
| compilerType = "modern"; | |||
| } | |||
| task.log("This version of java does " | |||
| + "not support the classic " | |||
| + "compiler; upgrading to modern", | |||
| Project.MSG_WARN); | |||
| compilerType = "modern"; | |||
| } | |||
| //on java<=1.3 the modern falls back to classic if it is not found | |||
| //but on java>=1.4 we just bail out early | |||
| @@ -135,22 +124,16 @@ public final class CompilerAdapterFactory { | |||
| if (doesModernCompilerExist()) { | |||
| return new Javac13(); | |||
| } else { | |||
| if (isClassicCompilerSupported) { | |||
| task.log("Modern compiler not found - looking for " | |||
| + "classic compiler", Project.MSG_WARN); | |||
| return new Javac12(); | |||
| } else { | |||
| throw new BuildException("Unable to find a javac " | |||
| + "compiler;\n" | |||
| + MODERN_COMPILER | |||
| + " is not on the " | |||
| + "classpath.\n" | |||
| + "Perhaps JAVA_HOME does not" | |||
| + " point to the JDK.\n" | |||
| + "It is currently set to \"" | |||
| + JavaEnvUtils.getJavaHome() | |||
| + "\""); | |||
| } | |||
| throw new BuildException("Unable to find a javac " | |||
| + "compiler;\n" | |||
| + MODERN_COMPILER | |||
| + " is not on the " | |||
| + "classpath.\n" | |||
| + "Perhaps JAVA_HOME does not" | |||
| + " point to the JDK.\n" | |||
| + "It is currently set to \"" | |||
| + JavaEnvUtils.getJavaHome() | |||
| + "\""); | |||
| } | |||
| } | |||
| @@ -554,11 +554,7 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter { | |||
| * @since Ant 1.5 | |||
| */ | |||
| protected boolean assumeJava12() { | |||
| return "javac1.2".equals(attributes.getCompilerVersion()) | |||
| || ("classic".equals(attributes.getCompilerVersion()) | |||
| && JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2)) | |||
| || ("extJavac".equals(attributes.getCompilerVersion()) | |||
| && JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2)); | |||
| return "javac1.2".equals(attributes.getCompilerVersion()); | |||
| } | |||
| /** | |||
| @@ -567,13 +563,7 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter { | |||
| * @since Ant 1.5 | |||
| */ | |||
| protected boolean assumeJava13() { | |||
| return "javac1.3".equals(attributes.getCompilerVersion()) | |||
| || ("classic".equals(attributes.getCompilerVersion()) | |||
| && JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_3)) | |||
| || ("modern".equals(attributes.getCompilerVersion()) | |||
| && JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_3)) | |||
| || ("extJavac".equals(attributes.getCompilerVersion()) | |||
| && JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_3)); | |||
| return "javac1.3".equals(attributes.getCompilerVersion()); | |||
| } | |||
| /** | |||
| @@ -34,6 +34,7 @@ import org.apache.tools.ant.types.Commandline; | |||
| * was refactored. | |||
| * | |||
| * @since Ant 1.3 | |||
| * @deprecated Use {@link Javac13} instead. | |||
| */ | |||
| public class Javac12 extends DefaultCompilerAdapter { | |||
| protected static final String CLASSIC_COMPILER_CLASSNAME = "sun.tools.javac.Main"; | |||
| @@ -58,15 +58,15 @@ import org.apache.tools.ant.util.regexp.Regexp; | |||
| * <pre> | |||
| * Available implementations: | |||
| * | |||
| * org.apache.tools.ant.util.regexp.JakartaOroRegexp (the default if available) | |||
| * org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp (default) | |||
| * Uses Java's built-in regular expression package | |||
| * | |||
| * org.apache.tools.ant.util.regexp.JakartaOroRegexp | |||
| * Requires the jakarta-oro package | |||
| * | |||
| * org.apache.tools.ant.util.regexp.JakartaRegexpRegexp | |||
| * Requires the jakarta-regexp package | |||
| * | |||
| * org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp (fallback default) | |||
| * Uses Java's built-in regular expression package | |||
| * | |||
| * Usage: | |||
| * | |||
| * Call Syntax: | |||
| @@ -33,14 +33,14 @@ import org.apache.tools.ant.util.regexp.RegexpFactory; | |||
| * <pre> | |||
| * Available implementations: | |||
| * | |||
| * org.apache.tools.ant.util.regexp.JakartaOroRegexp (the default if available) | |||
| * org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp (default) | |||
| * Based on the JDK's built-in regular expression package | |||
| * | |||
| * org.apache.tools.ant.util.regexp.JakartaOroRegexp | |||
| * Based on the jakarta-oro package | |||
| * | |||
| * org.apache.tools.ant.util.regexp.JakartaRegexpRegexp | |||
| * Based on the jakarta-regexp package | |||
| * | |||
| * org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp (fallback default) | |||
| * Based on the JDK's built-in regular expression package | |||
| * </pre> | |||
| * | |||
| * <pre> | |||
| @@ -17,7 +17,6 @@ | |||
| */ | |||
| package org.apache.tools.ant.util; | |||
| import java.io.BufferedWriter; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import java.io.FileWriter; | |||
| @@ -143,7 +142,7 @@ public final class JavaEnvUtils { | |||
| /** | |||
| * Returns the version of Java this class is running under. | |||
| * @return the version of Java as a String, e.g. "1.1" | |||
| * @return the version of Java as a String, e.g. "1.6" | |||
| */ | |||
| public static String getJavaVersion() { | |||
| return javaVersion; | |||
| @@ -164,8 +163,8 @@ public final class JavaEnvUtils { | |||
| * Compares the current Java version to the passed in String - | |||
| * assumes the argument is one of the constants defined in this | |||
| * class. | |||
| * Note that Ant now requires JDK 1.2+ so {@link #JAVA_1_0} and | |||
| * {@link #JAVA_1_1} need no longer be tested for. | |||
| * Note that Ant now requires JDK 1.4+ so {@link #JAVA_1_0} through | |||
| * {@link #JAVA_1_3} need no longer be tested for. | |||
| * @param version the version to check against the current version. | |||
| * @return true if the version of Java is the same as the given version. | |||
| * @since Ant 1.5 | |||
| @@ -178,8 +177,8 @@ public final class JavaEnvUtils { | |||
| * Compares the current Java version to the passed in String - | |||
| * assumes the argument is one of the constants defined in this | |||
| * class. | |||
| * Note that Ant now requires JDK 1.2+ so {@link #JAVA_1_0} and | |||
| * {@link #JAVA_1_1} need no longer be tested for. | |||
| * Note that Ant now requires JDK 1.4+ so {@link #JAVA_1_0} through | |||
| * {@link #JAVA_1_3} need no longer be tested for. | |||
| * @param version the version to check against the current version. | |||
| * @return true if the version of Java is the same or higher than the | |||
| * given version. | |||
| @@ -21,7 +21,6 @@ import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.MagicNames; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.util.ClasspathUtils; | |||
| import org.apache.tools.ant.util.JavaEnvUtils; | |||
| /*** | |||
| * Regular expression factory, which will create Regexp objects. The | |||
| @@ -41,7 +40,7 @@ public class RegexpFactory extends RegexpMatcherFactory { | |||
| * @throws BuildException on error | |||
| */ | |||
| public Regexp newRegexp() throws BuildException { | |||
| return (Regexp) newRegexp(null); | |||
| return newRegexp(null); | |||
| } | |||
| /*** | |||
| @@ -65,32 +64,7 @@ public class RegexpFactory extends RegexpMatcherFactory { | |||
| // load a different implementation? | |||
| } | |||
| Throwable cause = null; | |||
| try { | |||
| testAvailability("java.util.regex.Matcher"); | |||
| return createRegexpInstance("org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp"); | |||
| } catch (BuildException be) { | |||
| cause = orCause( | |||
| cause, be, | |||
| JavaEnvUtils.getJavaVersionNumber() < JavaEnvUtils.VERSION_1_4); | |||
| } | |||
| try { | |||
| testAvailability("org.apache.oro.text.regex.Pattern"); | |||
| return createRegexpInstance("org.apache.tools.ant.util.regexp.JakartaOroRegexp"); | |||
| } catch (BuildException be) { | |||
| cause = orCause(cause, be, true); | |||
| } | |||
| try { | |||
| testAvailability("org.apache.regexp.RE"); | |||
| return createRegexpInstance("org.apache.tools.ant.util.regexp.JakartaRegexpRegexp"); | |||
| } catch (BuildException be) { | |||
| cause = orCause(cause, be, true); | |||
| } | |||
| throw new BuildException("No supported regular expression matcher found" | |||
| + (cause != null ? ": " + cause : ""), cause); | |||
| return new Jdk14RegexpRegexp(); | |||
| } | |||
| /** | |||
| @@ -21,7 +21,6 @@ import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.MagicNames; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.util.ClasspathUtils; | |||
| import org.apache.tools.ant.util.JavaEnvUtils; | |||
| /** | |||
| * Simple Factory Class that produces an implementation of RegexpMatcher based on the system | |||
| @@ -68,40 +67,7 @@ public class RegexpMatcherFactory { | |||
| // load a different implementation? | |||
| } | |||
| Throwable cause = null; | |||
| try { | |||
| testAvailability("java.util.regex.Matcher"); | |||
| return createInstance("org.apache.tools.ant.util.regexp.Jdk14RegexpMatcher"); | |||
| } catch (BuildException be) { | |||
| cause = orCause( | |||
| cause, be, | |||
| JavaEnvUtils.getJavaVersionNumber() < JavaEnvUtils.VERSION_1_4); | |||
| } | |||
| try { | |||
| testAvailability("org.apache.oro.text.regex.Pattern"); | |||
| return createInstance("org.apache.tools.ant.util.regexp.JakartaOroMatcher"); | |||
| } catch (BuildException be) { | |||
| cause = orCause(cause, be, true); | |||
| } | |||
| try { | |||
| testAvailability("org.apache.regexp.RE"); | |||
| return createInstance("org.apache.tools.ant.util.regexp.JakartaRegexpMatcher"); | |||
| } catch (BuildException be) { | |||
| cause = orCause(cause, be, true); | |||
| } | |||
| throw new BuildException("No supported regular expression matcher found" | |||
| + (cause != null ? ": " + cause : ""), cause); | |||
| } | |||
| static Throwable orCause(Throwable deflt, BuildException be, boolean ignoreCnfe) { | |||
| if (deflt != null) { | |||
| return deflt; | |||
| } | |||
| Throwable t = be.getException(); | |||
| return ignoreCnfe && t instanceof ClassNotFoundException ? null : t; | |||
| return new Jdk14RegexpMatcher(); | |||
| } | |||
| /** | |||
| @@ -22,8 +22,6 @@ import org.apache.tools.ant.MagicNames; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.types.Path; | |||
| import org.apache.tools.ant.types.Commandline; | |||
| import org.apache.tools.ant.taskdefs.condition.Os; | |||
| import org.apache.tools.ant.util.JavaEnvUtils; | |||
| import junit.framework.TestCase; | |||
| @@ -98,12 +96,6 @@ public class ExecuteJavaTest extends TestCase { | |||
| // test that the watchdog ends the process | |||
| public void testTimeOutForked() throws Exception { | |||
| //process doesn't die properly under this combination, | |||
| //thus test fails. No workaround? | |||
| if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2) | |||
| && Os.isFamily("dos")) { | |||
| return; | |||
| } | |||
| Commandline cmd = getCommandline(TIME_OUT*2); | |||
| ej.setJavaCommand(cmd); | |||
| long now = System.currentTimeMillis(); | |||
| @@ -21,10 +21,8 @@ package org.apache.tools.ant.taskdefs; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.taskdefs.compilers.CompilerAdapter; | |||
| import org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory; | |||
| import org.apache.tools.ant.taskdefs.compilers.Javac12; | |||
| import org.apache.tools.ant.taskdefs.compilers.Javac13; | |||
| import org.apache.tools.ant.taskdefs.compilers.JavacExternal; | |||
| import org.apache.tools.ant.util.JavaEnvUtils; | |||
| import junit.framework.TestCase; | |||
| @@ -189,23 +187,13 @@ public class JavacTest extends TestCase { | |||
| } | |||
| public void testCompilerAdapter() { | |||
| if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2) | |||
| || JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_3)) { | |||
| javac.setCompiler("javac1.1"); | |||
| } else { | |||
| javac.setCompiler("javac1.4"); | |||
| } | |||
| javac.setCompiler("javac1.4"); | |||
| javac.setDepend(true); | |||
| CompilerAdapter adapter = | |||
| CompilerAdapterFactory.getCompiler(javac.getCompiler(), javac); | |||
| if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2) | |||
| || JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_3)) { | |||
| assertTrue(adapter instanceof Javac12); | |||
| } else { | |||
| assertTrue(adapter instanceof Javac13); | |||
| } | |||
| assertTrue(adapter instanceof Javac13); | |||
| javac.setFork(true); | |||
| adapter = | |||
| @@ -20,7 +20,6 @@ package org.apache.tools.ant.taskdefs; | |||
| import org.apache.tools.ant.BuildFileTest; | |||
| import org.apache.tools.ant.taskdefs.condition.Os; | |||
| import org.apache.tools.ant.util.JavaEnvUtils; | |||
| import org.apache.tools.ant.util.regexp.RegexpMatcherFactory; | |||
| /** | |||
| @@ -23,7 +23,6 @@ package org.apache.tools.ant.taskdefs; | |||
| import java.io.IOException; | |||
| import org.apache.tools.ant.util.JavaEnvUtils; | |||
| import junit.framework.TestCase; | |||
| @@ -40,10 +39,6 @@ public class ProcessDestroyerTest extends TestCase { | |||
| } | |||
| public void testProcessDestroyer(){ | |||
| if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2)) { | |||
| return; | |||
| } | |||
| try { | |||
| ProcessDestroyer processDestroyer = new ProcessDestroyer(); | |||
| Process process = | |||
| @@ -22,7 +22,6 @@ import junit.framework.TestCase; | |||
| import org.apache.tools.ant.MagicNames; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.util.JavaEnvUtils; | |||
| /** | |||
| * JUnit 3 testcases for org.apache.tools.ant.CommandlineJava | |||
| @@ -143,11 +142,6 @@ public class CommandlineJavaTest extends TestCase { | |||
| } | |||
| public void testAssertions() throws Exception { | |||
| if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2) | |||
| || JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_3)) { | |||
| return; | |||
| } | |||
| CommandlineJava c = new CommandlineJava(); | |||
| c.createArgument().setValue("org.apache.tools.ant.CommandlineJavaTest"); | |||
| c.setClassname("junit.textui.TestRunner"); | |||