From 35ab60246d6bf79227330e68f22a77f6b1870b31 Mon Sep 17 00:00:00 2001 From: guqing <38999863+guqing@users.noreply.github.com> Date: Thu, 4 Jul 2024 11:20:31 +0800 Subject: [PATCH] chore: replace plugin wrapper with plugin context (#136) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### What this PR does? 替换插件中对于 PluginWrapper 的引用,这是已经过时的引用,这将在后续被移除 ```release-note None ``` --- .../widget/CommentWidgetHeadProcessor.java | 19 +++++++++---------- .../comment/widget/CommentWidgetPlugin.java | 14 +++----------- .../comment/widget/DefaultCommentWidget.java | 7 +++---- 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/main/java/run/halo/comment/widget/CommentWidgetHeadProcessor.java b/src/main/java/run/halo/comment/widget/CommentWidgetHeadProcessor.java index 4407ea9..f2fbcea 100644 --- a/src/main/java/run/halo/comment/widget/CommentWidgetHeadProcessor.java +++ b/src/main/java/run/halo/comment/widget/CommentWidgetHeadProcessor.java @@ -1,7 +1,7 @@ package run.halo.comment.widget; +import java.util.Properties; import lombok.RequiredArgsConstructor; -import org.pf4j.PluginWrapper; import org.springframework.stereotype.Component; import org.springframework.util.PropertyPlaceholderHelper; import org.thymeleaf.context.ITemplateContext; @@ -9,17 +9,16 @@ import org.thymeleaf.model.IModelFactory; import org.thymeleaf.processor.element.IElementModelStructureHandler; import reactor.core.publisher.Mono; +import run.halo.app.plugin.PluginContext; import run.halo.app.theme.dialect.TemplateHeadProcessor; -import java.util.Properties; - @Component @RequiredArgsConstructor public class CommentWidgetHeadProcessor implements TemplateHeadProcessor { static final PropertyPlaceholderHelper PROPERTY_PLACEHOLDER_HELPER = new PropertyPlaceholderHelper("${", "}"); - private final PluginWrapper pluginWrapper; + private final PluginContext pluginContext; @Override public Mono process(ITemplateContext context, IModel model, @@ -32,13 +31,13 @@ public Mono process(ITemplateContext context, IModel model, private String commentWidgetScript() { final Properties properties = new Properties(); - properties.setProperty("version", pluginWrapper.getDescriptor().getVersion()); + properties.setProperty("version", pluginContext.getVersion()); return PROPERTY_PLACEHOLDER_HELPER.replacePlaceholders(""" - - - - - """, properties); + + + + + """, properties); } } diff --git a/src/main/java/run/halo/comment/widget/CommentWidgetPlugin.java b/src/main/java/run/halo/comment/widget/CommentWidgetPlugin.java index b83d35e..b32caf5 100644 --- a/src/main/java/run/halo/comment/widget/CommentWidgetPlugin.java +++ b/src/main/java/run/halo/comment/widget/CommentWidgetPlugin.java @@ -1,8 +1,8 @@ package run.halo.comment.widget; -import org.pf4j.PluginWrapper; import org.springframework.stereotype.Component; import run.halo.app.plugin.BasePlugin; +import run.halo.app.plugin.PluginContext; /** * @author ryanwang @@ -10,15 +10,7 @@ */ @Component public class CommentWidgetPlugin extends BasePlugin { - public CommentWidgetPlugin(PluginWrapper wrapper) { - super(wrapper); - } - - @Override - public void start() { - } - - @Override - public void stop() { + public CommentWidgetPlugin(PluginContext pluginContext) { + super(pluginContext); } } diff --git a/src/main/java/run/halo/comment/widget/DefaultCommentWidget.java b/src/main/java/run/halo/comment/widget/DefaultCommentWidget.java index d12d66e..de8f4f5 100644 --- a/src/main/java/run/halo/comment/widget/DefaultCommentWidget.java +++ b/src/main/java/run/halo/comment/widget/DefaultCommentWidget.java @@ -4,7 +4,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.pf4j.PluginWrapper; import org.springframework.stereotype.Component; import org.springframework.util.Assert; import org.springframework.util.PropertyPlaceholderHelper; @@ -12,7 +11,7 @@ import org.thymeleaf.model.IAttribute; import org.thymeleaf.model.IProcessableElementTag; import org.thymeleaf.processor.element.IElementTagStructureHandler; -import run.halo.app.plugin.SettingFetcher; +import run.halo.app.plugin.PluginContext; import run.halo.app.theme.dialect.CommentWidget; /** @@ -27,7 +26,7 @@ public class DefaultCommentWidget implements CommentWidget { static final PropertyPlaceholderHelper PROPERTY_PLACEHOLDER_HELPER = new PropertyPlaceholderHelper("${", "}"); - private final PluginWrapper pluginWrapper; + private final PluginContext pluginContext; private final SettingConfigGetter settingConfigGetter; @Override @@ -57,7 +56,7 @@ private String commentHtml(IAttribute groupAttribute, IAttribute kindAttribute, final Properties properties = new Properties(); - properties.setProperty("version", pluginWrapper.getDescriptor().getVersion()); + properties.setProperty("version", pluginContext.getVersion()); properties.setProperty("group", group); properties.setProperty("kind", kindAttribute.getValue()); properties.setProperty("name", nameAttribute.getValue());