Skip to content

Commit

Permalink
Silent prompt when plugins fail to load in development mode (#2907)
Browse files Browse the repository at this point in the history
#### 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
插件开发模式下无法被加载时改为静默提示不抛出异常
```
  • Loading branch information
minliacom authored Dec 12, 2022
1 parent 86e5366 commit d060788
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
12 changes: 3 additions & 9 deletions src/main/java/run/halo/app/plugin/HaloPluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,9 @@ public void releaseAdditionalResources(String pluginId) {

@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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,6 +14,7 @@
* @author guqing
* @since 2.0.0
*/
@Slf4j
@Component
public class PluginDevelopmentInitializer implements ApplicationListener<ApplicationReadyEvent> {

Expand Down Expand Up @@ -43,7 +45,17 @@ private void createFixedPluginIfNecessary(HaloPluginManager pluginManager) {
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;
Expand All @@ -65,4 +77,4 @@ protected String idForPath(Path pluginPath) {
}
return null;
}
}
}

0 comments on commit d060788

Please sign in to comment.