mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
groovy compile under jdk 9
This commit is contained in:
@@ -19,6 +19,7 @@ import com.intellij.ide.startup.StartupActionScriptManager;
|
||||
import com.intellij.idea.Main;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.ClassLoaderUtil;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.lang.UrlClassLoader;
|
||||
@@ -68,16 +69,7 @@ public class BootstrapClassLoaderUtil extends ClassUtilCore {
|
||||
builder.allowBootstrapResources();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
catch (Exception e) {
|
||||
getLogger().warn(e);
|
||||
}
|
||||
}
|
||||
ClassLoaderUtil.addPlatformLoaderParentIfOnJdk9(builder);
|
||||
|
||||
UrlClassLoader newClassLoader = builder.get();
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
package com.intellij.openapi.util;
|
||||
|
||||
import com.intellij.util.ThrowableRunnable;
|
||||
import com.intellij.util.lang.UrlClassLoader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ClassLoaderUtil {
|
||||
private ClassLoaderUtil() {
|
||||
@@ -66,4 +68,17 @@ public class ClassLoaderUtil {
|
||||
Thread.currentThread().setContextClassLoader(oldClassLoader);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addPlatformLoaderParentIfOnJdk9(@NotNull UrlClassLoader.Builder builder) {
|
||||
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);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -40,9 +40,9 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public abstract class GroovyConfigUtils extends AbstractConfigUtils {
|
||||
|
||||
@NonNls public static final Pattern GROOVY_ALL_JAR_PATTERN = Pattern.compile("groovy-all(-minimal)?(-(\\d+(\\.\\d+)*))?(-indy)?\\.jar");
|
||||
@NonNls public static final Pattern GROOVY_ALL_JAR_PATTERN = Pattern.compile("groovy-all(-minimal)?(-(\\d+(\\.\\d+)*))?(-indy|-alpha.*)?\\.jar");
|
||||
public static final int VERSION_GROUP_NUMBER = 3; // version will be in third group in GROOVY_ALL_JAR_PATTERN
|
||||
@NonNls public static final Pattern GROOVY_JAR_PATTERN = Pattern.compile("groovy(-(\\d+(\\.\\d+)*))?(-indy)?\\.jar");
|
||||
@NonNls public static final Pattern GROOVY_JAR_PATTERN = Pattern.compile("groovy(-(\\d+(\\.\\d+)*))?(-indy|-alpha.*)?\\.jar");
|
||||
|
||||
public static final String NO_VERSION = "<no version>";
|
||||
public static final String GROOVY1_7 = "1.7";
|
||||
|
||||
+23
-13
@@ -17,9 +17,10 @@ package org.jetbrains.jps.incremental.groovy;
|
||||
|
||||
import com.intellij.execution.process.ProcessOutputTypes;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.ClassLoaderUtil;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.reference.SoftReference;
|
||||
@@ -42,7 +43,10 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
@@ -52,6 +56,7 @@ class InProcessGroovyc implements GroovycFlavor {
|
||||
private static final Logger LOG = Logger.getInstance("#org.jetbrains.jps.incremental.groovy.InProcessGroovyc");
|
||||
private static final Pattern GROOVY_ALL_JAR_PATTERN = Pattern.compile("groovy-all(-(.*))?\\.jar");
|
||||
private static final Pattern GROOVY_JAR_PATTERN = Pattern.compile("groovy(-(.*))?\\.jar");
|
||||
private static final Pattern GROOVY_ECLIPSE_BATCH_PATTERN = Pattern.compile("groovy-eclipse-batch-(.*)\\.jar");
|
||||
private static final ThreadPoolExecutor ourExecutor = ConcurrencyUtil.newSingleThreadExecutor("Groovyc");
|
||||
private static SoftReference<Pair<String, ClassLoader>> ourParentLoaderCache;
|
||||
private static final UrlClassLoader.CachePool ourLoaderCachePool = UrlClassLoader.createCachePool();
|
||||
@@ -209,7 +214,7 @@ class InProcessGroovyc implements GroovycFlavor {
|
||||
|
||||
@Nullable
|
||||
private static ClassLoader obtainParentLoader(Collection<String> compilationClassPath) throws MalformedURLException {
|
||||
if (!"true".equals(System.getProperty("groovyc.reuse.compiler.classes", "true"))) {
|
||||
if (!SystemInfo.IS_AT_LEAST_JAVA9 && !"true".equals(System.getProperty("groovyc.reuse.compiler.classes", "true"))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -217,10 +222,11 @@ class InProcessGroovyc implements GroovycFlavor {
|
||||
String fileName = StringUtil.getShortName(s, '/');
|
||||
return GROOVY_ALL_JAR_PATTERN.matcher(fileName).matches() || GROOVY_JAR_PATTERN.matcher(fileName).matches();
|
||||
});
|
||||
ContainerUtil.retainAll(groovyJars, s -> !GROOVY_ECLIPSE_BATCH_PATTERN.matcher(StringUtil.getShortName(s, '/')).matches());
|
||||
|
||||
LOG.debug("Groovy jars: " + groovyJars);
|
||||
|
||||
if (groovyJars.size() != 1 || !GROOVY_ALL_JAR_PATTERN.matcher(groovyJars.get(0)).matches()) {
|
||||
if (groovyJars.size() != 1 || !GROOVY_ALL_JAR_PATTERN.matcher(StringUtil.getShortName(groovyJars.get(0), '/')).matches()) {
|
||||
// avoid complications caused by caching classes from several groovy versions in classpath
|
||||
return null;
|
||||
}
|
||||
@@ -261,15 +267,19 @@ class InProcessGroovyc implements GroovycFlavor {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
UrlClassLoader groovyAllLoader = UrlClassLoader.build().
|
||||
urls(toUrls(ContainerUtil.concat(GroovyBuilder.getGroovyRtRoots(), Collections.singletonList(groovyAll)))).allowLock().
|
||||
useCache(ourLoaderCachePool, new UrlClassLoader.CachingCondition() {
|
||||
@Override
|
||||
public boolean shouldCacheData(
|
||||
@NotNull URL url) {
|
||||
return true;
|
||||
}
|
||||
}).get();
|
||||
UrlClassLoader.Builder builder = UrlClassLoader.build();
|
||||
builder.urls(toUrls(ContainerUtil.concat(GroovyBuilder.getGroovyRtRoots(), Collections.singletonList(groovyAll))));
|
||||
builder.allowLock();
|
||||
builder.useCache(ourLoaderCachePool, new UrlClassLoader.CachingCondition() {
|
||||
@Override
|
||||
public boolean shouldCacheData(
|
||||
@NotNull URL url) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
ClassLoaderUtil.addPlatformLoaderParentIfOnJdk9(builder);
|
||||
UrlClassLoader groovyAllLoader = builder.get();
|
||||
|
||||
ClassLoader wrapper = new URLClassLoader(new URL[0], groovyAllLoader) {
|
||||
@Override
|
||||
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ class JointCompilationClassLoader extends UrlClassLoader {
|
||||
@NotNull private final Builder myBuilder;
|
||||
@NotNull private ClassPath myClassPath;
|
||||
|
||||
public JointCompilationClassLoader(@NotNull Builder builder) {
|
||||
JointCompilationClassLoader(@NotNull Builder builder) {
|
||||
super(builder);
|
||||
myBuilder = builder;
|
||||
myClassPath = super.getClassPath();
|
||||
|
||||
@@ -72,7 +72,7 @@ public class GroovyFacetUtil {
|
||||
|
||||
public static File getBundledGroovyJar() {
|
||||
final File[] groovyJars = LibrariesUtil.getFilesInDirectoryByPattern(getLibDirectory(), GroovyConfigUtils.GROOVY_ALL_JAR_PATTERN);
|
||||
assert groovyJars.length == 1;
|
||||
assert groovyJars.length == 1 : groovyJars;
|
||||
return groovyJars[0];
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.OrderEnumerator;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.util.ClassLoaderUtil;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
@@ -132,7 +133,7 @@ public class AntTasksProvider {
|
||||
private final Future<Map<String, Class>> myFuture;
|
||||
|
||||
public AntClassLoader(ArrayList<URL> urls) {
|
||||
super(build().urls(urls).allowUnescaped().noPreload());
|
||||
super(getBuilder(urls));
|
||||
myFuture = ApplicationManager.getApplication().executeOnPooledThread(() -> {
|
||||
try {
|
||||
final ReflectedProject antProject = ReflectedProject.getProject(this);
|
||||
@@ -156,6 +157,15 @@ public class AntTasksProvider {
|
||||
});
|
||||
}
|
||||
|
||||
private static Builder getBuilder(ArrayList<URL> urls) {
|
||||
Builder builder = build()
|
||||
.urls(urls)
|
||||
.allowUnescaped()
|
||||
.noPreload();
|
||||
ClassLoaderUtil.addPlatformLoaderParentIfOnJdk9(builder);
|
||||
return builder;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Map<String, Class> getAntObjects() {
|
||||
while (true) {
|
||||
|
||||
Reference in New Issue
Block a user