SLING-7365 for unsupported java version fall back to Java 9
also upgrade to the latest Eclipse Java Compiler (with the right GAV)
shipped with Oxygen .2
This closes #1
diff --git a/pom.xml b/pom.xml
index 6996c97..946895a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -88,10 +88,11 @@
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
+ <!-- the correct GAV is referenced in https://bugs.eclipse.org/bugs/show_bug.cgi?id=499019#c19 -->
<dependency>
- <groupId>org.eclipse.jdt.core.compiler</groupId>
+ <groupId>org.eclipse.jdt</groupId>
<artifactId>ecj</artifactId>
- <version>4.6.1</version>
+ <version>3.13.100</version> <!-- this is the version shipped in Oxygen .2 -->
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
diff --git a/src/main/java/org/apache/sling/commons/compiler/impl/EclipseJavaCompiler.java b/src/main/java/org/apache/sling/commons/compiler/impl/EclipseJavaCompiler.java
index 160bb6b..564b232 100644
--- a/src/main/java/org/apache/sling/commons/compiler/impl/EclipseJavaCompiler.java
+++ b/src/main/java/org/apache/sling/commons/compiler/impl/EclipseJavaCompiler.java
@@ -26,6 +26,8 @@
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
import org.apache.sling.commons.classloader.ClassLoaderWriter;
import org.apache.sling.commons.compiler.CompilationResult;
@@ -70,6 +72,8 @@
/** the static policy. */
private final IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.exitAfterAllProblems();
+
+ private final Set<String> warningEmittedForUnsupportedJavaVersion = new CopyOnWriteArraySet<>();
/**
* Get the classloader for the compilation.
@@ -233,9 +237,15 @@
}
private String adjustJavaVersion(String javaVersion) {
-
- // ECJ 4.6.1 expects Java version 1.9, not 9
- return "9".equals(javaVersion) ? "1.9" : javaVersion;
+ // use latest supported version (Java 9) in case the given java version is not supported by ECJ yet
+ if (CompilerOptions.versionToJdkLevel(javaVersion) == 0) {
+ // only log once per invalid javaVersion
+ if (!warningEmittedForUnsupportedJavaVersion.contains(javaVersion) && warningEmittedForUnsupportedJavaVersion.add(javaVersion)) {
+ logger.warn("Using unsupported java version '{}', assuming latest supported version '{}'", javaVersion, CompilerOptions.VERSION_9);
+ }
+ return CompilerOptions.VERSION_9;
+ }
+ return javaVersion;
}
//--------------------------------------------------------< inner classes >