mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-182825 Unable to compile groovy with JDK 9
use platform class loader as parent also when there's no groovy-all.jar
This commit is contained in:
@@ -18,6 +18,7 @@ package com.intellij.openapi.util;
|
||||
import com.intellij.util.ThrowableRunnable;
|
||||
import com.intellij.util.lang.UrlClassLoader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ClassLoaderUtil {
|
||||
private ClassLoaderUtil() {
|
||||
@@ -69,16 +70,22 @@ public class ClassLoaderUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void addPlatformLoaderParentIfOnJdk9(@NotNull UrlClassLoader.Builder builder) {
|
||||
@Nullable
|
||||
public static ClassLoader getPlatformLoaderParentIfOnJdk9() {
|
||||
if (SystemInfo.IS_AT_LEAST_JAVA9) {
|
||||
// on Java 8, 'tools.jar' is on a classpath; on Java 9, its classes are available via the platform loader
|
||||
try {
|
||||
ClassLoader platformCl = (ClassLoader)ClassLoader.class.getMethod("getPlatformClassLoader").invoke(null);
|
||||
builder.parent(platformCl);
|
||||
//noinspection JavaReflectionMemberAccess
|
||||
return (ClassLoader)ClassLoader.class.getMethod("getPlatformClassLoader").invoke(null);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void addPlatformLoaderParentIfOnJdk9(@NotNull UrlClassLoader.Builder builder) {
|
||||
builder.parent(getPlatformLoaderParentIfOnJdk9());
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -175,11 +175,11 @@ class InProcessGroovyc implements GroovycFlavor {
|
||||
private JointCompilationClassLoader createCompilationClassLoader(Collection<String> compilationClassPath) throws Exception {
|
||||
ClassLoader parent = obtainParentLoader(compilationClassPath);
|
||||
|
||||
ClassLoader groovyClassLoader = null;
|
||||
ClassLoader groovyClassLoader;
|
||||
try {
|
||||
ClassLoader auxiliary = parent != null ? parent : buildCompilationClassLoader(compilationClassPath, null).get();
|
||||
Class<?> gcl = auxiliary.loadClass("groovy.lang.GroovyClassLoader");
|
||||
groovyClassLoader = (ClassLoader)gcl.getConstructor(ClassLoader.class).newInstance(parent);
|
||||
groovyClassLoader = (ClassLoader)gcl.getConstructor(ClassLoader.class).newInstance(parent != null ? parent : ClassLoaderUtil.getPlatformLoaderParentIfOnJdk9());
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user