From 5c4fa522a3ff8c4abc5b14e74f012c0b0795eaf1 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 24 Nov 2024 01:13:58 -0500 Subject: [PATCH] Allow plugin classloader to define a parent classloader Required to support a change in the launcher that will allow us to bypass outdated bundled FX artifacts in JDK distros --- .../coley/recaf/services/plugin/PluginClassLoaderImpl.java | 3 ++- .../software/coley/recaf/services/plugin/PluginGraph.java | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/recaf-core/src/main/java/software/coley/recaf/services/plugin/PluginClassLoaderImpl.java b/recaf-core/src/main/java/software/coley/recaf/services/plugin/PluginClassLoaderImpl.java index 097f93cdc..c20d448d2 100644 --- a/recaf-core/src/main/java/software/coley/recaf/services/plugin/PluginClassLoaderImpl.java +++ b/recaf-core/src/main/java/software/coley/recaf/services/plugin/PluginClassLoaderImpl.java @@ -18,7 +18,8 @@ final class PluginClassLoaderImpl extends ClassLoader implements PluginClassLoad private final PluginSource source; private final String id; - PluginClassLoaderImpl(@Nonnull PluginGraph graph, @Nonnull PluginSource source, @Nonnull String id) { + PluginClassLoaderImpl(@Nonnull ClassLoader classLoader, @Nonnull PluginGraph graph, @Nonnull PluginSource source, @Nonnull String id) { + super(classLoader); this.graph = graph; this.source = source; this.id = id; diff --git a/recaf-core/src/main/java/software/coley/recaf/services/plugin/PluginGraph.java b/recaf-core/src/main/java/software/coley/recaf/services/plugin/PluginGraph.java index 58ec7fa84..ca743cf76 100644 --- a/recaf-core/src/main/java/software/coley/recaf/services/plugin/PluginGraph.java +++ b/recaf-core/src/main/java/software/coley/recaf/services/plugin/PluginGraph.java @@ -46,7 +46,9 @@ Collection> apply(@Nonnull List preparedPlugi if (plugins.containsKey(id)) { throw new PluginException("Plugin %s is already loaded".formatted(id)); } - var classLoader = new PluginClassLoaderImpl(this, preparedPlugin.pluginSource(), id); + var threadContextClassLoader = Thread.currentThread().getContextClassLoader(); + var parentLoader = threadContextClassLoader != null ? threadContextClassLoader : ClassLoader.getSystemClassLoader(); + var classLoader = new PluginClassLoaderImpl(parentLoader, this, preparedPlugin.pluginSource(), id); LoadedPlugin loadedPlugin = new LoadedPlugin(new PluginContainerImpl<>(preparedPlugin, classLoader)); if (temp.putIfAbsent(id, loadedPlugin) != null) {