mirror of
https://github.com/halo-dev/plugin-starter.git
synced 2025-10-17 00:15:01 +00:00
refactor: plugin template
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -9,7 +9,7 @@ logs/
|
|||||||
/out/
|
/out/
|
||||||
!gradle/wrapper/gradle-wrapper.jar
|
!gradle/wrapper/gradle-wrapper.jar
|
||||||
bin/
|
bin/
|
||||||
*.jar
|
|
||||||
### STS ###
|
### STS ###
|
||||||
.apt_generated
|
.apt_generated
|
||||||
.classpath
|
.classpath
|
||||||
|
@@ -5,7 +5,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group 'io.github.guqing'
|
group 'io.github.guqing'
|
||||||
version '1.0-SNAPSHOT'
|
version '0.0.1-SNAPSHOT'
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
@@ -21,6 +21,9 @@ bootJar {
|
|||||||
jar {
|
jar {
|
||||||
enabled = true
|
enabled = true
|
||||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||||
|
manifest.attributes(
|
||||||
|
'Plugin-Version': "${project.version}",
|
||||||
|
)
|
||||||
from {
|
from {
|
||||||
configurations.runtimeClasspath.collect {
|
configurations.runtimeClasspath.collect {
|
||||||
it.isDirectory() ? it : zipTree(it)
|
it.isDirectory() ? it : zipTree(it)
|
||||||
@@ -29,11 +32,13 @@ jar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly files("lib/halo-2.0.0-SNAPSHOT-plain.jar")
|
|
||||||
implementation 'io.github.guqing:pluggable-suite:0.0.1-SNAPSHOT'
|
implementation 'io.github.guqing:pluggable-suite:0.0.1-SNAPSHOT'
|
||||||
|
compileOnly "io.swagger.core.v3:swagger-core-jakarta:2.2.0"
|
||||||
compileOnly 'org.springframework.boot:spring-boot-starter-webflux'
|
compileOnly 'org.springframework.boot:spring-boot-starter-webflux'
|
||||||
annotationProcessor 'io.github.guqing:pluggable-suite:0.0.1-SNAPSHOT'
|
annotationProcessor 'io.github.guqing:pluggable-suite:0.0.1-SNAPSHOT'
|
||||||
|
|
||||||
|
compileOnly files("lib/halo-2.0.0-SNAPSHOT-plain.jar")
|
||||||
|
|
||||||
compileOnly 'org.projectlombok:lombok'
|
compileOnly 'org.projectlombok:lombok'
|
||||||
annotationProcessor 'org.projectlombok:lombok'
|
annotationProcessor 'org.projectlombok:lombok'
|
||||||
|
|
||||||
|
BIN
lib/halo-2.0.0-SNAPSHOT-plain.jar
Normal file
BIN
lib/halo-2.0.0-SNAPSHOT-plain.jar
Normal file
Binary file not shown.
26
src/main/java/io/github/guqing/template/Apple.java
Normal file
26
src/main/java/io/github/guqing/template/Apple.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package io.github.guqing.template;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import run.halo.app.extension.AbstractExtension;
|
||||||
|
import run.halo.app.extension.GVK;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author guqing
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
@GVK(group = "apple.guqing.xyz", kind = "Apple",
|
||||||
|
version = "v1alpha1", singular = "apple", plural = "apples")
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class Apple extends AbstractExtension {
|
||||||
|
|
||||||
|
@Schema(required = true, minLength = 1)
|
||||||
|
private String varieties;
|
||||||
|
|
||||||
|
private String color;
|
||||||
|
|
||||||
|
private String size;
|
||||||
|
}
|
||||||
|
|
30
src/main/java/io/github/guqing/template/ApplePlugin.java
Normal file
30
src/main/java/io/github/guqing/template/ApplePlugin.java
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package io.github.guqing.template;
|
||||||
|
|
||||||
|
import org.pf4j.PluginWrapper;
|
||||||
|
import run.halo.app.extension.Scheme;
|
||||||
|
import run.halo.app.extension.SchemeManager;
|
||||||
|
import run.halo.app.plugin.BasePlugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author guqing
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public class ApplePlugin extends BasePlugin {
|
||||||
|
private final SchemeManager schemeManager;
|
||||||
|
|
||||||
|
public ApplePlugin(PluginWrapper wrapper) {
|
||||||
|
super(wrapper);
|
||||||
|
this.schemeManager = getApplicationContext().getBean(SchemeManager.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start() {
|
||||||
|
schemeManager.register(Apple.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stop() {
|
||||||
|
Scheme scheme = schemeManager.get(Apple.class);
|
||||||
|
schemeManager.unregister(scheme);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,27 +0,0 @@
|
|||||||
package io.github.guqing.template.post;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author guqing
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class Post {
|
|
||||||
private String id;
|
|
||||||
private String userId;
|
|
||||||
private String topicId;
|
|
||||||
private String raw;
|
|
||||||
private String cooked;
|
|
||||||
private LocalDateTime createdAt;
|
|
||||||
private LocalDateTime updatedAt;
|
|
||||||
private LocalDateTime deletedAt;
|
|
||||||
private String replyToPostNumber;
|
|
||||||
private Integer replyCount;
|
|
||||||
private Integer quoteCount;
|
|
||||||
private Integer likeCount;
|
|
||||||
private Integer offTopicCount;
|
|
||||||
private Integer postType;
|
|
||||||
private Integer sortOrder;
|
|
||||||
}
|
|
@@ -1,28 +0,0 @@
|
|||||||
package io.github.guqing.template.post;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import reactor.core.publisher.Flux;
|
|
||||||
import run.halo.app.plugin.ApiVersion;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author guqing
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
@ApiVersion("v1alpha1")
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("posts")
|
|
||||||
public class PostController {
|
|
||||||
|
|
||||||
private final PostService postService;
|
|
||||||
|
|
||||||
public PostController(PostService postService) {
|
|
||||||
this.postService = postService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping
|
|
||||||
public Flux<Post> list() {
|
|
||||||
return postService.list();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,43 +0,0 @@
|
|||||||
package io.github.guqing.template.post;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import reactor.core.publisher.Flux;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author guqing
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
public class PostRepository {
|
|
||||||
|
|
||||||
private final Map<String, Post> postMap = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
public PostRepository() {
|
|
||||||
Post post = new Post();
|
|
||||||
post.setId(UUID.randomUUID().toString());
|
|
||||||
post.setRaw("静态方法适合生成简单的序列,当需要复杂的逻辑时,则应该使用 generate() 或 create() 方法。\n");
|
|
||||||
post.setCooked(post.getRaw());
|
|
||||||
post.setPostType(1);
|
|
||||||
post.setCreatedAt(LocalDateTime.now());
|
|
||||||
post.setLikeCount(1);
|
|
||||||
post.setReplyCount(0);
|
|
||||||
post.setOffTopicCount(0);
|
|
||||||
post.setUserId(UUID.randomUUID().toString());
|
|
||||||
post.setTopicId(UUID.randomUUID().toString());
|
|
||||||
post.setSortOrder(1);
|
|
||||||
postMap.put(post.getId(), post);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Flux<Post> findAll() {
|
|
||||||
return Flux.create(sink -> {
|
|
||||||
for (Post value : postMap.values()) {
|
|
||||||
sink.next(value);
|
|
||||||
}
|
|
||||||
sink.complete();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,20 +0,0 @@
|
|||||||
package io.github.guqing.template.post;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import reactor.core.publisher.Flux;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author guqing
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class PostService {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private PostRepository postRepository;
|
|
||||||
|
|
||||||
public Flux<Post> list() {
|
|
||||||
return postRepository.findAll();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -2,14 +2,15 @@ apiVersion: plugin.halo.run/v1alpha1
|
|||||||
kind: Plugin
|
kind: Plugin
|
||||||
metadata:
|
metadata:
|
||||||
# The name defines how the plugin is invoked,A unique name
|
# The name defines how the plugin is invoked,A unique name
|
||||||
name: io.github.guqing.apples
|
name: apples
|
||||||
spec:
|
spec:
|
||||||
enabled: true
|
enabled: true
|
||||||
# 'version' is a valid semantic version string (see semver.org).
|
# 'version' is a valid semantic version string (see semver.org).
|
||||||
version: 0.0.1
|
version: 0.0.1-SNAPSHOT
|
||||||
requires: "*"
|
requires: "*"
|
||||||
author: guqing
|
author: guqing
|
||||||
logo: https://guqing.xyz/avatar
|
logo: https://guqing.xyz/avatar
|
||||||
|
pluginClass: io.github.guqing.template.ApplePlugin
|
||||||
# 'homepage' usually links to the GitHub repository of the plugin
|
# 'homepage' usually links to the GitHub repository of the plugin
|
||||||
homepage: https://github.com/guqing/halo-plugin-template
|
homepage: https://github.com/guqing/halo-plugin-template
|
||||||
# 'displayName' explains what the plugin does in only a few words
|
# 'displayName' explains what the plugin does in only a few words
|
||||||
|
Reference in New Issue
Block a user