Skip to content

Commit

Permalink
chore: cleanup deprecated constructor for base plugin (#6243)
Browse files Browse the repository at this point in the history
#### 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 中已经过时的构造方法
```
  • Loading branch information
guqing authored Jul 3, 2024
1 parent 3dadd07 commit b964c7b
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 102 deletions.
31 changes: 1 addition & 30 deletions api/src/main/java/run/halo/app/plugin/BasePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

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
Expand All @@ -16,44 +14,17 @@
@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.
*/
public BasePlugin(PluginContext pluginContext) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public ApplicationContext create(String pluginId) {
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
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;
Expand Down Expand Up @@ -95,17 +94,6 @@ protected PluginDescriptorFinder createPluginDescriptorFinder() {
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();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ public void start() {
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);
Expand Down

This file was deleted.

0 comments on commit b964c7b

Please sign in to comment.