Skip to content

Commit

Permalink
plugin spring
Browse files Browse the repository at this point in the history
  • Loading branch information
Linyuzai committed Jun 9, 2024
1 parent 0f4901d commit d2b6472
Show file tree
Hide file tree
Showing 64 changed files with 849 additions and 688 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.github.linyuzai.plugin.core.exception.PluginException;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.io.File;
import java.util.function.Predicate;
Expand All @@ -12,33 +12,33 @@
* 监听插件位置
*/
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class PluginLocation {

/**
* 路径
*/
private String path;
private final String path;

/**
* 过滤器
*/
private Predicate<String> filter;
private final Predicate<String> filter;

/**
* 触发创建回调
*/
private boolean notifyCreate;
private final boolean notifyCreate;

/**
* 触发修改回调
*/
private boolean notifyModify;
private final boolean notifyModify;

/**
* 触发删除回调
*/
private boolean notifyDelete;
private final boolean notifyDelete;

public static final class Builder {
private String path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import com.github.linyuzai.plugin.core.concept.Plugin;
import com.github.linyuzai.plugin.core.concept.PluginConcept;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.net.URL;
import java.nio.file.StandardWatchEventKinds;
import java.nio.file.WatchEvent;
import java.util.function.BiConsumer;
Expand All @@ -14,7 +13,7 @@
* 插件自动加载通知者
*/
@Getter
@AllArgsConstructor
@RequiredArgsConstructor
public abstract class PluginNotifier implements BiConsumer<String, WatchEvent.Kind<?>> {

protected final PluginConcept concept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.io.IOException;
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;

@Getter
Expand Down Expand Up @@ -54,8 +55,7 @@ protected PluginContext createReadContent() {
@Override
public void prepare(PluginContext context) {
PluginTree.NodeFactory node = context.get(PluginTree.Node.class);
Collection<Entry> entries = collectEntries(context);
for (Entry entry : entries) {
collectEntries(context, entry -> {
Plugin subPlugin = getConcept().create(entry, context);
if (subPlugin == null) {
node.create(entry.getId(), entry.getName(), entry);
Expand All @@ -68,7 +68,7 @@ public void prepare(PluginContext context) {
subPlugin.prepare(subContext);
subContext.destroy();
}
}
});
onPrepare(context);
}

Expand All @@ -95,7 +95,7 @@ public void release(PluginContext context) {
onRelease(context);
}

public abstract Collection<Entry> collectEntries(PluginContext context);
public abstract void collectEntries(PluginContext context, Consumer<Entry> consumer);

public void onPrepare(PluginContext context) {

Expand Down
Loading

0 comments on commit d2b6472

Please sign in to comment.