插件版本更新

This commit is contained in:
张家训
2026-06-09 09:41:30 +08:00
parent 75a1049d8e
commit b964fef4dd
13 changed files with 661 additions and 276 deletions
@@ -1,7 +1,7 @@
package com.example.workutils;
import com.example.workutils.system.tool.Tool;
import com.example.workutils.system.tool.ToolRegistry;
import com.example.workutils.system.plugin.Plugin;
import com.example.workutils.system.plugin.PluginManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
@@ -16,10 +16,10 @@ import java.util.Scanner;
@Slf4j
public class WorkUtilsApplication implements CommandLineRunner {
private final ToolRegistry toolRegistry;
private final PluginManager pluginManager;
public WorkUtilsApplication(ToolRegistry toolRegistry) {
this.toolRegistry = toolRegistry;
public WorkUtilsApplication(PluginManager pluginManager) {
this.pluginManager = pluginManager;
}
public static void main(String[] args) {
@@ -37,25 +37,25 @@ public class WorkUtilsApplication implements CommandLineRunner {
private void showInteractiveMenu() {
Scanner scanner = new Scanner(System.in);
toolRegistry.runMainMenu(scanner);
pluginManager.runMainMenu(scanner);
}
/**
* 命令行模式:通过ToolRegistry按命令名分发到对应Tool
* 启动类不依赖任何具体业务Service
* 命令行模式:通过 PluginManager 按命令名分发到对应 Plugin
* 启动类不依赖任何具体业务 Service
*/
private void processCommand(String... args) throws Exception {
String command = args[0].toLowerCase();
Optional<Tool> toolOpt = toolRegistry.getToolByCommand(command);
if (toolOpt.isPresent()) {
Tool tool = toolOpt.get();
Optional<Plugin> pluginOpt = pluginManager.getPluginByCommand(command);
if (pluginOpt.isPresent()) {
Plugin plugin = pluginOpt.get();
try {
// args[0]是命令名,从args[1]开始传给tool
String[] toolArgs = args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0];
tool.executeCommand(toolArgs);
// args[0]是命令名,从args[1]开始传给plugin
String[] pluginArgs = args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0];
plugin.executeCommand(pluginArgs);
} catch (Exception e) {
log.error("命令执行失败: {} [{}]", tool.getName(), tool.getId(), e);
log.error("命令执行失败: {} [{}]", plugin.getName(), plugin.getId(), e);
System.err.println("命令执行失败: " + e.getMessage());
}
} else {