mirror of https://github.com/halo-dev/halo
refactor: remove get root application context method from halo plugin manager (#2949)
#### What type of PR is this? /kind improvement /area core #### What this PR does / why we need it: HaloPluginManager 移除 getRootApplicationContext 方法 #### Which issue(s) this PR fixes: Fixes #2943 #### Special notes for your reviewer: /cc @halo-dev/sig-halo #### Does this PR introduce a user-facing change? ```release-note HaloPluginManager 移除 getRootApplicationContext 方法 ```pull/2955/head
parent
843dcc0e4a
commit
d5eb7b71cf
|
@ -2,6 +2,7 @@ package run.halo.app.plugin;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.pf4j.Plugin;
|
import org.pf4j.Plugin;
|
||||||
|
import org.pf4j.PluginManager;
|
||||||
import org.pf4j.PluginWrapper;
|
import org.pf4j.PluginWrapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,7 +19,7 @@ public class BasePlugin extends Plugin {
|
||||||
super(wrapper);
|
super(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
private HaloPluginManager getPluginManager() {
|
private PluginManager getPluginManager() {
|
||||||
return (HaloPluginManager) getWrapper().getPluginManager();
|
return getWrapper().getPluginManager();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,17 +68,13 @@ public class HaloPluginManager extends DefaultPluginManager
|
||||||
return new SpringComponentsFinder(this);
|
return new SpringComponentsFinder(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApplicationContext getRootApplicationContext() {
|
|
||||||
return this.rootApplicationContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setApplicationContext(@NonNull ApplicationContext rootApplicationContext)
|
public final void setApplicationContext(@NonNull ApplicationContext rootApplicationContext)
|
||||||
throws BeansException {
|
throws BeansException {
|
||||||
this.rootApplicationContext = rootApplicationContext;
|
this.rootApplicationContext = rootApplicationContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginApplicationContext getPluginApplicationContext(String pluginId) {
|
final PluginApplicationContext getPluginApplicationContext(String pluginId) {
|
||||||
return pluginApplicationInitializer.getPluginApplicationContext(pluginId);
|
return pluginApplicationInitializer.getPluginApplicationContext(pluginId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,8 +84,9 @@ public class HaloPluginManager extends DefaultPluginManager
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() {
|
public final void afterPropertiesSet() {
|
||||||
this.pluginApplicationInitializer = new PluginApplicationInitializer(this);
|
this.pluginApplicationInitializer =
|
||||||
|
new PluginApplicationInitializer(this, rootApplicationContext);
|
||||||
|
|
||||||
this.requestMappingManager =
|
this.requestMappingManager =
|
||||||
rootApplicationContext.getBean(PluginRequestMappingManager.class);
|
rootApplicationContext.getBean(PluginRequestMappingManager.class);
|
||||||
|
|
|
@ -26,17 +26,18 @@ public class PluginApplicationInitializer {
|
||||||
|
|
||||||
private final ExtensionContextRegistry contextRegistry = ExtensionContextRegistry.getInstance();
|
private final ExtensionContextRegistry contextRegistry = ExtensionContextRegistry.getInstance();
|
||||||
private final SharedApplicationContextHolder sharedApplicationContextHolder;
|
private final SharedApplicationContextHolder sharedApplicationContextHolder;
|
||||||
|
private final ApplicationContext rootApplicationContext;
|
||||||
|
|
||||||
public PluginApplicationInitializer(HaloPluginManager springPluginManager) {
|
public PluginApplicationInitializer(HaloPluginManager haloPluginManager,
|
||||||
this.haloPluginManager = springPluginManager;
|
ApplicationContext rootApplicationContext) {
|
||||||
sharedApplicationContextHolder = springPluginManager.getRootApplicationContext()
|
Assert.notNull(haloPluginManager, "The haloPluginManager must not be null");
|
||||||
|
Assert.notNull(rootApplicationContext, "The rootApplicationContext must not be null");
|
||||||
|
this.haloPluginManager = haloPluginManager;
|
||||||
|
this.rootApplicationContext = rootApplicationContext;
|
||||||
|
sharedApplicationContextHolder = rootApplicationContext
|
||||||
.getBean(SharedApplicationContextHolder.class);
|
.getBean(SharedApplicationContextHolder.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApplicationContext getRootApplicationContext() {
|
|
||||||
return this.haloPluginManager.getRootApplicationContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
private PluginApplicationContext createPluginApplicationContext(String pluginId) {
|
private PluginApplicationContext createPluginApplicationContext(String pluginId) {
|
||||||
PluginWrapper plugin = haloPluginManager.getPlugin(pluginId);
|
PluginWrapper plugin = haloPluginManager.getPlugin(pluginId);
|
||||||
ClassLoader pluginClassLoader = plugin.getPluginClassLoader();
|
ClassLoader pluginClassLoader = plugin.getPluginClassLoader();
|
||||||
|
@ -111,7 +112,7 @@ public class PluginApplicationInitializer {
|
||||||
private void populateSettingFetcher(String pluginName,
|
private void populateSettingFetcher(String pluginName,
|
||||||
DefaultListableBeanFactory listableBeanFactory) {
|
DefaultListableBeanFactory listableBeanFactory) {
|
||||||
ExtensionClient extensionClient =
|
ExtensionClient extensionClient =
|
||||||
getRootApplicationContext().getBean(ExtensionClient.class);
|
rootApplicationContext.getBean(ExtensionClient.class);
|
||||||
SettingFetcher settingFetcher = new SettingFetcher(pluginName, extensionClient);
|
SettingFetcher settingFetcher = new SettingFetcher(pluginName, extensionClient);
|
||||||
listableBeanFactory.registerSingleton("settingFetcher", settingFetcher);
|
listableBeanFactory.registerSingleton("settingFetcher", settingFetcher);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue