From 02bbab8e6dd5971f92551e80d3af6546b1a745b8 Mon Sep 17 00:00:00 2001 From: LamGC Date: Sun, 22 Nov 2020 10:32:49 +0800 Subject: [PATCH] =?UTF-8?q?[Fix]=20Core=20=E4=BF=AE=E5=A4=8D=E5=9B=A0=20Pl?= =?UTF-8?q?uginClassLoader=20=E9=BB=98=E8=AE=A4=E7=B1=BB=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E7=AD=96=E7=95=A5=E9=94=99=E8=AF=AF=E5=AF=BC=E8=87=B4=E7=B1=BB?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E5=8A=A0=E8=BD=BD;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [Add] JarFrameworkLoader 添加一个调整了类加载策略的 Loader 构造器; [Fix] FrameworkManager 注册 JarFrameworkLoader 以解决类加载策略错误导致的类重复加载问题; --- .../cgj/bot/framework/FrameworkManager.java | 7 +++ .../cgj/bot/framework/JarFrameworkLoader.java | 43 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 ContentGrabbingJi-core/src/main/java/net/lamgc/cgj/bot/framework/JarFrameworkLoader.java diff --git a/ContentGrabbingJi-core/src/main/java/net/lamgc/cgj/bot/framework/FrameworkManager.java b/ContentGrabbingJi-core/src/main/java/net/lamgc/cgj/bot/framework/FrameworkManager.java index 553ff46..8175fe3 100644 --- a/ContentGrabbingJi-core/src/main/java/net/lamgc/cgj/bot/framework/FrameworkManager.java +++ b/ContentGrabbingJi-core/src/main/java/net/lamgc/cgj/bot/framework/FrameworkManager.java @@ -40,6 +40,13 @@ public class FrameworkManager extends JarPluginManager { setSystemVersion(systemVersion); } + @Override + protected PluginLoader createPluginLoader() { + return new CompoundPluginLoader() + .add(new DevelopmentPluginLoader(this), this::isDevelopment) + .add(new JarFrameworkLoader(this), this::isNotDevelopment); + } + @Override protected PluginDescriptorFinder createPluginDescriptorFinder() { return new JsonFrameworkDescriptorFinder(); diff --git a/ContentGrabbingJi-core/src/main/java/net/lamgc/cgj/bot/framework/JarFrameworkLoader.java b/ContentGrabbingJi-core/src/main/java/net/lamgc/cgj/bot/framework/JarFrameworkLoader.java new file mode 100644 index 0000000..733efaa --- /dev/null +++ b/ContentGrabbingJi-core/src/main/java/net/lamgc/cgj/bot/framework/JarFrameworkLoader.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2020 LamGC + * + * ContentGrabbingJi is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * ContentGrabbingJi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package net.lamgc.cgj.bot.framework; + +import org.pf4j.*; + +import java.nio.file.Path; + +/** + * + * @author LamGC + */ +public class JarFrameworkLoader extends JarPluginLoader { + + public JarFrameworkLoader(PluginManager pluginManager) { + super(pluginManager); + } + + @Override + public ClassLoader loadPlugin(Path pluginPath, PluginDescriptor pluginDescriptor) { + PluginClassLoader pluginClassLoader = + new PluginClassLoader(pluginManager, pluginDescriptor, + getClass().getClassLoader(), ClassLoadingStrategy.ADP); + pluginClassLoader.addFile(pluginPath.toFile()); + + return pluginClassLoader; + } +}