You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2021/09/02 12:01:07 UTC
[ant] 01/01: Merge branch '1.9.x'
This is an automated email from the ASF dual-hosted git repository.
bodewig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git
commit 9943641b56b712d564340da122ca2b0f6f9e3bd3
Merge: 5aca870 e5e0019
Author: Stefan Bodewig <bo...@apache.org>
AuthorDate: Thu Sep 2 14:00:51 2021 +0200
Merge branch '1.9.x'
WHATSNEW | 5 +
src/main/org/apache/tools/ant/taskdefs/Javac.java | 68 ++-------
.../taskdefs/compilers/CompilerAdapterFactory.java | 170 ++++++++++++++++++---
.../taskdefs/compilers/DefaultCompilerAdapter.java | 45 +++---
.../org/apache/tools/ant/taskdefs/JavacTest.java | 5 +
.../compilers/DefaultCompilerAdapterTest.java | 28 +++-
6 files changed, 225 insertions(+), 96 deletions(-)
diff --cc WHATSNEW
index 68b2ccf,f3f9ddf..1fba75e
--- a/WHATSNEW
+++ b/WHATSNEW
@@@ -4,36 -4,13 +4,41 @@@ Changes from Ant 1.10.11 TO Ant 1.10.1
Fixed bugs:
-----------
+ * The http condition would follow redirects even when "followRedirects" attribute
+ 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
+
-Changes from Ant 1.9.15 TO Ant 1.9.16
-=====================================
+Other changes:
+--------------
+
+ * The implementation of AntClassLoader#findResources() has been changed to optimize
+ it for potential performance issues, as those noted at
+ https://issues.jenkins.io/browse/JENKINS-22310?focusedCommentId=197405&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-197405
+ Github Pull Request #151
+
+ * AntClassLoader now implements the ClassLoader#findResource(String) method.
+ Github Pull Request #150
+
+ * Ant tries to avoid file name canonicalization whne possible.
+ Bugzilla Report 65499
+
+Changes from Ant 1.10.10 TO Ant 1.10.11
+=======================================
+
+Fixed bugs:
+-----------
+
+ * a race condition could lead to NullPointerExceptions when running
+ tasks in parallel.
+ Bugzilla Report 65316
+
+ * fixed potential OutOfMemory errors when reading broken archives
+ using the tar or zip formats or formats derived from zip.
Other changes:
--------------
diff --cc src/main/org/apache/tools/ant/taskdefs/Javac.java
index ad4ce2a,a9bcb6a..f79a4aa
--- a/src/main/org/apache/tools/ant/taskdefs/Javac.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Javac.java
@@@ -160,16 -146,23 +145,17 @@@ public class Javac extends MatchingTas
}
private String assumedJavaVersion() {
- if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_4)) {
- return CompilerAdapterFactory.COMPILER_JAVAC_1_4;
- } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_5)) {
- return CompilerAdapterFactory.COMPILER_JAVAC_1_5;
- } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_6)) {
- return CompilerAdapterFactory.COMPILER_JAVAC_1_6;
- } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_7)) {
- return CompilerAdapterFactory.COMPILER_JAVAC_1_7;
- } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_8)) {
+ if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_8)) {
- return JAVAC1_8;
+ return CompilerAdapterFactory.COMPILER_JAVAC_1_8;
- } else if (JavaEnvUtils.isAtLeastJavaVersion("10")) {
- return CompilerAdapterFactory.COMPILER_JAVAC_10_PLUS;
- } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_9)) {
+ }
+ if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_9)) {
- return JAVAC9;
+ return CompilerAdapterFactory.COMPILER_JAVAC_9;
- } else {
- return CompilerAdapterFactory.COMPILER_CLASSIC;
}
+ 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;
}
/**
@@@ -1290,10 -1262,10 +1254,10 @@@
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);
+ log("Since compiler setting isn't classic or modern, ignoring fork setting.",
+ Project.MSG_WARN);
}
}
return compilerImpl;
diff --cc src/main/org/apache/tools/ant/taskdefs/compilers/CompilerAdapterFactory.java
index 6f30b3f,3fc60f7..a7087bf
--- a/src/main/org/apache/tools/ant/taskdefs/compilers/CompilerAdapterFactory.java
+++ b/src/main/org/apache/tools/ant/taskdefs/compilers/CompilerAdapterFactory.java
@@@ -96,60 -176,59 +176,49 @@@ public final class CompilerAdapterFacto
* @since Ant 1.8.0
*/
public static CompilerAdapter getCompiler(String compilerType, Task task,
- Path classpath)
- throws BuildException {
- if (compilerType.equalsIgnoreCase(COMPILER_JIKES)) {
- return new Jikes();
- }
- if (isForkedJavac(compilerType)) {
- return new JavacExternal();
- }
- 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 = COMPILER_MODERN;
- }
- if (compilerType.equalsIgnoreCase(COMPILER_MODERN)
- || isModernJdkCompiler(compilerType)) {
- // does the modern compiler exist?
- if (doesModernCompilerExist()) {
- return new Javac13();
- } 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()
- + "\"");
- }
+ 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();
}
+ throw new BuildException(
+ "Unable to find a javac compiler;\n%s is not on the classpath.\nPerhaps JAVA_HOME does not point to the JDK.\nIt is currently set to \"%s\"",
+ MODERN_COMPILER, JavaEnvUtils.getJavaHome());
+ }
- if ("jvc".equalsIgnoreCase(compilerType)
- || "microsoft".equalsIgnoreCase(compilerType)) {
- if (compilerType.equalsIgnoreCase(COMPILER_JVC)
- || compilerType.equalsIgnoreCase(COMPILER_JVC_ALIAS)) {
- return new Jvc();
- }
- if (compilerType.equalsIgnoreCase(COMPILER_KJC)) {
- return new Kjc();
- }
- if (compilerType.equalsIgnoreCase(COMPILER_GCJ)) {
- return new Gcj();
- }
- if (compilerType.equalsIgnoreCase(COMPILER_SYMANTEC_ALIAS)
- || compilerType.equalsIgnoreCase(COMPILER_SYMANTEC)) {
- return new Sj();
- }
- return resolveClassName(compilerType,
- // Memory-Leak in line below
- task.getProject().createClassLoader(classpath));
++ 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,
+ // Memory-Leak in line below
+ task.getProject().createClassLoader(classpath));
+ }
/**
* query for the Modern compiler existing
@@@ -191,4 -270,62 +260,57 @@@
CompilerAdapter.class);
}
+ /**
+ * Is the compiler implementation a forked jdk compiler?
+ *
+ * @param compilerImpl the name of the compiler implementation
- * @since 1.9.17
++ * @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.9.17
++ * @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.9.17
++ * @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.9.17
++ * @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.9.17
++ * @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) {
- for (String compiler : compilers) {
- if (compiler.equalsIgnoreCase(compilerName)) {
- return true;
- }
- }
- return false;
++ return compilerName != null && compilers.stream().anyMatch(compilerName::equalsIgnoreCase);
+ }
}
diff --cc src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
index b5227f5,9046e24..cf3ec45
--- a/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
+++ b/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
@@@ -624,22 -630,12 +624,24 @@@ public abstract class DefaultCompilerAd
* Shall we assume JDK 1.1 command line switches?
* @return true if jdk 1.1
* @since Ant 1.5
+ * @deprecated since Ant 1.10.7, use assumeJava1_1Plus, if necessary combined with !assumeJava1_2Plus
*/
+ @Deprecated
protected boolean assumeJava11() {
+ return assumeJava1_1Plus() && !assumeJava1_2Plus();
+ }
+
+ /**
+ * Shall we assume JDK 1.1+ command line switches?
+ * @return true if jdk 1.1 and above
+ * @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());
++ .equalsIgnoreCase(attributes.getCompilerVersion())
++ || assumeJava1_2Plus();
}
-
+
/**
* Shall we assume JDK 1.2 command line switches?
* @return true if jdk 1.2
@@@ -652,15 -647,6 +654,17 @@@
}
/**
+ * Shall we assume JDK 1.2+ command line switches?
+ * @return true if jdk 1.2 and above
+ * @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();
+ }
+
+ /**
* Shall we assume JDK 1.3 command line switches?
* @return true if jdk 1.3
* @since Ant 1.5
@@@ -672,52 -657,21 +676,56 @@@
}
/**
+ * Shall we assume JDK 1.3+ command line switches?
+ * @return true if jdk 1.3 and above
+ * @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();
+ }
+
+ /**
* Shall we assume JDK 1.4 command line switches?
* @return true if jdk 1.4
* @since Ant 1.6.3
+ * @deprecated since Ant 1.10.7, use assumeJava1_4Plus, if necessary combined with !assumeJava1_5Plus
*/
+ @Deprecated
protected boolean assumeJava14() {
- return assumeJavaXY(CompilerAdapterFactory.COMPILER_JAVAC_1_4, JavaEnvUtils.JAVA_1_4);
+ return assumeJava1_4Plus() && !assumeJava1_5Plus();
+ }
+
+ /**
+ * Shall we assume JDK 1.4+ command line switches?
+ * @return true if jdk 1.4 and above
+ * @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();
}
/**
* Shall we assume JDK 1.5 command line switches?
* @return true if JDK 1.5
* @since Ant 1.6.3
+ * @deprecated since Ant 1.10.7, use assumeJava1_5Plus, if necessary combined with !assumeJava1_6Plus
*/
+ @Deprecated
protected boolean assumeJava15() {
- return assumeJavaXY(CompilerAdapterFactory.COMPILER_JAVAC_1_5, JavaEnvUtils.JAVA_1_5);
+ return assumeJava1_5Plus() && !assumeJava1_6Plus();
+ }
+
+ /**
+ * Shall we assume JDK 1.5+ command line switches?
+ * @return true if jdk 1.5 and above
+ * @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();
}
/**
@@@ -732,32 -684,12 +740,34 @@@
}
/**
+ * Shall we assume JDK 1.6+ command line switches?
+ * @return true if jdk 1.6 and above
+ * @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() ;
+ }
+
+ /**
* Shall we assume JDK 1.7 command line switches?
* @return true if JDK 1.7
* @since Ant 1.8.2
+ * @deprecated since Ant 1.10.7, use assumeJava1_7Plus, if necessary combined with !assumeJava1_8Plus
*/
+ @Deprecated
protected boolean assumeJava17() {
- return assumeJavaXY(CompilerAdapterFactory.COMPILER_JAVAC_1_7, JavaEnvUtils.JAVA_1_7);
+ return assumeJava1_7Plus() && !assumeJava1_8Plus();
+ }
+
+ /**
+ * Shall we assume JDK 1.7+ command line switches?
+ * @return true if jdk 1.7 and above
+ * @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();
}
/**
@@@ -772,15 -702,6 +782,16 @@@
}
/**
+ * Shall we assume JDK 1.8+ command line switches?
+ * @return true if jdk 1.8 and above
+ * @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();
+ }
+
+ /**
* Shall we assume JDK 9 command line switches?
* @return true if JDK 9
* @since Ant 1.9.4
@@@ -805,38 -724,24 +816,34 @@@
/**
* Shall we assume JDK 9+ command line switches?
* @return true if JDK 9+
- * @since Ant 1.9.10
+ * @since Ant 1.10.2
*/
protected boolean assumeJava9Plus() {
- return assumeJavaXY("javac1.9", JavaEnvUtils.JAVA_9)
- || assumeJavaXY("javac9", JavaEnvUtils.JAVA_9)
- || assumeJava10Plus();
- 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)
- && CompilerAdapterFactory.isJdkCompilerNickname(attributes.getCompilerVersion()));
++ return assumeJavaXY(CompilerAdapterFactory.COMPILER_JAVAC_9, JavaEnvUtils.JAVA_9)
++ || assumeJavaXY(CompilerAdapterFactory.COMPILER_JAVAC_9_ALIAS, JavaEnvUtils.JAVA_9)
++ || assumeJava10Plus();
}
/**
+ * Shall we assume JDK 10+ command line switches?
+ * @return true if JDK 10+
+ * @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()));
+ }
+
+ /**
* Shall we assume command line switches for the given version of Java?
* @since Ant 1.8.3
*/
private boolean assumeJavaXY(final String javacXY, final String javaEnvVersionXY) {
- return javacXY.equalsIgnoreCase(attributes.getCompilerVersion())
- || (JavaEnvUtils.isJavaVersion(javaEnvVersionXY)
- && CompilerAdapterFactory.isJdkCompilerNickname(attributes.getCompilerVersion()));
+ 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()));
}
/**
diff --cc src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java
index 0aca5a1,1005c1d..a7a0875
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java
@@@ -75,10 -75,16 +75,15 @@@ public class JavacTest
project.setProperty("build.compiler", "extJavac");
javac.setFork(false);
assertNotNull("fork via property", javac.getJavacExecutable());
- assertContains("name should contain \"javac\"", "javac", 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());
+ assertNull("no fork and not extJavac means no executable", javac.getJavacExecutable());
String myJavac = "Slartibartfast";
javac.setFork(true);
diff --cc src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java
index c3f2ea1,92a488c..581d10a
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java
@@@ -458,89 -453,46 +458,115 @@@ public class DefaultCompilerAdapterTes
assertEquals("6", args[4]);
}
+ @Test
+ public void testAssumeJavaXPlus() {
+ LogCapturingJavac javac = new LogCapturingJavac();
+ Project p = new Project();
+ javac.setProject(p);
+ DefaultCompilerAdapter ca = new DefaultCompilerAdapter() {
+ @Override
+ public boolean execute() throws BuildException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+ };
+ ca.setJavac(javac);
+ System.out.println(javac.getCompiler());
+
+ 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());
+ assertTrue(ca.assumeJava1_8Plus());
+ } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_8)) {
+ assertFalse(ca.assumeJava9Plus());
+ assertTrue(ca.assumeJava1_8Plus());
+ assertTrue(ca.assumeJava1_7Plus());
+ }
+ javac.setCompiler("javac10+");
+ assertTrue(ca.assumeJava10Plus());
+ assertTrue(ca.assumeJava9Plus());
+
+ javac.setCompiler("javac9");
+ assertFalse(ca.assumeJava10Plus());
+ assertTrue(ca.assumeJava9Plus());
+ assertTrue(ca.assumeJava1_8Plus());
+
+ javac.setCompiler("javac1.9");
+ assertFalse(ca.assumeJava10Plus());
+ assertTrue(ca.assumeJava9Plus());
+ assertTrue(ca.assumeJava1_8Plus());
+
+ javac.setCompiler("javac1.8");
+ assertFalse(ca.assumeJava9Plus());
+ assertTrue(ca.assumeJava1_8Plus());
+ assertTrue(ca.assumeJava1_7Plus());
+
+ javac.setCompiler("javac1.7");
+ assertFalse(ca.assumeJava1_8Plus());
+ assertTrue(ca.assumeJava1_7Plus());
+ assertTrue(ca.assumeJava1_6Plus());
+
+ javac.setCompiler("javac1.6");
+ assertFalse(ca.assumeJava1_7Plus());
+ assertTrue(ca.assumeJava1_6Plus());
+ assertTrue(ca.assumeJava1_5Plus());
+
+ javac.setCompiler("javac1.5");
+ assertFalse(ca.assumeJava1_6Plus());
+ assertTrue(ca.assumeJava1_5Plus());
+ assertTrue(ca.assumeJava1_4Plus());
+
+ javac.setCompiler("javac1.4");
+ assertFalse(ca.assumeJava1_5Plus());
+ assertTrue(ca.assumeJava1_4Plus());
+ assertTrue(ca.assumeJava1_3Plus());
+
+ javac.setCompiler("javac1.3");
+ assertFalse(ca.assumeJava1_4Plus());
+ assertTrue(ca.assumeJava1_3Plus());
+ assertTrue(ca.assumeJava1_2Plus());
+
+ javac.setCompiler("javac1.2");
+ assertFalse(ca.assumeJava1_3Plus());
+ assertTrue(ca.assumeJava1_2Plus());
+ assertTrue(ca.assumeJava1_1Plus());
+
+ javac.setCompiler("javac1.1");
+ assertFalse(ca.assumeJava1_2Plus());
+ assertTrue(ca.assumeJava1_1Plus());
+ }
+
+
-
+ /**
+ * @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)) {
++ 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());
- assertTrue(ca.assumeJava9());
- assertTrue(ca.assumeJava19());
- assertFalse(ca.assumeJava18());
+ } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_8)) {
++ assertFalse(ca.assumeJava10Plus());
+ 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());
+ }
++ assertTrue(ca.assumeJava1_8Plus());
++ assertTrue(ca.assumeJava1_7Plus());
++ assertTrue(ca.assumeJava1_2Plus());
+ }
private void commonSourceDowngrades(String javaVersion) {
testSource("1.3", javaVersion,