chore: cleanup deprecated constructor for base plugin (#6243)

#### What type of PR is this?
/kind cleanup
/area plugin
/milestone 2.17.x

#### What this PR does / why we need it:
移除 BasePlugin 中已经过时的构造方法

在 2.6.1 版本中将 `BasePlugin(PluginWrapper wrapper)` 标记为过时并使用 `BasePlugin(PluginContext pluginContext)` 代替,现在已经过了很多版本,是时候移除它了。

see also #4023
#### Does this PR introduce a user-facing change?
```release-note
开发者相关:移除 BasePlugin 中已经过时的构造方法
```
pull/6259/head
guqing 2024-07-03 11:49:34 +08:00 committed by GitHub
parent 3dadd07986
commit b964c7bb00
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 1 additions and 102 deletions

View File

@ -2,9 +2,7 @@ package run.halo.app.plugin;
import lombok.extern.slf4j.Slf4j;
import org.pf4j.Plugin;
import org.pf4j.PluginWrapper;
import org.springframework.lang.NonNull;
import org.springframework.util.Assert;
/**
* This class will be extended by all plugins and serve as the common class between a plugin and
@ -16,17 +14,10 @@ import org.springframework.util.Assert;
@Slf4j
public class BasePlugin extends Plugin {
protected PluginContext context;
@Deprecated
public BasePlugin(PluginWrapper wrapper) {
super(wrapper);
log.info("Initialized plugin {}", wrapper.getPluginId());
}
protected final PluginContext context;
/**
* Constructor a plugin with the given plugin context.
* TODO Mark {@link PluginContext} as final to prevent modification.
*
* @param pluginContext plugin context must not be null.
*/
@ -34,26 +25,6 @@ public class BasePlugin extends Plugin {
this.context = pluginContext;
}
/**
* use {@link #BasePlugin(PluginContext)} instead of.
*
* @deprecated since 2.10.0
*/
public BasePlugin() {
}
/**
* Compatible with old constructors, if the plugin is not use
* {@link #BasePlugin(PluginContext)} constructor then base plugin factory will use this
* method to set plugin context.
*
* @param context plugin context must not be null.
*/
final void setContext(PluginContext context) {
Assert.notNull(context, "Plugin context must not be null");
this.context = context;
}
@NonNull
public PluginContext getContext() {
return context;

View File

@ -86,7 +86,6 @@ public class DefaultPluginApplicationContextFactory implements PluginApplication
sw.start("RegisterBeans");
var beanFactory = context.getBeanFactory();
context.registerBean(AggregatedRouterFunction.class);
beanFactory.registerSingleton("pluginWrapper", pluginWrapper);
if (pluginWrapper.getPlugin() instanceof SpringPlugin springPlugin) {
beanFactory.registerSingleton("pluginContext", springPlugin.getPluginContext());

View File

@ -15,7 +15,6 @@ import org.pf4j.ExtensionFactory;
import org.pf4j.ExtensionFinder;
import org.pf4j.JarPluginLoader;
import org.pf4j.JarPluginRepository;
import org.pf4j.PluginDescriptor;
import org.pf4j.PluginDescriptorFinder;
import org.pf4j.PluginFactory;
import org.pf4j.PluginLoader;
@ -95,17 +94,6 @@ public class HaloPluginManager extends DefaultPluginManager implements SpringPlu
return new YamlPluginDescriptorFinder();
}
@Override
protected PluginWrapper createPluginWrapper(PluginDescriptor pluginDescriptor, Path pluginPath,
ClassLoader pluginClassLoader) {
// create the plugin wrapper
log.debug("Creating wrapper for plugin '{}'", pluginPath);
var pluginWrapper =
new HaloPluginWrapper(this, pluginDescriptor, pluginPath, pluginClassLoader);
pluginWrapper.setPluginFactory(getPluginFactory());
return pluginWrapper;
}
@Override
protected PluginLoader createPluginLoader() {
var compoundLoader = new CompoundPluginLoader();

View File

@ -1,34 +0,0 @@
package run.halo.app.plugin;
import java.nio.file.Files;
import java.nio.file.Path;
import org.pf4j.PluginDescriptor;
import org.pf4j.PluginManager;
import org.pf4j.PluginWrapper;
import org.pf4j.RuntimeMode;
/**
* A wrapper over plugin instance for Halo.
*
* @author guqing
* @since 2.10.0
*/
public class HaloPluginWrapper extends PluginWrapper {
private final RuntimeMode runtimeMode;
/**
* Creates a new plugin wrapper to manage the specified plugin.
*/
public HaloPluginWrapper(PluginManager pluginManager, PluginDescriptor descriptor,
Path pluginPath, ClassLoader pluginClassLoader) {
super(pluginManager, descriptor, pluginPath, pluginClassLoader);
this.runtimeMode = Files.isDirectory(pluginPath)
? RuntimeMode.DEVELOPMENT : RuntimeMode.DEPLOYMENT;
}
@Override
public RuntimeMode getRuntimeMode() {
return runtimeMode;
}
}

View File

@ -40,9 +40,6 @@ public class SpringPlugin extends Plugin {
log.info("After publishing plugin starting event for plugin {}", pluginId);
if (pluginOpt.isPresent()) {
this.delegate = pluginOpt.get();
if (this.delegate instanceof BasePlugin basePlugin) {
basePlugin.setContext(pluginContext);
}
log.info("Starting {} for plugin {}", this.delegate, pluginId);
this.delegate.start();
log.info("Started {} for plugin {}", this.delegate, pluginId);

View File

@ -1,22 +0,0 @@
package run.halo.app.plugin.event;
import org.pf4j.PluginWrapper;
import org.springframework.context.ApplicationEvent;
/**
* @author guqing
* @since 2.0.0
*/
public class HaloPluginLoadedEvent extends ApplicationEvent {
private final PluginWrapper pluginWrapper;
public HaloPluginLoadedEvent(Object source, PluginWrapper pluginWrapper) {
super(source);
this.pluginWrapper = pluginWrapper;
}
public PluginWrapper getPluginWrapper() {
return pluginWrapper;
}
}