[#2697] Use ECJ compiler on JRE's without compiler for Alias.*

This commit is contained in:
Jan-Willem Gmelig Meyling 2020-12-28 13:46:38 +01:00 committed by Jan-Willem Gmelig Meyling
parent 9eeb13f329
commit 15da5c069f

View File

@ -21,6 +21,7 @@ import java.util.Map;
import javax.annotation.Nullable;
import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
import com.google.common.primitives.Primitives;
import com.mysema.codegen.ECJEvaluatorFactory;
@ -52,7 +53,7 @@ public class DefaultEvaluatorFactory {
public DefaultEvaluatorFactory(CollQueryTemplates templates) {
this(templates,
Thread.currentThread().getContextClassLoader());
Thread.currentThread().getContextClassLoader() != null ? Thread.currentThread().getContextClassLoader() : DefaultEvaluatorFactory.class.getClassLoader());
}
public DefaultEvaluatorFactory(CollQueryTemplates templates, EvaluatorFactory factory) {
@ -68,10 +69,11 @@ public class DefaultEvaluatorFactory {
protected DefaultEvaluatorFactory(CollQueryTemplates templates, ClassLoader classLoader) {
this.templates = templates;
if (classLoader instanceof URLClassLoader) {
this.factory = new JDKEvaluatorFactory((URLClassLoader) classLoader);
final JavaCompiler systemJavaCompiler = ToolProvider.getSystemJavaCompiler();
if (classLoader instanceof URLClassLoader && systemJavaCompiler != null) {
this.factory = new JDKEvaluatorFactory((URLClassLoader) classLoader, systemJavaCompiler);
} else {
// for OSGi compatibility
// for OSGi and JRE compatibility
this.factory = new ECJEvaluatorFactory(classLoader);
}
}