From 47804e9975acd4a4c640b907f256db7fcf054ca6 Mon Sep 17 00:00:00 2001 From: guqing Date: Thu, 27 Jun 2024 16:27:53 +0800 Subject: [PATCH] chore: replace plugin wrapper with plugin context --- .../widget/CommentWidgetHeadProcessor.java | 19 +++++++++---------- .../comment/widget/CommentWidgetPlugin.java | 14 +++----------- .../comment/widget/DefaultCommentWidget.java | 6 +++--- 3 files changed, 15 insertions(+), 24 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 baeb9f5..12d9052 100644 --- a/src/main/java/run/halo/comment/widget/DefaultCommentWidget.java +++ b/src/main/java/run/halo/comment/widget/DefaultCommentWidget.java @@ -5,7 +5,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; @@ -13,6 +12,7 @@ import org.thymeleaf.model.IAttribute; import org.thymeleaf.model.IProcessableElementTag; import org.thymeleaf.processor.element.IElementTagStructureHandler; +import run.halo.app.plugin.PluginContext; import run.halo.app.plugin.SettingFetcher; import run.halo.app.theme.dialect.CommentWidget; @@ -28,7 +28,7 @@ public class DefaultCommentWidget implements CommentWidget { static final PropertyPlaceholderHelper PROPERTY_PLACEHOLDER_HELPER = new PropertyPlaceholderHelper("${", "}"); - private final PluginWrapper pluginWrapper; + private final PluginContext pluginContext; private final SettingFetcher settingFetcher; private final SettingConfigGetter settingConfigGetter; @@ -59,7 +59,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());