Skip to content

Commit 35ab602

Browse files
authored
chore: replace plugin wrapper with plugin context (#136)
### What this PR does? 替换插件中对于 PluginWrapper 的引用,这是已经过时的引用,这将在后续被移除 ```release-note None ```
1 parent ec513c2 commit 35ab602

File tree

3 files changed

+15
-25
lines changed

3 files changed

+15
-25
lines changed
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
package run.halo.comment.widget;
22

3+
import java.util.Properties;
34
import lombok.RequiredArgsConstructor;
4-
import org.pf4j.PluginWrapper;
55
import org.springframework.stereotype.Component;
66
import org.springframework.util.PropertyPlaceholderHelper;
77
import org.thymeleaf.context.ITemplateContext;
88
import org.thymeleaf.model.IModel;
99
import org.thymeleaf.model.IModelFactory;
1010
import org.thymeleaf.processor.element.IElementModelStructureHandler;
1111
import reactor.core.publisher.Mono;
12+
import run.halo.app.plugin.PluginContext;
1213
import run.halo.app.theme.dialect.TemplateHeadProcessor;
1314

14-
import java.util.Properties;
15-
1615
@Component
1716
@RequiredArgsConstructor
1817
public class CommentWidgetHeadProcessor implements TemplateHeadProcessor {
1918

2019
static final PropertyPlaceholderHelper PROPERTY_PLACEHOLDER_HELPER = new PropertyPlaceholderHelper("${", "}");
2120

22-
private final PluginWrapper pluginWrapper;
21+
private final PluginContext pluginContext;
2322

2423
@Override
2524
public Mono<Void> process(ITemplateContext context, IModel model,
@@ -32,13 +31,13 @@ public Mono<Void> process(ITemplateContext context, IModel model,
3231
private String commentWidgetScript() {
3332

3433
final Properties properties = new Properties();
35-
properties.setProperty("version", pluginWrapper.getDescriptor().getVersion());
34+
properties.setProperty("version", pluginContext.getVersion());
3635

3736
return PROPERTY_PLACEHOLDER_HELPER.replacePlaceholders("""
38-
<!-- plugin-comment-widget start -->
39-
<script src="/plugins/PluginCommentWidget/assets/static/comment-widget.iife.js?version=${version}"></script>
40-
<link rel="stylesheet" href="/plugins/PluginCommentWidget/assets/static/style.css?version=${version}" />
41-
<!-- plugin-comment-widget end -->
42-
""", properties);
37+
<!-- plugin-comment-widget start -->
38+
<script src="/plugins/PluginCommentWidget/assets/static/comment-widget.iife.js?version=${version}"></script>
39+
<link rel="stylesheet" href="/plugins/PluginCommentWidget/assets/static/style.css?version=${version}" />
40+
<!-- plugin-comment-widget end -->
41+
""", properties);
4342
}
4443
}
Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
11
package run.halo.comment.widget;
22

3-
import org.pf4j.PluginWrapper;
43
import org.springframework.stereotype.Component;
54
import run.halo.app.plugin.BasePlugin;
5+
import run.halo.app.plugin.PluginContext;
66

77
/**
88
* @author ryanwang
99
* @since 2.0.0
1010
*/
1111
@Component
1212
public class CommentWidgetPlugin extends BasePlugin {
13-
public CommentWidgetPlugin(PluginWrapper wrapper) {
14-
super(wrapper);
15-
}
16-
17-
@Override
18-
public void start() {
19-
}
20-
21-
@Override
22-
public void stop() {
13+
public CommentWidgetPlugin(PluginContext pluginContext) {
14+
super(pluginContext);
2315
}
2416
}

src/main/java/run/halo/comment/widget/DefaultCommentWidget.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
import lombok.RequiredArgsConstructor;
55
import lombok.extern.slf4j.Slf4j;
66
import org.apache.commons.lang3.StringUtils;
7-
import org.pf4j.PluginWrapper;
87
import org.springframework.stereotype.Component;
98
import org.springframework.util.Assert;
109
import org.springframework.util.PropertyPlaceholderHelper;
1110
import org.thymeleaf.context.ITemplateContext;
1211
import org.thymeleaf.model.IAttribute;
1312
import org.thymeleaf.model.IProcessableElementTag;
1413
import org.thymeleaf.processor.element.IElementTagStructureHandler;
15-
import run.halo.app.plugin.SettingFetcher;
14+
import run.halo.app.plugin.PluginContext;
1615
import run.halo.app.theme.dialect.CommentWidget;
1716

1817
/**
@@ -27,7 +26,7 @@
2726
public class DefaultCommentWidget implements CommentWidget {
2827
static final PropertyPlaceholderHelper PROPERTY_PLACEHOLDER_HELPER = new PropertyPlaceholderHelper("${", "}");
2928

30-
private final PluginWrapper pluginWrapper;
29+
private final PluginContext pluginContext;
3130
private final SettingConfigGetter settingConfigGetter;
3231

3332
@Override
@@ -57,7 +56,7 @@ private String commentHtml(IAttribute groupAttribute, IAttribute kindAttribute,
5756

5857
final Properties properties = new Properties();
5958

60-
properties.setProperty("version", pluginWrapper.getDescriptor().getVersion());
59+
properties.setProperty("version", pluginContext.getVersion());
6160
properties.setProperty("group", group);
6261
properties.setProperty("kind", kindAttribute.getValue());
6362
properties.setProperty("name", nameAttribute.getValue());

0 commit comments

Comments
 (0)