diff --git a/api/src/main/java/run/halo/app/plugin/BasePlugin.java b/api/src/main/java/run/halo/app/plugin/BasePlugin.java index d010998c56..18765375fb 100644 --- a/api/src/main/java/run/halo/app/plugin/BasePlugin.java +++ b/api/src/main/java/run/halo/app/plugin/BasePlugin.java @@ -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 @@ -16,17 +14,10 @@ @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 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; diff --git a/application/src/main/java/run/halo/app/plugin/DefaultPluginApplicationContextFactory.java b/application/src/main/java/run/halo/app/plugin/DefaultPluginApplicationContextFactory.java index 0d29e3290d..95563b325b 100644 --- a/application/src/main/java/run/halo/app/plugin/DefaultPluginApplicationContextFactory.java +++ b/application/src/main/java/run/halo/app/plugin/DefaultPluginApplicationContextFactory.java @@ -85,7 +85,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()); diff --git a/application/src/main/java/run/halo/app/plugin/HaloPluginManager.java b/application/src/main/java/run/halo/app/plugin/HaloPluginManager.java index 76b44f870e..1dafb4b455 100644 --- a/application/src/main/java/run/halo/app/plugin/HaloPluginManager.java +++ b/application/src/main/java/run/halo/app/plugin/HaloPluginManager.java @@ -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; @@ -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(); diff --git a/application/src/main/java/run/halo/app/plugin/HaloPluginWrapper.java b/application/src/main/java/run/halo/app/plugin/HaloPluginWrapper.java deleted file mode 100644 index f784400ab4..0000000000 --- a/application/src/main/java/run/halo/app/plugin/HaloPluginWrapper.java +++ /dev/null @@ -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; - } -} diff --git a/application/src/main/java/run/halo/app/plugin/SpringPlugin.java b/application/src/main/java/run/halo/app/plugin/SpringPlugin.java index 0eaaba3615..0acc144782 100644 --- a/application/src/main/java/run/halo/app/plugin/SpringPlugin.java +++ b/application/src/main/java/run/halo/app/plugin/SpringPlugin.java @@ -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); diff --git a/application/src/main/java/run/halo/app/plugin/event/HaloPluginLoadedEvent.java b/application/src/main/java/run/halo/app/plugin/event/HaloPluginLoadedEvent.java deleted file mode 100644 index 23861984d9..0000000000 --- a/application/src/main/java/run/halo/app/plugin/event/HaloPluginLoadedEvent.java +++ /dev/null @@ -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; - } -}