| @@ -8,6 +8,11 @@ Fixed bugs: | |||
| was set to "false". This has now been fixed. | |||
| Bugzilla Report 65489 | |||
| * Made sure setting build.compiler to the fully qualified classname | |||
| that corresponds to extJavac or modern has the same effect as using | |||
| the shorter alias names. | |||
| Bugzilla Report 65539 | |||
| Other changes: | |||
| -------------- | |||
| @@ -85,21 +85,6 @@ public class Javac extends MatchingTask { | |||
| private static final String FAIL_MSG | |||
| = "Compile failed; see the compiler error output for details."; | |||
| private static final String JAVAC10_PLUS = "javac10+"; | |||
| private static final String JAVAC9 = "javac9"; | |||
| private static final String JAVAC9_ALIAS = "javac1.9"; | |||
| private static final String JAVAC1_8 = "javac1.8"; | |||
| private static final String JAVAC1_7 = "javac1.7"; | |||
| private static final String JAVAC1_6 = "javac1.6"; | |||
| private static final String JAVAC1_5 = "javac1.5"; | |||
| private static final String JAVAC1_4 = "javac1.4"; | |||
| private static final String JAVAC1_3 = "javac1.3"; | |||
| private static final String JAVAC1_2 = "javac1.2"; | |||
| private static final String JAVAC1_1 = "javac1.1"; | |||
| private static final String MODERN = "modern"; | |||
| private static final String CLASSIC = "classic"; | |||
| private static final String EXTJAVAC = "extJavac"; | |||
| private static final char GROUP_START_MARK = '{'; //modulesourcepath group start character | |||
| private static final char GROUP_END_MARK = '}'; //modulesourcepath group end character | |||
| private static final char GROUP_SEP_MARK = ','; //modulesourcepath group element separator character | |||
| @@ -161,15 +146,16 @@ public class Javac extends MatchingTask { | |||
| private String assumedJavaVersion() { | |||
| if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_8)) { | |||
| return JAVAC1_8; | |||
| return CompilerAdapterFactory.COMPILER_JAVAC_1_8; | |||
| } | |||
| if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_9)) { | |||
| return JAVAC9; | |||
| return CompilerAdapterFactory.COMPILER_JAVAC_9; | |||
| } | |||
| if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_10)) { | |||
| return JAVAC10_PLUS; | |||
| return CompilerAdapterFactory.COMPILER_JAVAC_10_PLUS; | |||
| } | |||
| return MODERN; // as we are assumed to be 1.8+ and classic refers to the really old ones, default to modern | |||
| // as we are assumed to be 1.8+ and classic refers to the really old ones, default to modern | |||
| return CompilerAdapterFactory.COMPILER_MODERN; | |||
| } | |||
| /** | |||
| @@ -878,7 +864,7 @@ public class Javac extends MatchingTask { | |||
| * @return true if this is a forked invocation | |||
| */ | |||
| public boolean isForkedJavac() { | |||
| return fork || EXTJAVAC.equalsIgnoreCase(getCompiler()); | |||
| return fork || CompilerAdapterFactory.isForkedJavac(getCompiler()); | |||
| } | |||
| /** | |||
| @@ -957,33 +943,22 @@ public class Javac extends MatchingTask { | |||
| } | |||
| private String getAltCompilerName(final String anImplementation) { | |||
| if (JAVAC10_PLUS.equalsIgnoreCase(anImplementation) | |||
| || JAVAC9.equalsIgnoreCase(anImplementation) | |||
| || JAVAC9_ALIAS.equalsIgnoreCase(anImplementation) | |||
| || JAVAC1_8.equalsIgnoreCase(anImplementation) | |||
| || JAVAC1_7.equalsIgnoreCase(anImplementation) | |||
| || JAVAC1_6.equalsIgnoreCase(anImplementation) | |||
| || JAVAC1_5.equalsIgnoreCase(anImplementation) | |||
| || JAVAC1_4.equalsIgnoreCase(anImplementation) | |||
| || JAVAC1_3.equalsIgnoreCase(anImplementation)) { | |||
| return MODERN; | |||
| if (CompilerAdapterFactory.isModernJdkCompiler(anImplementation)) { | |||
| return CompilerAdapterFactory.COMPILER_MODERN; | |||
| } | |||
| if (JAVAC1_2.equalsIgnoreCase(anImplementation) | |||
| || JAVAC1_1.equalsIgnoreCase(anImplementation)) { | |||
| return CLASSIC; | |||
| if (CompilerAdapterFactory.isClassicJdkCompiler(anImplementation)) { | |||
| return CompilerAdapterFactory.COMPILER_CLASSIC; | |||
| } | |||
| if (MODERN.equalsIgnoreCase(anImplementation)) { | |||
| if (CompilerAdapterFactory.COMPILER_MODERN.equalsIgnoreCase(anImplementation)) { | |||
| final String nextSelected = assumedJavaVersion(); | |||
| if (JAVAC10_PLUS.equalsIgnoreCase(anImplementation) | |||
| || JAVAC9.equalsIgnoreCase(nextSelected) | |||
| || JAVAC1_8.equalsIgnoreCase(nextSelected)) { | |||
| if (CompilerAdapterFactory.isModernJdkCompiler(nextSelected)) { | |||
| return nextSelected; | |||
| } | |||
| } | |||
| if (CLASSIC.equalsIgnoreCase(anImplementation)) { | |||
| if (CompilerAdapterFactory.COMPILER_CLASSIC.equalsIgnoreCase(anImplementation)) { | |||
| return assumedJavaVersion(); | |||
| } | |||
| if (EXTJAVAC.equalsIgnoreCase(anImplementation)) { | |||
| if (CompilerAdapterFactory.isForkedJavac(anImplementation)) { | |||
| return assumedJavaVersion(); | |||
| } | |||
| return null; | |||
| @@ -1242,18 +1217,7 @@ public class Javac extends MatchingTask { | |||
| * "javac1.6", "javac1.7", "javac1.8", "javac1.9", "javac9" or "javac10+". | |||
| */ | |||
| protected boolean isJdkCompiler(final String compilerImpl) { | |||
| return MODERN.equals(compilerImpl) | |||
| || CLASSIC.equals(compilerImpl) | |||
| || JAVAC10_PLUS.equals(compilerImpl) | |||
| || JAVAC9.equals(compilerImpl) | |||
| || JAVAC1_8.equals(compilerImpl) | |||
| || JAVAC1_7.equals(compilerImpl) | |||
| || JAVAC1_6.equals(compilerImpl) | |||
| || JAVAC1_5.equals(compilerImpl) | |||
| || JAVAC1_4.equals(compilerImpl) | |||
| || JAVAC1_3.equals(compilerImpl) | |||
| || JAVAC1_2.equals(compilerImpl) | |||
| || JAVAC1_1.equals(compilerImpl); | |||
| return CompilerAdapterFactory.isJdkCompiler(compilerImpl); | |||
| } | |||
| /** | |||
| @@ -1290,7 +1254,7 @@ public class Javac extends MatchingTask { | |||
| String compilerImpl = getCompilerVersion(); | |||
| if (fork) { | |||
| if (isJdkCompiler(compilerImpl)) { | |||
| compilerImpl = EXTJAVAC; | |||
| compilerImpl = CompilerAdapterFactory.COMPILER_EXTJAVAC; | |||
| } else { | |||
| log("Since compiler setting isn't classic or modern, ignoring fork setting.", | |||
| Project.MSG_WARN); | |||
| @@ -18,6 +18,9 @@ | |||
| package org.apache.tools.ant.taskdefs.compilers; | |||
| import java.util.Arrays; | |||
| import java.util.List; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.Task; | |||
| @@ -33,6 +36,83 @@ import org.apache.tools.ant.util.JavaEnvUtils; | |||
| public final class CompilerAdapterFactory { | |||
| private static final String MODERN_COMPILER = "com.sun.tools.javac.Main"; | |||
| public static final String COMPILER_JIKES = "jikes"; | |||
| public static final String COMPILER_GCJ = "gcj"; | |||
| public static final String COMPILER_SYMANTEC_ALIAS = "sj"; | |||
| public static final String COMPILER_SYMANTEC = "symantec"; | |||
| public static final String COMPILER_JVC_ALIAS = "microsoft"; | |||
| public static final String COMPILER_JVC = "jvc"; | |||
| public static final String COMPILER_KJC = "kjc"; | |||
| public static final String COMPILER_JAVAC_1_1 = "javac1.1"; | |||
| public static final String COMPILER_JAVAC_1_2 = "javac1.2"; | |||
| public static final String COMPILER_JAVAC_1_3 = "javac1.3"; | |||
| public static final String COMPILER_JAVAC_1_4 = "javac1.4"; | |||
| public static final String COMPILER_JAVAC_1_5 = "javac1.5"; | |||
| public static final String COMPILER_JAVAC_1_6 = "javac1.6"; | |||
| public static final String COMPILER_JAVAC_1_7 = "javac1.7"; | |||
| public static final String COMPILER_JAVAC_1_8 = "javac1.8"; | |||
| public static final String COMPILER_JAVAC_9_ALIAS = "javac1.9"; | |||
| public static final String COMPILER_JAVAC_9 = "javac9"; | |||
| public static final String COMPILER_JAVAC_10_PLUS = "javac10+"; | |||
| public static final String COMPILER_CLASSIC = "classic"; | |||
| public static final String COMPILER_MODERN = "modern"; | |||
| public static final String COMPILER_EXTJAVAC = "extJavac"; | |||
| public static final String COMPILER_MODERN_CLASSNAME = Javac13.class.getName(); | |||
| public static final String COMPILER_EXTJAVAC_CLASSNAME = JavacExternal.class.getName(); | |||
| private static final List<String> JDK_COMPILERS = Arrays.asList( | |||
| COMPILER_JAVAC_1_1, | |||
| COMPILER_JAVAC_1_2, | |||
| COMPILER_JAVAC_1_3, | |||
| COMPILER_JAVAC_1_4, | |||
| COMPILER_JAVAC_1_5, | |||
| COMPILER_JAVAC_1_6, | |||
| COMPILER_JAVAC_1_7, | |||
| COMPILER_JAVAC_1_8, | |||
| COMPILER_JAVAC_9_ALIAS, | |||
| COMPILER_JAVAC_9, | |||
| COMPILER_JAVAC_10_PLUS, | |||
| COMPILER_CLASSIC, | |||
| COMPILER_MODERN, | |||
| COMPILER_EXTJAVAC, | |||
| COMPILER_MODERN_CLASSNAME, | |||
| COMPILER_EXTJAVAC_CLASSNAME | |||
| ); | |||
| private static final List<String> FORKED_JDK_COMPILERS = Arrays.asList( | |||
| COMPILER_EXTJAVAC, | |||
| COMPILER_EXTJAVAC_CLASSNAME | |||
| ); | |||
| private static final List<String> JDK_COMPILER_NICKNAMES = Arrays.asList( | |||
| COMPILER_CLASSIC, | |||
| COMPILER_MODERN, | |||
| COMPILER_EXTJAVAC, | |||
| COMPILER_MODERN_CLASSNAME, | |||
| COMPILER_EXTJAVAC_CLASSNAME | |||
| ); | |||
| private static final List<String> CLASSIC_JDK_COMPILERS = Arrays.asList( | |||
| COMPILER_JAVAC_1_1, | |||
| COMPILER_JAVAC_1_2 | |||
| ); | |||
| private static final List<String> MODERN_JDK_COMPILERS = Arrays.asList( | |||
| COMPILER_JAVAC_1_3, | |||
| COMPILER_JAVAC_1_4, | |||
| COMPILER_JAVAC_1_5, | |||
| COMPILER_JAVAC_1_6, | |||
| COMPILER_JAVAC_1_7, | |||
| COMPILER_JAVAC_1_8, | |||
| COMPILER_JAVAC_9_ALIAS, | |||
| COMPILER_JAVAC_9, | |||
| COMPILER_JAVAC_10_PLUS, | |||
| COMPILER_MODERN_CLASSNAME | |||
| ); | |||
| /** This is a singleton -- can't create instances!! */ | |||
| private CompilerAdapterFactory() { | |||
| } | |||
| @@ -97,32 +177,21 @@ public final class CompilerAdapterFactory { | |||
| */ | |||
| public static CompilerAdapter getCompiler(String compilerType, Task task, | |||
| Path classpath) throws BuildException { | |||
| if ("jikes".equalsIgnoreCase(compilerType)) { | |||
| if (COMPILER_JIKES.equalsIgnoreCase(compilerType)) { | |||
| return new Jikes(); | |||
| } | |||
| if ("extjavac".equalsIgnoreCase(compilerType)) { | |||
| if (isForkedJavac(compilerType)) { | |||
| return new JavacExternal(); | |||
| } | |||
| if ("classic".equalsIgnoreCase(compilerType) | |||
| || "javac1.1".equalsIgnoreCase(compilerType) | |||
| || "javac1.2".equalsIgnoreCase(compilerType)) { | |||
| if (COMPILER_CLASSIC.equalsIgnoreCase(compilerType) | |||
| || isClassicJdkCompiler(compilerType)) { | |||
| task.log( | |||
| "This version of java does not support the classic compiler; upgrading to modern", | |||
| Project.MSG_WARN); | |||
| compilerType = "modern"; | |||
| compilerType = COMPILER_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 | |||
| if ("modern".equalsIgnoreCase(compilerType) | |||
| || "javac1.3".equalsIgnoreCase(compilerType) | |||
| || "javac1.4".equalsIgnoreCase(compilerType) | |||
| || "javac1.5".equalsIgnoreCase(compilerType) | |||
| || "javac1.6".equalsIgnoreCase(compilerType) | |||
| || "javac1.7".equalsIgnoreCase(compilerType) | |||
| || "javac1.8".equalsIgnoreCase(compilerType) | |||
| || "javac1.9".equalsIgnoreCase(compilerType) | |||
| || "javac9".equalsIgnoreCase(compilerType) | |||
| || "javac10+".equalsIgnoreCase(compilerType)) { | |||
| if (COMPILER_MODERN.equalsIgnoreCase(compilerType) | |||
| || isModernJdkCompiler(compilerType)) { | |||
| // does the modern compiler exist? | |||
| if (doesModernCompilerExist()) { | |||
| return new Javac13(); | |||
| @@ -132,18 +201,18 @@ public final class CompilerAdapterFactory { | |||
| MODERN_COMPILER, JavaEnvUtils.getJavaHome()); | |||
| } | |||
| if ("jvc".equalsIgnoreCase(compilerType) | |||
| || "microsoft".equalsIgnoreCase(compilerType)) { | |||
| if (COMPILER_JVC.equalsIgnoreCase(compilerType) | |||
| || COMPILER_JVC_ALIAS.equalsIgnoreCase(compilerType)) { | |||
| return new Jvc(); | |||
| } | |||
| if ("kjc".equalsIgnoreCase(compilerType)) { | |||
| if (COMPILER_KJC.equalsIgnoreCase(compilerType)) { | |||
| return new Kjc(); | |||
| } | |||
| if ("gcj".equalsIgnoreCase(compilerType)) { | |||
| if (COMPILER_GCJ.equalsIgnoreCase(compilerType)) { | |||
| return new Gcj(); | |||
| } | |||
| if ("sj".equalsIgnoreCase(compilerType) | |||
| || "symantec".equalsIgnoreCase(compilerType)) { | |||
| if (COMPILER_SYMANTEC_ALIAS.equalsIgnoreCase(compilerType) | |||
| || COMPILER_SYMANTEC.equalsIgnoreCase(compilerType)) { | |||
| return new Sj(); | |||
| } | |||
| return resolveClassName(compilerType, | |||
| @@ -191,4 +260,57 @@ public final class CompilerAdapterFactory { | |||
| CompilerAdapter.class); | |||
| } | |||
| /** | |||
| * Is the compiler implementation a forked jdk compiler? | |||
| * | |||
| * @param compilerImpl the name of the compiler implementation | |||
| * @since 1.10.12 | |||
| */ | |||
| public static boolean isForkedJavac(final String compilerName) { | |||
| return containsIgnoreCase(FORKED_JDK_COMPILERS, compilerName); | |||
| } | |||
| /** | |||
| * Is the compiler implementation a jdk compiler? | |||
| * | |||
| * @param compilerImpl the name of the compiler implementation | |||
| * @since 1.10.12 | |||
| */ | |||
| public static boolean isJdkCompiler(final String compilerName) { | |||
| return containsIgnoreCase(JDK_COMPILERS, compilerName); | |||
| } | |||
| /** | |||
| * Is the compiler implementation a jdk compiler without specified version? | |||
| * | |||
| * @param compilerImpl the name of the compiler implementation | |||
| * @since 1.10.12 | |||
| */ | |||
| public static boolean isJdkCompilerNickname(final String compilerName) { | |||
| return containsIgnoreCase(JDK_COMPILER_NICKNAMES, compilerName); | |||
| } | |||
| /** | |||
| * Does the compiler correspond to "classic"? | |||
| * | |||
| * @param compilerImpl the name of the compiler implementation | |||
| * @since 1.10.12 | |||
| */ | |||
| public static boolean isClassicJdkCompiler(final String compilerName) { | |||
| return containsIgnoreCase(CLASSIC_JDK_COMPILERS, compilerName); | |||
| } | |||
| /** | |||
| * Does the compiler correspond to "modern"? | |||
| * | |||
| * @param compilerImpl the name of the compiler implementation | |||
| * @since 1.10.12 | |||
| */ | |||
| public static boolean isModernJdkCompiler(final String compilerName) { | |||
| return containsIgnoreCase(MODERN_JDK_COMPILERS, compilerName); | |||
| } | |||
| private static boolean containsIgnoreCase(final List<String> compilers, final String compilerName) { | |||
| return compilerName != null && compilers.stream().anyMatch(compilerName::equalsIgnoreCase); | |||
| } | |||
| } | |||
| @@ -637,7 +637,9 @@ public abstract class DefaultCompilerAdapter | |||
| * @since Ant 1.10.7 | |||
| */ | |||
| protected boolean assumeJava1_1Plus() { | |||
| return "javac1.1".equals(attributes.getCompilerVersion()) || assumeJava1_2Plus() ; | |||
| return CompilerAdapterFactory.COMPILER_JAVAC_1_1 | |||
| .equalsIgnoreCase(attributes.getCompilerVersion()) | |||
| || assumeJava1_2Plus(); | |||
| } | |||
| /** | |||
| @@ -657,7 +659,9 @@ public abstract class DefaultCompilerAdapter | |||
| * @since Ant 1.10.7 | |||
| */ | |||
| protected boolean assumeJava1_2Plus() { | |||
| return "javac1.2".equals(attributes.getCompilerVersion()) || assumeJava1_3Plus() ; | |||
| return CompilerAdapterFactory.COMPILER_JAVAC_1_2 | |||
| .equalsIgnoreCase(attributes.getCompilerVersion()) | |||
| || assumeJava1_3Plus(); | |||
| } | |||
| /** | |||
| @@ -677,7 +681,9 @@ public abstract class DefaultCompilerAdapter | |||
| * @since Ant 1.10.7 | |||
| */ | |||
| protected boolean assumeJava1_3Plus() { | |||
| return "javac1.3".equals(attributes.getCompilerVersion()) || assumeJava1_4Plus() ; | |||
| return CompilerAdapterFactory.COMPILER_JAVAC_1_3 | |||
| .equalsIgnoreCase(attributes.getCompilerVersion()) | |||
| || assumeJava1_4Plus(); | |||
| } | |||
| /** | |||
| @@ -697,7 +703,8 @@ public abstract class DefaultCompilerAdapter | |||
| * @since Ant 1.10.7 | |||
| */ | |||
| protected boolean assumeJava1_4Plus() { | |||
| return assumeJavaXY("javac1.4", JavaEnvUtils.JAVA_1_4) || assumeJava1_5Plus() ; | |||
| return assumeJavaXY(CompilerAdapterFactory.COMPILER_JAVAC_1_4, JavaEnvUtils.JAVA_1_4) | |||
| || assumeJava1_5Plus(); | |||
| } | |||
| /** | |||
| @@ -717,7 +724,8 @@ public abstract class DefaultCompilerAdapter | |||
| * @since Ant 1.10.7 | |||
| */ | |||
| protected boolean assumeJava1_5Plus() { | |||
| return assumeJavaXY("javac1.5", JavaEnvUtils.JAVA_1_5) || assumeJava1_6Plus() ; | |||
| return assumeJavaXY(CompilerAdapterFactory.COMPILER_JAVAC_1_5, JavaEnvUtils.JAVA_1_5) | |||
| || assumeJava1_6Plus(); | |||
| } | |||
| /** | |||
| @@ -737,7 +745,8 @@ public abstract class DefaultCompilerAdapter | |||
| * @since Ant 1.10.7 | |||
| */ | |||
| protected boolean assumeJava1_6Plus() { | |||
| return assumeJavaXY("javac1.6", JavaEnvUtils.JAVA_1_6) || assumeJava1_7Plus() ; | |||
| return assumeJavaXY(CompilerAdapterFactory.COMPILER_JAVAC_1_6, JavaEnvUtils.JAVA_1_6) | |||
| || assumeJava1_7Plus() ; | |||
| } | |||
| /** | |||
| @@ -757,7 +766,8 @@ public abstract class DefaultCompilerAdapter | |||
| * @since Ant 1.10.7 | |||
| */ | |||
| protected boolean assumeJava1_7Plus() { | |||
| return assumeJavaXY("javac1.7", JavaEnvUtils.JAVA_1_7) || assumeJava1_8Plus() ; | |||
| return assumeJavaXY(CompilerAdapterFactory.COMPILER_JAVAC_1_7, JavaEnvUtils.JAVA_1_7) | |||
| || assumeJava1_8Plus(); | |||
| } | |||
| /** | |||
| @@ -777,7 +787,8 @@ public abstract class DefaultCompilerAdapter | |||
| * @since Ant 1.10.7 | |||
| */ | |||
| protected boolean assumeJava1_8Plus() { | |||
| return assumeJavaXY("javac1.8", JavaEnvUtils.JAVA_1_8) || assumeJava9Plus() ; | |||
| return assumeJavaXY(CompilerAdapterFactory.COMPILER_JAVAC_1_8, JavaEnvUtils.JAVA_1_8) | |||
| || assumeJava9Plus(); | |||
| } | |||
| /** | |||
| @@ -808,9 +819,9 @@ public abstract class DefaultCompilerAdapter | |||
| * @since Ant 1.10.2 | |||
| */ | |||
| protected boolean assumeJava9Plus() { | |||
| return assumeJavaXY("javac1.9", JavaEnvUtils.JAVA_9) | |||
| || assumeJavaXY("javac9", JavaEnvUtils.JAVA_9) | |||
| || assumeJava10Plus(); | |||
| return assumeJavaXY(CompilerAdapterFactory.COMPILER_JAVAC_9, JavaEnvUtils.JAVA_9) | |||
| || assumeJavaXY(CompilerAdapterFactory.COMPILER_JAVAC_9_ALIAS, JavaEnvUtils.JAVA_9) | |||
| || assumeJava10Plus(); | |||
| } | |||
| /** | |||
| @@ -819,11 +830,9 @@ public abstract class DefaultCompilerAdapter | |||
| * @since Ant 1.10.7 | |||
| */ | |||
| protected boolean assumeJava10Plus() { | |||
| return "javac10+".equals(attributes.getCompilerVersion()) | |||
| return CompilerAdapterFactory.COMPILER_JAVAC_10_PLUS.equalsIgnoreCase(attributes.getCompilerVersion()) | |||
| || (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_10) | |||
| && ("classic".equals(attributes.getCompilerVersion()) | |||
| || "modern".equals(attributes.getCompilerVersion()) | |||
| || "extJavac".equals(attributes.getCompilerVersion()))); | |||
| && CompilerAdapterFactory.isJdkCompilerNickname(attributes.getCompilerVersion())); | |||
| } | |||
| /** | |||
| @@ -832,11 +841,9 @@ public abstract class DefaultCompilerAdapter | |||
| */ | |||
| private boolean assumeJavaXY(final String javacXY, final String javaEnvVersionXY) { | |||
| String compilerVersion = attributes.getCompilerVersion(); | |||
| return javacXY.equals(compilerVersion) || | |||
| return javacXY.equalsIgnoreCase(compilerVersion) || | |||
| (JavaEnvUtils.isJavaVersion(javaEnvVersionXY) | |||
| && ("classic".equals(compilerVersion) | |||
| || "modern".equals(compilerVersion) | |||
| || "extJavac".equals(compilerVersion))); | |||
| && CompilerAdapterFactory.isJdkCompilerNickname(attributes.getCompilerVersion())); | |||
| } | |||
| /** | |||
| @@ -77,6 +77,11 @@ public class JavacTest { | |||
| assertNotNull("fork via property", javac.getJavacExecutable()); | |||
| assertThat("name should contain \"javac\"", javac.getJavacExecutable(), containsString("javac")); | |||
| project.setProperty("build.compiler", "org.apache.tools.ant.taskdefs.compilers.JavacExternal"); | |||
| javac.setFork(false); | |||
| assertNotNull("fork via property", javac.getJavacExecutable()); | |||
| assertThat("name should contain \"javac\"", javac.getJavacExecutable(), containsString("javac")); | |||
| project.setProperty("build.compiler", "whatever"); | |||
| assertNull("no fork and not extJavac means no executable", javac.getJavacExecutable()); | |||
| @@ -540,7 +540,33 @@ public class DefaultCompilerAdapterTest { | |||
| } | |||
| /** | |||
| * @see "https://bz.apache.org/bugzilla/show_bug.cgi?id=65539" | |||
| */ | |||
| @Test | |||
| public void assumeJavaXPlusWorksWithBuildCompilerSetToExplicitAdapterName() { | |||
| LogCapturingJavac javac = new LogCapturingJavac(); | |||
| Project p = new Project(); | |||
| p.setProperty("build.compiler", "org.apache.tools.ant.taskdefs.compilers.JavacExternal"); | |||
| javac.setProject(p); | |||
| javac.setFork(true); | |||
| javac.setSourcepath(new Path(p)); | |||
| SourceTargetHelperNoOverride ca = new SourceTargetHelperNoOverride(); | |||
| ca.setJavac(javac); | |||
| if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_10)) { | |||
| assertTrue(ca.assumeJava10Plus()); | |||
| assertTrue(ca.assumeJava9Plus()); | |||
| } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_9)) { | |||
| assertFalse(ca.assumeJava10Plus()); | |||
| assertTrue(ca.assumeJava9Plus()); | |||
| } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_8)) { | |||
| assertFalse(ca.assumeJava10Plus()); | |||
| assertFalse(ca.assumeJava9Plus()); | |||
| } | |||
| assertTrue(ca.assumeJava1_8Plus()); | |||
| assertTrue(ca.assumeJava1_7Plus()); | |||
| assertTrue(ca.assumeJava1_2Plus()); | |||
| } | |||
| private void commonSourceDowngrades(String javaVersion) { | |||
| testSource("1.3", javaVersion, | |||