https://bz.apache.org/bugzilla/show_bug.cgi?id=65539master
@@ -1,6 +1,14 @@ | |||
Changes from Ant 1.9.16 TO Ant 1.9.17 | |||
===================================== | |||
Fixed bugs: | |||
----------- | |||
* 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 | |||
Changes from Ant 1.9.15 TO Ant 1.9.16 | |||
===================================== | |||
@@ -86,21 +86,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 JAVAC19 = "javac1.9"; | |||
private static final String JAVAC18 = "javac1.8"; | |||
private static final String JAVAC17 = "javac1.7"; | |||
private static final String JAVAC16 = "javac1.6"; | |||
private static final String JAVAC15 = "javac1.5"; | |||
private static final String JAVAC14 = "javac1.4"; | |||
private static final String JAVAC13 = "javac1.3"; | |||
private static final String JAVAC12 = "javac1.2"; | |||
private static final String JAVAC11 = "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 | |||
@@ -162,21 +147,21 @@ public class Javac extends MatchingTask { | |||
private String assumedJavaVersion() { | |||
if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_4)) { | |||
return JAVAC14; | |||
return CompilerAdapterFactory.COMPILER_JAVAC_1_4; | |||
} else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_5)) { | |||
return JAVAC15; | |||
return CompilerAdapterFactory.COMPILER_JAVAC_1_5; | |||
} else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_6)) { | |||
return JAVAC16; | |||
return CompilerAdapterFactory.COMPILER_JAVAC_1_6; | |||
} else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_7)) { | |||
return JAVAC17; | |||
return CompilerAdapterFactory.COMPILER_JAVAC_1_7; | |||
} else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_8)) { | |||
return JAVAC18; | |||
return CompilerAdapterFactory.COMPILER_JAVAC_1_8; | |||
} else if (JavaEnvUtils.isAtLeastJavaVersion("10")) { | |||
return JAVAC10_PLUS; | |||
return CompilerAdapterFactory.COMPILER_JAVAC_10_PLUS; | |||
} else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_9)) { | |||
return JAVAC9; | |||
return CompilerAdapterFactory.COMPILER_JAVAC_9; | |||
} else { | |||
return CLASSIC; | |||
return CompilerAdapterFactory.COMPILER_CLASSIC; | |||
} | |||
} | |||
@@ -886,7 +871,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()); | |||
} | |||
/** | |||
@@ -965,38 +950,22 @@ public class Javac extends MatchingTask { | |||
} | |||
private String getAltCompilerName(final String anImplementation) { | |||
if (JAVAC10_PLUS.equalsIgnoreCase(anImplementation) | |||
|| JAVAC9.equalsIgnoreCase(anImplementation) | |||
|| JAVAC19.equalsIgnoreCase(anImplementation) | |||
|| JAVAC18.equalsIgnoreCase(anImplementation) | |||
|| JAVAC17.equalsIgnoreCase(anImplementation) | |||
|| JAVAC16.equalsIgnoreCase(anImplementation) | |||
|| JAVAC15.equalsIgnoreCase(anImplementation) | |||
|| JAVAC14.equalsIgnoreCase(anImplementation) | |||
|| JAVAC13.equalsIgnoreCase(anImplementation)) { | |||
return MODERN; | |||
if (CompilerAdapterFactory.isModernJdkCompiler(anImplementation)) { | |||
return CompilerAdapterFactory.COMPILER_MODERN; | |||
} | |||
if (JAVAC12.equalsIgnoreCase(anImplementation) | |||
|| JAVAC11.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) | |||
|| JAVAC18.equalsIgnoreCase(nextSelected) | |||
|| JAVAC17.equalsIgnoreCase(nextSelected) | |||
|| JAVAC16.equalsIgnoreCase(nextSelected) | |||
|| JAVAC15.equalsIgnoreCase(nextSelected) | |||
|| JAVAC14.equalsIgnoreCase(nextSelected) | |||
|| JAVAC13.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; | |||
@@ -1256,18 +1225,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) | |||
|| JAVAC18.equals(compilerImpl) | |||
|| JAVAC17.equals(compilerImpl) | |||
|| JAVAC16.equals(compilerImpl) | |||
|| JAVAC15.equals(compilerImpl) | |||
|| JAVAC14.equals(compilerImpl) | |||
|| JAVAC13.equals(compilerImpl) | |||
|| JAVAC12.equals(compilerImpl) | |||
|| JAVAC11.equals(compilerImpl); | |||
return CompilerAdapterFactory.isJdkCompiler(compilerImpl); | |||
} | |||
/** | |||
@@ -1304,7 +1262,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() { | |||
} | |||
@@ -98,33 +178,22 @@ public final class CompilerAdapterFactory { | |||
public static CompilerAdapter getCompiler(String compilerType, Task task, | |||
Path classpath) | |||
throws BuildException { | |||
if (compilerType.equalsIgnoreCase("jikes")) { | |||
if (compilerType.equalsIgnoreCase(COMPILER_JIKES)) { | |||
return new Jikes(); | |||
} | |||
if (compilerType.equalsIgnoreCase("extjavac")) { | |||
if (isForkedJavac(compilerType)) { | |||
return new JavacExternal(); | |||
} | |||
if (compilerType.equalsIgnoreCase("classic") | |||
|| compilerType.equalsIgnoreCase("javac1.1") | |||
|| compilerType.equalsIgnoreCase("javac1.2")) { | |||
if (compilerType.equalsIgnoreCase(COMPILER_CLASSIC) | |||
|| 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 (compilerType.equalsIgnoreCase("modern") | |||
|| compilerType.equalsIgnoreCase("javac1.3") | |||
|| compilerType.equalsIgnoreCase("javac1.4") | |||
|| compilerType.equalsIgnoreCase("javac1.5") | |||
|| compilerType.equalsIgnoreCase("javac1.6") | |||
|| compilerType.equalsIgnoreCase("javac1.7") | |||
|| compilerType.equalsIgnoreCase("javac1.8") | |||
|| compilerType.equalsIgnoreCase("javac1.9") | |||
|| compilerType.equalsIgnoreCase("javac9") | |||
|| compilerType.equalsIgnoreCase("javac10+")) { | |||
if (compilerType.equalsIgnoreCase(COMPILER_MODERN) | |||
|| isModernJdkCompiler(compilerType)) { | |||
// does the modern compiler exist? | |||
if (doesModernCompilerExist()) { | |||
return new Javac13(); | |||
@@ -142,18 +211,18 @@ public final class CompilerAdapterFactory { | |||
} | |||
} | |||
if (compilerType.equalsIgnoreCase("jvc") | |||
|| compilerType.equalsIgnoreCase("microsoft")) { | |||
if (compilerType.equalsIgnoreCase(COMPILER_JVC) | |||
|| compilerType.equalsIgnoreCase(COMPILER_JVC_ALIAS)) { | |||
return new Jvc(); | |||
} | |||
if (compilerType.equalsIgnoreCase("kjc")) { | |||
if (compilerType.equalsIgnoreCase(COMPILER_KJC)) { | |||
return new Kjc(); | |||
} | |||
if (compilerType.equalsIgnoreCase("gcj")) { | |||
if (compilerType.equalsIgnoreCase(COMPILER_GCJ)) { | |||
return new Gcj(); | |||
} | |||
if (compilerType.equalsIgnoreCase("sj") | |||
|| compilerType.equalsIgnoreCase("symantec")) { | |||
if (compilerType.equalsIgnoreCase(COMPILER_SYMANTEC_ALIAS) | |||
|| compilerType.equalsIgnoreCase(COMPILER_SYMANTEC)) { | |||
return new Sj(); | |||
} | |||
return resolveClassName(compilerType, | |||
@@ -201,4 +270,62 @@ public final class CompilerAdapterFactory { | |||
CompilerAdapter.class); | |||
} | |||
/** | |||
* Is the compiler implementation a forked jdk compiler? | |||
* | |||
* @param compilerImpl the name of the compiler implementation | |||
* @since 1.9.17 | |||
*/ | |||
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.9.17 | |||
*/ | |||
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.9.17 | |||
*/ | |||
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.9.17 | |||
*/ | |||
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.9.17 | |||
*/ | |||
public static boolean isModernJdkCompiler(final String compilerName) { | |||
return containsIgnoreCase(MODERN_JDK_COMPILERS, compilerName); | |||
} | |||
private static boolean containsIgnoreCase(final List<String> compilers, final String compilerName) { | |||
for (String compiler : compilers) { | |||
if (compiler.equalsIgnoreCase(compilerName)) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
} |
@@ -632,7 +632,8 @@ public abstract class DefaultCompilerAdapter | |||
* @since Ant 1.5 | |||
*/ | |||
protected boolean assumeJava11() { | |||
return "javac1.1".equals(attributes.getCompilerVersion()); | |||
return CompilerAdapterFactory.COMPILER_JAVAC_1_1 | |||
.equalsIgnoreCase(attributes.getCompilerVersion()); | |||
} | |||
/** | |||
@@ -641,7 +642,8 @@ public abstract class DefaultCompilerAdapter | |||
* @since Ant 1.5 | |||
*/ | |||
protected boolean assumeJava12() { | |||
return "javac1.2".equals(attributes.getCompilerVersion()); | |||
return CompilerAdapterFactory.COMPILER_JAVAC_1_2 | |||
.equalsIgnoreCase(attributes.getCompilerVersion()); | |||
} | |||
/** | |||
@@ -650,7 +652,8 @@ public abstract class DefaultCompilerAdapter | |||
* @since Ant 1.5 | |||
*/ | |||
protected boolean assumeJava13() { | |||
return "javac1.3".equals(attributes.getCompilerVersion()); | |||
return CompilerAdapterFactory.COMPILER_JAVAC_1_3 | |||
.equalsIgnoreCase(attributes.getCompilerVersion()); | |||
} | |||
/** | |||
@@ -659,7 +662,7 @@ public abstract class DefaultCompilerAdapter | |||
* @since Ant 1.6.3 | |||
*/ | |||
protected boolean assumeJava14() { | |||
return assumeJavaXY("javac1.4", JavaEnvUtils.JAVA_1_4); | |||
return assumeJavaXY(CompilerAdapterFactory.COMPILER_JAVAC_1_4, JavaEnvUtils.JAVA_1_4); | |||
} | |||
/** | |||
@@ -668,7 +671,7 @@ public abstract class DefaultCompilerAdapter | |||
* @since Ant 1.6.3 | |||
*/ | |||
protected boolean assumeJava15() { | |||
return assumeJavaXY("javac1.5", JavaEnvUtils.JAVA_1_5); | |||
return assumeJavaXY(CompilerAdapterFactory.COMPILER_JAVAC_1_5, JavaEnvUtils.JAVA_1_5); | |||
} | |||
/** | |||
@@ -677,7 +680,7 @@ public abstract class DefaultCompilerAdapter | |||
* @since Ant 1.7 | |||
*/ | |||
protected boolean assumeJava16() { | |||
return assumeJavaXY("javac1.6", JavaEnvUtils.JAVA_1_6); | |||
return assumeJavaXY(CompilerAdapterFactory.COMPILER_JAVAC_1_6, JavaEnvUtils.JAVA_1_6); | |||
} | |||
/** | |||
@@ -686,7 +689,7 @@ public abstract class DefaultCompilerAdapter | |||
* @since Ant 1.8.2 | |||
*/ | |||
protected boolean assumeJava17() { | |||
return assumeJavaXY("javac1.7", JavaEnvUtils.JAVA_1_7); | |||
return assumeJavaXY(CompilerAdapterFactory.COMPILER_JAVAC_1_7, JavaEnvUtils.JAVA_1_7); | |||
} | |||
/** | |||
@@ -695,7 +698,7 @@ public abstract class DefaultCompilerAdapter | |||
* @since Ant 1.8.3 | |||
*/ | |||
protected boolean assumeJava18() { | |||
return assumeJavaXY("javac1.8", JavaEnvUtils.JAVA_1_8); | |||
return assumeJavaXY(CompilerAdapterFactory.COMPILER_JAVAC_1_8, JavaEnvUtils.JAVA_1_8); | |||
} | |||
/** | |||
@@ -705,8 +708,8 @@ public abstract class DefaultCompilerAdapter | |||
* @deprecated use #assumeJava9 instead | |||
*/ | |||
protected boolean assumeJava19() { | |||
return assumeJavaXY("javac1.9", JavaEnvUtils.JAVA_9) | |||
|| assumeJavaXY("javac9", JavaEnvUtils.JAVA_9); | |||
return assumeJavaXY(CompilerAdapterFactory.COMPILER_JAVAC_9, JavaEnvUtils.JAVA_9) | |||
|| assumeJavaXY(CompilerAdapterFactory.COMPILER_JAVAC_9_ALIAS, JavaEnvUtils.JAVA_9); | |||
} | |||
/** | |||
@@ -724,13 +727,11 @@ public abstract class DefaultCompilerAdapter | |||
* @since Ant 1.9.10 | |||
*/ | |||
protected boolean assumeJava9Plus() { | |||
return "javac1.9".equals(attributes.getCompilerVersion()) | |||
|| "javac9".equals(attributes.getCompilerVersion()) | |||
|| "javac10+".equals(attributes.getCompilerVersion()) | |||
return CompilerAdapterFactory.COMPILER_JAVAC_9.equalsIgnoreCase(attributes.getCompilerVersion()) | |||
|| CompilerAdapterFactory.COMPILER_JAVAC_9_ALIAS.equalsIgnoreCase(attributes.getCompilerVersion()) | |||
|| CompilerAdapterFactory.COMPILER_JAVAC_10_PLUS.equalsIgnoreCase(attributes.getCompilerVersion()) | |||
|| (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9) | |||
&& ("classic".equals(attributes.getCompilerVersion()) | |||
|| "modern".equals(attributes.getCompilerVersion()) | |||
|| "extJavac".equals(attributes.getCompilerVersion()))); | |||
&& CompilerAdapterFactory.isJdkCompilerNickname(attributes.getCompilerVersion())); | |||
} | |||
/** | |||
@@ -738,11 +739,9 @@ public abstract class DefaultCompilerAdapter | |||
* @since Ant 1.8.3 | |||
*/ | |||
private boolean assumeJavaXY(final String javacXY, final String javaEnvVersionXY) { | |||
return javacXY.equals(attributes.getCompilerVersion()) | |||
return javacXY.equalsIgnoreCase(attributes.getCompilerVersion()) | |||
|| (JavaEnvUtils.isJavaVersion(javaEnvVersionXY) | |||
&& ("classic".equals(attributes.getCompilerVersion()) | |||
|| "modern".equals(attributes.getCompilerVersion()) | |||
|| "extJavac".equals(attributes.getCompilerVersion()))); | |||
&& CompilerAdapterFactory.isJdkCompilerNickname(attributes.getCompilerVersion())); | |||
} | |||
/** | |||
@@ -19,21 +19,24 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import java.io.File; | |||
import org.apache.tools.ant.BuildException; | |||
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 org.apache.tools.ant.types.Path; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import static org.apache.tools.ant.AntAssert.assertContains; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.types.Path; | |||
import static org.hamcrest.Matchers.containsString; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertNotNull; | |||
import static org.junit.Assert.assertNull; | |||
import static org.junit.Assert.assertThat; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.junit.Assert.fail; | |||
@@ -74,6 +77,11 @@ public class JavacTest { | |||
assertNotNull("fork via property", javac.getJavacExecutable()); | |||
assertContains("name should contain \"javac\"", "javac", javac.getJavacExecutable()); | |||
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()); | |||
@@ -25,17 +25,21 @@ import java.util.Collections; | |||
import java.util.List; | |||
import java.util.Set; | |||
import java.util.TreeSet; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.Project; | |||
import org.apache.tools.ant.taskdefs.Javac; | |||
import org.apache.tools.ant.types.Commandline; | |||
import org.junit.Test; | |||
import static org.apache.tools.ant.AntAssert.assertContains; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.types.Path; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.util.JavaEnvUtils; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import static org.apache.tools.ant.AntAssert.assertContains; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertFalse; | |||
import static org.junit.Assert.assertTrue; | |||
public class DefaultCompilerAdapterTest { | |||
@@ -449,6 +453,47 @@ public class DefaultCompilerAdapterTest { | |||
assertEquals("6", args[4]); | |||
} | |||
/** | |||
* @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_9)) { | |||
assertTrue(ca.assumeJava9Plus()); | |||
assertTrue(ca.assumeJava9()); | |||
assertTrue(ca.assumeJava19()); | |||
assertFalse(ca.assumeJava18()); | |||
} else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_8)) { | |||
assertFalse(ca.assumeJava9Plus()); | |||
assertFalse(ca.assumeJava9()); | |||
assertTrue(ca.assumeJava18()); | |||
assertFalse(ca.assumeJava17()); | |||
} else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_7)) { | |||
assertFalse(ca.assumeJava9Plus()); | |||
assertFalse(ca.assumeJava18()); | |||
assertTrue(ca.assumeJava17()); | |||
assertFalse(ca.assumeJava16()); | |||
} else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_6)) { | |||
assertFalse(ca.assumeJava9Plus()); | |||
assertFalse(ca.assumeJava17()); | |||
assertTrue(ca.assumeJava16()); | |||
assertFalse(ca.assumeJava15()); | |||
} else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_5)) { | |||
assertFalse(ca.assumeJava9Plus()); | |||
assertFalse(ca.assumeJava16()); | |||
assertTrue(ca.assumeJava15()); | |||
assertFalse(ca.assumeJava14()); | |||
} | |||
} | |||
private void commonSourceDowngrades(String javaVersion) { | |||
testSource("1.3", javaVersion, | |||
"If you specify -target 1.1 you now must also specify" | |||