Skip to content

Commit 7726f77

Browse files
author
fxu
committed
refactor(plugin):优化插件管理与配置加载逻辑
- 使用 ConfigureUtil 统一处理日志与插件路径 - 更新日志文件存储路径至用户主目录下 -重构插件配置文件读取与保存方法 - 调整 PluginJarInfo 文件路径获取方式
1 parent f8bc731 commit 7726f77

5 files changed

Lines changed: 23 additions & 31 deletions

File tree

xJavaFxTool/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ plugins {
2222
dependencies {
2323
api project(':xcore')
2424
// implementation "com.sandec.jpro:jpro-webapi:2024.2.1"
25-
api project(":littleTools:x-EncryptAndDecrypt")
25+
// api project(":littleTools:x-EncryptAndDecrypt")
2626
// api project(":littleTools:x-ZHConverter")
27-
api project(":littleTools:x-ImageTool")
28-
api project(":littleTools:x-IconTool")
27+
// api project(":littleTools:x-ImageTool")
28+
// api project(":littleTools:x-IconTool")
2929
// api project(":littleTools:x-PdfConvertTool")
3030
// api project(":littleTools:x-QRCodeBuilder")
3131
// api project(":littleTools:x-FileCopy")
@@ -35,7 +35,7 @@ dependencies {
3535
// api project(":littleTools:x-BookManageSystem")
3636
// api project(":littleTools:x-CoordinateTransformTool")
3737
// api project(":littleTools:x-ElementaryArithmeticProblemTool")
38-
api project(":littleTools:x-CronExpBuilder")
38+
// api project(":littleTools:x-CronExpBuilder")
3939
// api project(":littleTools:x-EmailTool")
4040
// api project(":littleTools:x-ExcelSplitTool")
4141
// api project(":littleTools:x-FileBuildTool")
@@ -68,7 +68,7 @@ dependencies {
6868
// api project(":debugTools:x-RedisTool")
6969
// api project(":debugTools:x-ScriptEngineTool")
7070
// api project(":debugTools:x-ZookeeperTool")
71-
api project(":codeTools:x-RegexTester")
71+
// api project(":codeTools:x-RegexTester")
7272
// api project(":codeTools:x-RandomGeneratorTool")
7373
// api project(":codeTools:x-IdCardGenerator")
7474
// api project(":codeTools:x-CharsetDetectTool")

xJavaFxTool/src/main/java/com/xwintop/xJavaFxTool/controller/IndexController.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ private void initService() {
104104
PluginManager pluginManager = PluginManager.getInstance();
105105
pluginManager.getDevPluginList().clear();
106106
pluginManager.getLocalDevPluginList().clear();
107-
pluginManager.getPluginList().clear();
108107
pluginManager.loadDevPluginConfiguration();
109108
pluginManager.loadLocalDevPluginConfiguration();
110109
pluginManager.loadLocalPlugins();
@@ -261,13 +260,13 @@ private void setLanguageAction(ActionEvent event) throws Exception {
261260

262261
@FXML
263262
private void openLogFileAction() {
264-
String filePath = "logs/logFile.log";
263+
String filePath = ConfigureUtil.getConfigurePath("logs/logFile.log");
265264
JavaFxSystemUtil.openDirectory(filePath);
266265
}
267266

268267
@FXML
269268
private void openLogFolderAction() {
270-
JavaFxSystemUtil.openDirectory("logs/");
269+
JavaFxSystemUtil.openDirectory(ConfigureUtil.getConfigurePath("logs/"));
271270
}
272271

273272
@FXML
@@ -277,7 +276,7 @@ private void openConfigFolderAction() {
277276

278277
@FXML
279278
private void openPluginFolderAction() {
280-
JavaFxSystemUtil.openDirectory("libs/");
279+
JavaFxSystemUtil.openDirectory(ConfigureUtil.getConfigurePath("libs/"));
281280
}
282281

283282
@FXML

xJavaFxTool/src/main/java/com/xwintop/xJavaFxTool/model/PluginJarInfo.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.xwintop.xJavaFxTool.model;
22

33
import com.alibaba.fastjson2.annotation.JSONField;
4+
import com.xwintop.xcore.util.ConfigureUtil;
45
import javafx.scene.image.Image;
56
import lombok.Data;
67
import lombok.NoArgsConstructor;
@@ -17,7 +18,7 @@
1718
@NoArgsConstructor
1819
public class PluginJarInfo {
1920

20-
///////////////////////////////////////// 下面的属性在远程插件列表和本地配置中都存在
21+
///下面的属性在远程插件列表和本地配置中都存在
2122

2223
private String name; // 名称
2324

@@ -31,7 +32,7 @@ public class PluginJarInfo {
3132

3233
private String downloadUrl; // 下载地址
3334

34-
///////////////////////////////////////// 下面的属性在远程插件列表中不存在
35+
///下面的属性在远程插件列表中不存在
3536

3637
private Boolean isDownload; // 是否下载
3738

@@ -43,7 +44,7 @@ public class PluginJarInfo {
4344

4445
private String localPath; // 插件本地文件路径(如果是本地插件)
4546

46-
///////////////////////////////////////// 下面的属性来自插件描述文件 toolFxmlLoaderConfiguration.xml
47+
///下面的属性来自插件描述文件 toolFxmlLoaderConfiguration.xml
4748

4849
private String fxmlPath; // FXML 资源路径
4950

@@ -67,17 +68,13 @@ public class PluginJarInfo {
6768

6869
private String controllerType = "Node"; // 内容类型(Node/WebView)
6970

70-
////////////////////////////////////////////////////////////
71-
7271
public boolean getIsFavorite() {
7372
return this.isFavorite != null && this.isFavorite;
7473
}
7574

76-
////////////////////////////////////////////////////////////
77-
7875
@JSONField(serialize = false)
7976
public File getFile() {
80-
return localPath == null? new File("libs/", getJarName() + "-" + getVersion() + ".jar"): new File(localPath);
77+
return localPath == null ? ConfigureUtil.getConfigureFile("libs/" + getJarName() + "-" + getVersion() + ".jar") : new File(localPath);
8178
}
8279

8380
@JSONField(serialize = false)

xJavaFxTool/src/main/java/com/xwintop/xJavaFxTool/plugin/PluginManager.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.alibaba.fastjson2.JSON;
44
import com.xwintop.xJavaFxTool.model.PluginJarInfo;
5+
import com.xwintop.xcore.util.ConfigureUtil;
56
import lombok.Data;
67
import lombok.extern.slf4j.Slf4j;
78
import org.apache.commons.io.FileUtils;
@@ -11,9 +12,6 @@
1112
import java.io.IOException;
1213
import java.net.URL;
1314
import java.nio.charset.StandardCharsets;
14-
import java.nio.file.Files;
15-
import java.nio.file.Path;
16-
import java.nio.file.Paths;
1715
import java.util.ArrayList;
1816
import java.util.Enumeration;
1917
import java.util.List;
@@ -23,7 +21,7 @@
2321
@Slf4j
2422
@Data
2523
public class PluginManager {
26-
public static final String LOCAL_PLUGINS_PATH = "./system_plugin_list.json";
24+
public static final String LOCAL_PLUGINS_PATH = "system_plugin_list.json";
2725

2826
private static PluginManager instance;
2927

@@ -62,11 +60,12 @@ public PluginJarInfo getPlugin(String jarName) {
6260
*/
6361
private void loadLocalPluginConfiguration() {
6462
try {
65-
Path path = Paths.get(LOCAL_PLUGINS_PATH);
66-
if (!Files.exists(path)) {
63+
File file = ConfigureUtil.getConfigureFile(LOCAL_PLUGINS_PATH);
64+
if (!file.exists()) {
6765
return;
6866
}
69-
String json = FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8);
67+
String json = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
68+
this.pluginList.clear();
7069
this.pluginList.addAll(JSON.parseArray(json, PluginJarInfo.class));
7170
} catch (IOException e) {
7271
log.error("读取插件配置失败", e);
@@ -177,11 +176,8 @@ public void loadLocalPlugins() {
177176
// 保存配置,如果失败则抛出异常
178177
public void saveToFile() throws IOException {
179178
String json = JSON.toJSONString(this.pluginList);
180-
Path path = Paths.get(LOCAL_PLUGINS_PATH);
181-
if (!Files.exists(path)) {
182-
Files.createFile(path);
183-
}
184-
FileUtils.writeStringToFile(path.toFile(), json, StandardCharsets.UTF_8);
179+
File file = ConfigureUtil.getConfigureFile(LOCAL_PLUGINS_PATH);
180+
FileUtils.writeStringToFile(file, json, StandardCharsets.UTF_8);
185181
}
186182

187183
// 保存配置,如果失败不抛出异常

xJavaFxTool/src/main/resources/logback.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<configuration>
22
<jmxConfigurator/>
33
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
4-
<file>logs/logFile.log</file>
4+
<file>${user.home}/xJavaFxTool/logs/logFile.log</file>
55
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
6-
<fileNamePattern>logs/logFile.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
6+
<fileNamePattern>${user.home}/xJavaFxTool/logs/logFile.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
77
<maxFileSize>100MB</maxFileSize>
88
<maxHistory>30</maxHistory>
99
<totalSizeCap>3GB</totalSizeCap>

0 commit comments

Comments
 (0)