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 040460077..aeecb4a50 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/CompilerAdapterFactory.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/CompilerAdapterFactory.java @@ -121,7 +121,8 @@ public final class CompilerAdapterFactory { || compilerType.equalsIgnoreCase("javac1.5") || compilerType.equalsIgnoreCase("javac1.6") || compilerType.equalsIgnoreCase("javac1.7") - || compilerType.equalsIgnoreCase("javac1.8")) { + || compilerType.equalsIgnoreCase("javac1.8") + || compilerType.equalsIgnoreCase("javac1.9")) { // 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 88a74f775..c5a139102 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java @@ -605,6 +605,15 @@ public abstract class DefaultCompilerAdapter return assumeJavaXY("javac1.8", JavaEnvUtils.JAVA_1_8); } + /** + * Shall we assume JDK 1.9 command line switches? + * @return true if JDK 1.9 + * @since Ant 1.9.4 + */ + protected boolean assumeJava19() { + return assumeJavaXY("javac1.9", JavaEnvUtils.JAVA_1_8); + } + /** * Shall we assume command line switches for the given version of Java? * @since Ant 1.8.3 diff --git a/src/tests/antunit/antunit-base.xml b/src/tests/antunit/antunit-base.xml index 7d05913aa..80b289cac 100644 --- a/src/tests/antunit/antunit-base.xml +++ b/src/tests/antunit/antunit-base.xml @@ -27,6 +27,9 @@ + + + diff --git a/src/tests/antunit/taskdefs/javac-test.xml b/src/tests/antunit/taskdefs/javac-test.xml index 3e5ceba04..1ad4a49cc 100644 --- a/src/tests/antunit/taskdefs/javac-test.xml +++ b/src/tests/antunit/taskdefs/javac-test.xml @@ -197,4 +197,116 @@ public class Adapter implements CompilerAdapter { + + + + + + + public class A { } + + + + + + + + + + JDK 1.4+ + + + + + + JDK 1.5+ + + + + + + + JDK 1.6+ + + + + + + + JDK 1.7+ + + + + + + + JDK 1.8+ + + + + + + + JDK 1.9+ + + + + + + + + + + + + public class A { } + + + + + + + + + + JDK 1.4+ + + + + + + JDK 1.5+ + + + + + + + JDK 1.6+ + + + + + + + JDK 1.7+ + + + + + + + JDK 1.8+ + + + + + + + JDK 1.9+ + + + + + diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java index 175086eeb..8e0697c2e 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java @@ -18,13 +18,21 @@ package org.apache.tools.ant.taskdefs; +import java.io.File; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Date; +import java.util.List; + +import junit.framework.TestCase; + 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.Javac13; import org.apache.tools.ant.taskdefs.compilers.JavacExternal; - -import junit.framework.TestCase; +import org.apache.tools.ant.types.Path; /** * Testcase for . diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java index c2cec6e66..503bc3f06 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java @@ -133,6 +133,36 @@ public class DefaultCompilerAdapterTest extends TestCase { testSource(null, "javac1.8", "", "8"); } + public void testImplicitSourceForJava19() { + commonSourceDowngrades("javac1.9"); + testSource("1.5", "javac1.9", + "If you specify -target 1.5 you now must also specify" + + " -source 1.5", "1.5"); + testSource("1.6", "javac1.9", + "If you specify -target 1.6 you now must also specify" + + " -source 1.6", "1.6"); + testSource("1.7", "javac1.9", + "If you specify -target 1.7 you now must also specify" + + " -source 1.7", "1.7"); + testSource("1.8", "javac1.9", + "If you specify -target 1.8 you now must also specify" + + " -source 1.8", "1.8"); + testSource("5", "javac1.9", + "If you specify -target 5 you now must also specify" + + " -source 5", "5"); + testSource("6", "javac1.9", + "If you specify -target 6 you now must also specify" + + " -source 6", "6"); + testSource("7", "javac1.9", + "If you specify -target 7 you now must also specify" + + " -source 7", "7"); + testSource("8", "javac1.9", + "If you specify -target 8 you now must also specify" + + " -source 8", "8"); + testSource(null, "javac1.9", "", "1.8"); + testSource(null, "javac1.9", "", "8"); + } + private void commonSourceDowngrades(String javaVersion) { testSource("1.3", javaVersion, "If you specify -target 1.1 you now must also specify"