diff --git a/WHATSNEW b/WHATSNEW
index 0974de2f7..d37e547d7 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -18,6 +18,9 @@ Changes that could break older environments:
*
javac1.6
and
javac1.7
(since Ant 1.8.2) and
javac1.8
(since Ant 1.8.3) and
- javac1.9
(since Ant 1.9.5) can be used as aliases.
+ javac1.9
(since Ant 1.9.5) and
+ javac9
(since Ant 1.9.8) can be used as aliases.
jikes
(the Jikes
compiler).ant.jar
file.
+ "1.2".
+ant.core.lib the absolute path of the ant.jar
file.
There is also another property, but this is set by the launcher diff --git a/src/main/org/apache/tools/ant/taskdefs/Javac.java b/src/main/org/apache/tools/ant/taskdefs/Javac.java index 1104fae4b..1eef467d3 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Javac.java +++ b/src/main/org/apache/tools/ant/taskdefs/Javac.java @@ -85,6 +85,7 @@ public class Javac extends MatchingTask { private static final String FAIL_MSG = "Compile failed; see the compiler error output for details."; + private static final String JAVAC9 = "javac9"; private static final String JAVAC19 = "javac1.9"; private static final String JAVAC18 = "javac1.8"; private static final String JAVAC17 = "javac1.7"; @@ -166,8 +167,8 @@ public class Javac extends MatchingTask { return JAVAC17; } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_8)) { return JAVAC18; - } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_9)) { - return JAVAC19; + } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_9)) { + return JAVAC9; } else { return CLASSIC; } @@ -912,7 +913,8 @@ public class Javac extends MatchingTask { } private String getAltCompilerName(final String anImplementation) { - if (JAVAC19.equalsIgnoreCase(anImplementation) + if (JAVAC9.equalsIgnoreCase(anImplementation) + || JAVAC19.equalsIgnoreCase(anImplementation) || JAVAC18.equalsIgnoreCase(anImplementation) || JAVAC17.equalsIgnoreCase(anImplementation) || JAVAC16.equalsIgnoreCase(anImplementation) @@ -927,7 +929,7 @@ public class Javac extends MatchingTask { } if (MODERN.equalsIgnoreCase(anImplementation)) { final String nextSelected = assumedJavaVersion(); - if (JAVAC19.equalsIgnoreCase(nextSelected) + if (JAVAC9.equalsIgnoreCase(nextSelected) || JAVAC18.equalsIgnoreCase(nextSelected) || JAVAC17.equalsIgnoreCase(nextSelected) || JAVAC16.equalsIgnoreCase(nextSelected) @@ -1194,12 +1196,12 @@ public class Javac extends MatchingTask { * @param compilerImpl the name of the compiler implementation * @return true if compilerImpl is "modern", "classic", * "javac1.1", "javac1.2", "javac1.3", "javac1.4", "javac1.5", - * "javac1.6", "javac1.7", "javac1.8" or "javac1.9". + * "javac1.6", "javac1.7", "javac1.8", "javac1.9" or "javac9". */ protected boolean isJdkCompiler(final String compilerImpl) { return MODERN.equals(compilerImpl) || CLASSIC.equals(compilerImpl) - || JAVAC19.equals(compilerImpl) + || JAVAC9.equals(compilerImpl) || JAVAC18.equals(compilerImpl) || JAVAC17.equals(compilerImpl) || JAVAC16.equals(compilerImpl) diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/CompilerAdapterFactory.java b/src/main/org/apache/tools/ant/taskdefs/compilers/CompilerAdapterFactory.java index aeecb4a50..871271593 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/CompilerAdapterFactory.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/CompilerAdapterFactory.java @@ -122,7 +122,8 @@ public final class CompilerAdapterFactory { || compilerType.equalsIgnoreCase("javac1.6") || compilerType.equalsIgnoreCase("javac1.7") || compilerType.equalsIgnoreCase("javac1.8") - || compilerType.equalsIgnoreCase("javac1.9")) { + || compilerType.equalsIgnoreCase("javac1.9") + || compilerType.equalsIgnoreCase("javac9")) { // does the modern compiler exist? if (doesModernCompilerExist()) { return new Javac13(); diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java b/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java index d1a9cb3cc..db6cd8551 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java @@ -672,12 +672,23 @@ public abstract class DefaultCompilerAdapter } /** - * Shall we assume JDK 1.9 command line switches? - * @return true if JDK 1.9 + * Shall we assume JDK 9 command line switches? + * @return true if JDK 9 * @since Ant 1.9.4 + * @deprecated use #assumeJava9 instead */ protected boolean assumeJava19() { - return assumeJavaXY("javac1.9", JavaEnvUtils.JAVA_1_9); + return assumeJavaXY("javac1.9", JavaEnvUtils.JAVA_9) + || assumeJavaXY("javac9", JavaEnvUtils.JAVA_9); + } + + /** + * Shall we assume JDK 9 command line switches? + * @return true if JDK 9 + * @since Ant 1.9.8 + */ + protected boolean assumeJava9() { + return assumeJava19(); } /** @@ -686,12 +697,10 @@ public abstract class DefaultCompilerAdapter */ private boolean assumeJavaXY(final String javacXY, final String javaEnvVersionXY) { return javacXY.equals(attributes.getCompilerVersion()) - || ("classic".equals(attributes.getCompilerVersion()) - && JavaEnvUtils.isJavaVersion(javaEnvVersionXY)) - || ("modern".equals(attributes.getCompilerVersion()) - && JavaEnvUtils.isJavaVersion(javaEnvVersionXY)) - || ("extJavac".equals(attributes.getCompilerVersion()) - && JavaEnvUtils.isJavaVersion(javaEnvVersionXY)); + || (JavaEnvUtils.isJavaVersion(javaEnvVersionXY) && + ("classic".equals(attributes.getCompilerVersion()) + || "modern".equals(attributes.getCompilerVersion()) + || "extJavac".equals(attributes.getCompilerVersion()))); } /** @@ -755,8 +764,8 @@ public abstract class DefaultCompilerAdapter if (assumeJava18()) { return "1.8 in JDK 1.8"; } - if (assumeJava19()) { - return "1.9 in JDK 1.9"; + if (assumeJava9()) { + return "9 in JDK 9"; } return ""; } @@ -782,7 +791,7 @@ public abstract class DefaultCompilerAdapter && !assumeJava15() && !assumeJava16()) || (t.equals("7") && !assumeJava17()) || (t.equals("8") && !assumeJava18()) - || (t.equals("9") && !assumeJava19()); + || (t.equals("9") && !assumeJava9()); } diff --git a/src/main/org/apache/tools/ant/util/JavaEnvUtils.java b/src/main/org/apache/tools/ant/util/JavaEnvUtils.java index 4f244da31..a551c0f6b 100644 --- a/src/main/org/apache/tools/ant/util/JavaEnvUtils.java +++ b/src/main/org/apache/tools/ant/util/JavaEnvUtils.java @@ -55,6 +55,9 @@ public final class JavaEnvUtils { /** floating version of the JVM */ private static int javaVersionNumber; + /** Version of currently running VM. */ + private static final DeweyDecimal parsedJavaVersion; + /** Version constant for Java 1.0 */ public static final String JAVA_1_0 = "1.0"; /** Number Version constant for Java 1.0 */ @@ -100,11 +103,28 @@ public final class JavaEnvUtils { /** Number Version constant for Java 1.8 */ public static final int VERSION_1_8 = 18; - /** Version constant for Java 1.9 */ + /** + * Version constant for Java 1.9 + * @deprecated use #JAVA_9 instead + */ public static final String JAVA_1_9 = "1.9"; - /** Number Version constant for Java 1.9 */ + /** + * Number Version constant for Java 1.9 + * @deprecated use #VERSION_9 instead + */ public static final int VERSION_1_9 = 19; + /** + * Version constant for Java 9 + * @since Ant 1.9.8 + */ + public static final String JAVA_9 = "9"; + /** + * Number Version constant for Java 9 + * @since Ant 1.9.8 + */ + public static final int VERSION_9 = 90; + /** Whether this is the Kaffe VM */ private static boolean kaffeDetected; @@ -158,13 +178,14 @@ public final class JavaEnvUtils { Class.forName("java.lang.reflect.Executable"); javaVersion = JAVA_1_8; javaVersionNumber++; - checkForJava9(); - javaVersion = JAVA_1_9; - javaVersionNumber++; + Class.forName("java.lang.module.ModuleDescriptor"); + javaVersion = JAVA_9; + javaVersionNumber = VERSION_9; } catch (Throwable t) { // swallow as we've hit the max class version that // we have } + parsedJavaVersion = new DeweyDecimal(javaVersion); kaffeDetected = false; try { Class.forName("kaffe.util.NotImplemented"); @@ -197,7 +218,11 @@ 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.6" + * + *
Up until Java 8 Java version numbers were 1.VERSION - + * e.g. 1.8.x for Java 8, starting with Java 9 it became 9.x.
+ * + * @return the version of Java as a String, e.g. "1.6" or "9" */ public static String getJavaVersion() { return javaVersion; @@ -205,31 +230,28 @@ public final class JavaEnvUtils { /** - * Checks for a give Java 9 runtime. - * At the time of writing the actual version of the JDK was 1.9.0_b06. - * Searching for new classes gave no hits, so we need another aproach. - * Searching for changes (grep -r -i -n "@since 1.9" .) in the sources gave - * only one hit: a new constant in the class SourceVersion. - * So we have to check that ... - * - * @throws Exception if we can't load the class or don't find the new constant. - * This is the behavior when searching for new features on older versions. - * @since Ant 1.9.4 + * Returns the version of Java this class is running under. + *This number can be used for comparisons.
+ * @return the version of Java as a number 10x the major/minor, + * e.g Java1.5 has a value of 15 and Java9 the value 90 - major + * will be 1 for all versions of Java prior to Java 9, minor will + * be 0 for all versions of Java starting with Java 9. + * @deprecated use #getParsedJavaVersion instead */ - private static void checkForJava9() throws Exception { - Class> clazz = Class.forName("javax.lang.model.SourceVersion"); - clazz.getDeclaredField("RELEASE_9"); + public static int getJavaVersionNumber() { + return javaVersionNumber; } - /** * Returns the version of Java this class is running under. - * This number can be used for comparisons; it will always be - * @return the version of Java as a number 10x the major/minor, - * e.g Java1.5 has a value of 15 + *This number can be used for comparisons.
+ * @return the version of Java as major.minor, e.g Java1.5 has a + * value of 1.5 and Java9 the value 9 - major will be 1 for all + * versions of Java prior to Java 9, minor will be 0 for all + * versions of Java starting with Java 9. */ - public static int getJavaVersionNumber() { - return javaVersionNumber; + public static DeweyDecimal getParsedJavaVersion() { + return parsedJavaVersion; } /** @@ -243,7 +265,8 @@ public final class JavaEnvUtils { * @since Ant 1.5 */ public static boolean isJavaVersion(String version) { - return javaVersion.equals(version); + return javaVersion.equals(version) + || (javaVersion.equals(JAVA_9) && JAVA_1_9.equals(version)); } /** @@ -258,7 +281,7 @@ public final class JavaEnvUtils { * @since Ant 1.7 */ public static boolean isAtLeastJavaVersion(String version) { - return javaVersion.compareTo(version) >= 0; + return parsedJavaVersion.compareTo(new DeweyDecimal(version)) >= 0; } /** @@ -385,7 +408,7 @@ public final class JavaEnvUtils { // fall back to JRE bin directory, also catches JDK 1.0 and 1.1 // where java.home points to the root of the JDK and Mac OS X where // the whole directory layout is different from Sun's - // and also catches JDK 1.9 (and probably later) which + // and also catches JDK 9 (and probably later) which // merged JDK and JRE dirs return getJreExecutable(command); } @@ -427,7 +450,7 @@ public final class JavaEnvUtils { private static void buildJrePackages() { jrePackages = new Vector