Skip to content

Commit

Permalink
refactor: plugin resource loading to only load from plugin itself ins…
Browse files Browse the repository at this point in the history
…tead of delegating to core (#4663)

#### What type of PR is this?
/kind improvement
/area core
/area plugin
/milestone 2.10.x

#### What this PR does / why we need it:
重构插件类加载器以优化当插件的 resources 目录资源与 Halo 中同名时加载不到的问题

how to test it?
1. 在创建的 resources/extensions 目录创建一个与 halo 的 resources/extensions 目录中已存在的同名 yaml
2. 使用插件观察插件的同名文件 yaml 是否被 apply 到 halo 中
3. 测试插件的其他功能是否正常比如静态资源加载如 logo 等

#### Which issue(s) this PR fixes:
Fixes #4610

#### Does this PR introduce a user-facing change?
```release-note
重构插件类加载器以优化当插件的 resources 目录资源与 Halo 中同名时加载不到的问题
```
  • Loading branch information
guqing authored Sep 27, 2023
1 parent e119b63 commit 86db26a
Showing 1 changed file with 1 addition and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
import java.time.Instant;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.pf4j.ClassLoadingStrategy;
import org.pf4j.CompoundPluginLoader;
import org.pf4j.CompoundPluginRepository;
import org.pf4j.DefaultPluginRepository;
import org.pf4j.DevelopmentPluginLoader;
import org.pf4j.JarPluginLoader;
import org.pf4j.JarPluginRepository;
import org.pf4j.PluginClassLoader;
import org.pf4j.PluginDescriptor;
import org.pf4j.PluginLoader;
import org.pf4j.PluginManager;
Expand Down Expand Up @@ -111,17 +109,7 @@ protected PluginLoader createPluginLoader() {
} else {
return new CompoundPluginLoader()
.add(createDevelopmentPluginLoader(this), this::isDevelopment)
.add(new JarPluginLoader(this) {
@Override
public ClassLoader loadPlugin(Path pluginPath,
PluginDescriptor pluginDescriptor) {
PluginClassLoader pluginClassLoader =
new PluginClassLoader(pluginManager, pluginDescriptor,
getClass().getClassLoader(), ClassLoadingStrategy.APD);
pluginClassLoader.addFile(pluginPath.toFile());
return pluginClassLoader;
}
});
.add(new JarPluginLoader(this));
}
}

Expand Down Expand Up @@ -156,12 +144,6 @@ protected PluginRepository createPluginRepository() {

DevelopmentPluginLoader createDevelopmentPluginLoader(PluginManager pluginManager) {
return new DevelopmentPluginLoader(pluginManager) {
@Override
protected PluginClassLoader createPluginClassLoader(Path pluginPath,
PluginDescriptor pluginDescriptor) {
return new PluginClassLoader(pluginManager, pluginDescriptor,
getClass().getClassLoader(), ClassLoadingStrategy.APD);
}

@Override
public ClassLoader loadPlugin(Path pluginPath,
Expand Down

0 comments on commit 86db26a

Please sign in to comment.