Silent prompt when plugins fail to load in development mode (#2907)

#### What type of PR is this?
/kind improvement
/area core

#### What this PR does / why we need it:
在插件开发模式下加载插件失败时不抛出异常改为静默提示

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

A part of #2901

#### Special notes for your reviewer:
how to test it?
1. 配置 `halo.plugin.fixed-plugin-path` 为一些不合法的插件项目路径不影响 Halo 正常启动,且有错误提示
2. 配置合法路径,插件能正确启动

#### Does this PR introduce a user-facing change?

```release-note
插件开发模式下无法被加载时改为静默提示不抛出异常
```
pull/2918/head
will 2022-12-12 10:24:22 +08:00 committed by GitHub
parent 86e5366797
commit d06078893e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 11 deletions

View File

@ -381,15 +381,9 @@ public class HaloPluginManager extends DefaultPluginManager
@Override
protected PluginWrapper loadPluginFromPath(Path pluginPath) {
try {
PluginWrapper pluginWrapper = super.loadPluginFromPath(pluginPath);
rootApplicationContext.publishEvent(new HaloPluginLoadedEvent(this, pluginWrapper));
return pluginWrapper;
} catch (PluginRuntimeException e) {
// ignore this
log.warn(e.getMessage(), e);
}
return null;
PluginWrapper pluginWrapper = super.loadPluginFromPath(pluginPath);
rootApplicationContext.publishEvent(new HaloPluginLoadedEvent(this, pluginWrapper));
return pluginWrapper;
}
private void removePluginComponentsCache(String pluginId) {

View File

@ -1,6 +1,7 @@
package run.halo.app.plugin;
import java.nio.file.Path;
import lombok.extern.slf4j.Slf4j;
import org.pf4j.PluginWrapper;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
@ -13,6 +14,7 @@ import run.halo.app.extension.ExtensionClient;
* @author guqing
* @since 2.0.0
*/
@Slf4j
@Component
public class PluginDevelopmentInitializer implements ApplicationListener<ApplicationReadyEvent> {
@ -43,7 +45,17 @@ public class PluginDevelopmentInitializer implements ApplicationListener<Applica
if (idForPath(path) != null) {
continue;
}
String pluginId = pluginManager.loadPlugin(path);
// for issue #2901
String pluginId;
try {
pluginId = pluginManager.loadPlugin(path);
} catch (Exception e) {
log.warn(e.getMessage(), e);
continue;
}
PluginWrapper pluginWrapper = pluginManager.getPlugin(pluginId);
if (pluginWrapper == null) {
continue;
@ -65,4 +77,4 @@ public class PluginDevelopmentInitializer implements ApplicationListener<Applica
}
return null;
}
}
}