refactor: check whether plugin has been loaded when startup (#2759)

#### What type of PR is this?
/kind improvement
/area core
/milestone 2.0.0-rc.1

#### What this PR does / why we need it:
插件以开发模式启动时加载插件需判断是否已经加载过

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

Fixes #2758

#### Special notes for your reviewer:
how to test it?
1. 配置 `halo.plugin.fixed-plugin-path`
2. 以开发模式启动后重启几次不会出现  #2758 中描述的异常

/cc @halo-dev/sig-halo 
#### Does this PR introduce a user-facing change?

```release-note
修复插件以开发模式启动时会出现插件已经加载过的异常
```
pull/2762/head^2
guqing 2022-11-24 21:37:06 +08:00 committed by GitHub
parent a76ade8aa8
commit 61c7459ccf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 0 deletions

View File

@ -39,6 +39,10 @@ public class PluginDevelopmentInitializer implements ApplicationListener<Applica
private void createFixedPluginIfNecessary(HaloPluginManager pluginManager) {
for (Path path : pluginProperties.getFixedPluginPath()) {
// already loaded
if (idForPath(path) != null) {
continue;
}
String pluginId = pluginManager.loadPlugin(path);
PluginWrapper pluginWrapper = pluginManager.getPlugin(pluginId);
if (pluginWrapper == null) {
@ -52,4 +56,13 @@ public class PluginDevelopmentInitializer implements ApplicationListener<Applica
}, () -> extensionClient.create(plugin));
}
}
protected String idForPath(Path pluginPath) {
for (PluginWrapper plugin : haloPluginManager.getPlugins()) {
if (plugin.getPluginPath().equals(pluginPath)) {
return plugin.getPluginId();
}
}
return null;
}
}