[Fix] Core 修复因 PluginClassLoader 默认类加载策略错误导致类重复加载;

[Add] JarFrameworkLoader 添加一个调整了类加载策略的 Loader 构造器;
[Fix] FrameworkManager 注册 JarFrameworkLoader 以解决类加载策略错误导致的类重复加载问题;
This commit is contained in:
LamGC 2020-11-22 10:32:49 +08:00
parent 3f353cbfa3
commit 02bbab8e6d
Signed by: LamGC
GPG Key ID: 6C5AE2A913941E1D
2 changed files with 50 additions and 0 deletions

View File

@ -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();

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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;
}
}