From 7a577e49ee319a97461c6f88c0844262e91d7265 Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Wed, 28 Sep 2016 23:10:53 +0300 Subject: [PATCH] allow plugin script engines --- .../Jsr223IdeScriptEngineManagerImpl.java | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/platform/core-impl/src/org/jetbrains/ide/script/Jsr223IdeScriptEngineManagerImpl.java b/platform/core-impl/src/org/jetbrains/ide/script/Jsr223IdeScriptEngineManagerImpl.java index c4ed7782241a..e38a4f8e607a 100644 --- a/platform/core-impl/src/org/jetbrains/ide/script/Jsr223IdeScriptEngineManagerImpl.java +++ b/platform/core-impl/src/org/jetbrains/ide/script/Jsr223IdeScriptEngineManagerImpl.java @@ -36,9 +36,7 @@ import java.io.IOException; import java.io.Reader; import java.io.Writer; import java.net.URL; -import java.util.Enumeration; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.Callable; import java.util.concurrent.Future; @@ -50,7 +48,12 @@ class Jsr223IdeScriptEngineManagerImpl extends IdeScriptEngineManager { public ScriptEngineManager call() { long start = System.currentTimeMillis(); try { - return new ScriptEngineManager(); + return ClassLoaderUtil.runWithClassLoader(AllPluginsLoader.INSTANCE, new Computable() { + @Override + public ScriptEngineManager compute() { + return new ScriptEngineManager(); + } + }); } finally { long end = System.currentTimeMillis(); @@ -300,13 +303,38 @@ class Jsr223IdeScriptEngineManagerImpl extends IdeScriptEngineManager { throw new ClassNotFoundException(name); } + private static boolean isAllowedPluginResource(String name) { + // allow plugin engines but suppress all other resources + return "META-INF/services/javax.script.ScriptEngineFactory".equals(name); + } + @Override protected URL findResource(String name) { + if (isAllowedPluginResource(name)) { + for (IdeaPluginDescriptor descriptor : PluginManagerCore.getPlugins()) { + ClassLoader l = descriptor.getPluginClassLoader(); + URL url = l == null ? null : l.getResource(name); + if (url != null) return url; + } + } return getClass().getClassLoader().getResource(name); } @Override protected Enumeration findResources(String name) throws IOException { + if (isAllowedPluginResource(name)) { + Set result = null; + for (IdeaPluginDescriptor descriptor : PluginManagerCore.getPlugins()) { + ClassLoader l = descriptor.getPluginClassLoader(); + Enumeration urls = l == null ? null : l.getResources(name); + if (urls == null || !urls.hasMoreElements()) continue; + if (result == null) result = ContainerUtil.newLinkedHashSet(); + ContainerUtil.addAll(result, urls); + } + if (result != null) { + return Collections.enumeration(result); + } + } return getClass().getClassLoader().getResources(name); } }