diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 4653f36..6a479b1 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -9,6 +9,7 @@
+
@@ -34,6 +35,7 @@
+
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
index 4e65c60..fc2343b 100644
--- a/.idea/encodings.xml
+++ b/.idea/encodings.xml
@@ -4,7 +4,6 @@
-
@@ -14,6 +13,8 @@
+
+
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c457f0d..6ae0bae 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,15 @@
- 🎈新增: 新增 `JsonFileUtil` 工具类,用于进行json文件的读写操作
- 🎈新增: 新增 `FileUtil` 工具类,用于进行文件复制文件删除等操作
- 🎈新增: 新增 `FileCondition` 方法,用于对文件递归删除进行条件过滤
+- 🎈新增: 新增 `ModuleConfigSrcInit` 初始化模块,用于初始化各个模块的配置文件夹,以及模块配置文件路径管理
+- 🎈新增: 新增 `ModuleConfigSrc` 模块配置类
- 🧪测试: 测试 `FileUtil` 工具类, 测试 `JsonFileUtil` 工具类
+### console
+- 🎈新增: 新增 `InitWord` 用于整个项目的初始化启动
+
+### 🎈新增 common 模块
+- 🎈新增: 新增 `InitMachine` 初始化机器接口,为所有模块初始化类提供统一接口
+
+
diff --git a/FileModule/pom.xml b/FileModule/pom.xml
index 8e5c0b0..e18c0a0 100644
--- a/FileModule/pom.xml
+++ b/FileModule/pom.xml
@@ -18,6 +18,11 @@
+
+ org.example
+ common
+ 1.0-SNAPSHOT
+
com.alibaba
@@ -32,7 +37,6 @@
org.projectlombok
lombok
- test
diff --git a/FileModule/src/main/java/org/example/bean/ModuleConfigSrc.java b/FileModule/src/main/java/org/example/bean/ModuleConfigSrc.java
new file mode 100644
index 0000000..72df930
--- /dev/null
+++ b/FileModule/src/main/java/org/example/bean/ModuleConfigSrc.java
@@ -0,0 +1,15 @@
+package org.example.bean;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+/**
+ * @author Genius
+ * @date 2023/04/20 19:29
+ **/
+
+@Data
+@AllArgsConstructor
+public class ModuleConfigSrc {
+ private String src;
+}
diff --git a/FileModule/src/main/java/org/example/init/ModuleConfigSrcInit.java b/FileModule/src/main/java/org/example/init/ModuleConfigSrcInit.java
new file mode 100644
index 0000000..bef80f5
--- /dev/null
+++ b/FileModule/src/main/java/org/example/init/ModuleConfigSrcInit.java
@@ -0,0 +1,99 @@
+package org.example.init;
+
+import org.example.bean.ModuleConfigSrc;
+import org.example.util.FileUtil;
+import org.example.util.JsonFileUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * @author Genius
+ * @date 2023/04/20 18:34
+ **/
+
+public class ModuleConfigSrcInit implements InitMachine {
+
+ private Logger logger = LoggerFactory.getLogger(ModuleConfigSrcInit.class);
+ private static final Map config;
+
+ static{
+ config = Map.of(
+ "account", new ModuleConfigSrc("./config/account"),
+ "section", new ModuleConfigSrc("./config/section"),
+ "barrage", new ModuleConfigSrc("./config/barrage"),
+ "creeper", new ModuleConfigSrc("./config/creeper"),
+ "videowork", new ModuleConfigSrc("./config/videowork"),
+ "hot", new ModuleConfigSrc("./config/hot"),
+ "publish", new ModuleConfigSrc("./config/publish")
+ );
+ }
+
+ private static final String CONFIG_SRC = "./config";
+ private static final String CONFIG_SRC_FILE = "moduleConfig.json";
+
+ // 初始化每个模块的配置文件夹
+ @Override
+ public boolean init() {
+ Path dir = Paths.get(CONFIG_SRC);
+ if (!createConfigDirectory(dir)) {
+ return false;
+ }
+ if (!createConfigFile(dir)) {
+ return false;
+ }
+ if (!createModuleDirectory()) {
+ return false;
+ }
+ return true;
+ }
+
+ private boolean createConfigDirectory(Path dir) {
+ try {
+ if (!Files.exists(dir)) {
+ Files.createDirectory(dir);
+ logger.info("创建 config 文件夹成功 √ ");
+ }
+ }catch (Exception e) {
+ logger.error("创建配置文件夹失败");
+ return false;
+ }
+ return true;
+ }
+
+ private boolean createConfigFile(Path dir) {
+ Path path = Paths.get(dir.toString(), CONFIG_SRC_FILE);
+ try {
+ if (!Files.exists(path)) {
+ JsonFileUtil.writeJsonFile(path.toString(),config);
+ logger.info("创建 {} 配置文件成功 √",CONFIG_SRC_FILE);
+ }
+ }catch (Exception e) {
+ logger.error("创建配置文件失败");
+ return false;
+ }
+ return true;
+ }
+
+ private boolean createModuleDirectory() {
+ for (Map.Entry stringModuleConfigSrcEntry : config.entrySet()) {
+ ModuleConfigSrc moduleConfigSrc = stringModuleConfigSrcEntry.getValue();
+ try {
+ if (!FileUtil.isFileExist(moduleConfigSrc.getSrc())) {
+ Files.createDirectory(Path.of(moduleConfigSrc.getSrc()));
+ logger.info("创建 {} 模块文件夹成功 √ ",moduleConfigSrc.getSrc());
+ }
+ }catch (Exception e) {
+ logger.error("创建 {} 模块文件夹失败 ×",moduleConfigSrc.getSrc());
+ return false;
+ }
+ }
+ return true;
+ }
+}
diff --git a/FileModule/src/main/resources/student.json b/FileModule/src/main/resources/student.json
new file mode 100644
index 0000000..ea587fa
--- /dev/null
+++ b/FileModule/src/main/resources/student.json
@@ -0,0 +1,15 @@
+{
+ "age":18,
+ "hobby":[
+ "Coding",
+ "Reading",
+ "Playing"
+ ],
+ "info":{
+ "QQ":"123456789",
+ "WeChat":"987654321"
+ },
+ "major":"CS",
+ "name":"Genius",
+ "school":"HUST"
+}
\ No newline at end of file
diff --git a/FileModule/src/main/resources/student2.json b/FileModule/src/main/resources/student2.json
new file mode 100644
index 0000000..c4be758
--- /dev/null
+++ b/FileModule/src/main/resources/student2.json
@@ -0,0 +1 @@
+[{"age":18,"hobby":["Coding","Reading","Playing"],"info":{"QQ":"123456789","WeChat":"987654321"},"major":"CS","name":"Genius","school":"HUST"}]
\ No newline at end of file
diff --git a/FileModule/src/main/resources/test2.json b/FileModule/src/main/resources/test2.json
new file mode 100644
index 0000000..ddb85d9
--- /dev/null
+++ b/FileModule/src/main/resources/test2.json
@@ -0,0 +1,19 @@
+{
+ "module":{
+ "ui":"console-ui",
+ "main":"console",
+ "type":[
+ "Account",
+ "Creeper",
+ "File",
+ "Hot",
+ "Publish",
+ "Section",
+ "SectionWork",
+ "VideoSection"
+ ]
+ },
+ "name":"ChopperBot",
+ "description":"A bot for the ChopperMC server",
+ "version":"1.0.0"
+}
\ No newline at end of file
diff --git a/FileModule/src/test/java/org/example/util/FileUtilTest.java b/FileModule/src/test/java/org/example/util/FileUtilTest.java
index cd0d98d..aadde4a 100644
--- a/FileModule/src/test/java/org/example/util/FileUtilTest.java
+++ b/FileModule/src/test/java/org/example/util/FileUtilTest.java
@@ -3,6 +3,9 @@ package org.example.util;
import org.junit.jupiter.api.Test;
import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
/**
* @author Genius
@@ -14,4 +17,9 @@ public class FileUtilTest {
public void testDelete() throws IOException {
FileUtil.deleteDirectory("E:\\Project\\ChopperBot\\FileModule\\src\\main\\resources\\trash");
}
+
+ @Test
+ public void testCreate() throws IOException {
+ Files.createDirectories(Paths.get("./Hello"));
+ }
}
diff --git a/FileModule/target/classes/org/example/bean/ModuleConfigSrc.class b/FileModule/target/classes/org/example/bean/ModuleConfigSrc.class
new file mode 100644
index 0000000..38e1a24
Binary files /dev/null and b/FileModule/target/classes/org/example/bean/ModuleConfigSrc.class differ
diff --git a/FileModule/target/classes/org/example/init/ModuleConfigSrcInit.class b/FileModule/target/classes/org/example/init/ModuleConfigSrcInit.class
new file mode 100644
index 0000000..593c22d
Binary files /dev/null and b/FileModule/target/classes/org/example/init/ModuleConfigSrcInit.class differ
diff --git a/FileModule/target/classes/org/example/method/FileCondition.class b/FileModule/target/classes/org/example/method/FileCondition.class
new file mode 100644
index 0000000..1f185c3
Binary files /dev/null and b/FileModule/target/classes/org/example/method/FileCondition.class differ
diff --git a/FileModule/target/classes/org/example/util/FileUtil$1.class b/FileModule/target/classes/org/example/util/FileUtil$1.class
new file mode 100644
index 0000000..7cdbfab
Binary files /dev/null and b/FileModule/target/classes/org/example/util/FileUtil$1.class differ
diff --git a/FileModule/target/classes/org/example/util/FileUtil.class b/FileModule/target/classes/org/example/util/FileUtil.class
new file mode 100644
index 0000000..452cb6a
Binary files /dev/null and b/FileModule/target/classes/org/example/util/FileUtil.class differ
diff --git a/FileModule/target/classes/org/example/util/JsonFileUtil.class b/FileModule/target/classes/org/example/util/JsonFileUtil.class
new file mode 100644
index 0000000..276fc0a
Binary files /dev/null and b/FileModule/target/classes/org/example/util/JsonFileUtil.class differ
diff --git a/FileModule/target/classes/student.json b/FileModule/target/classes/student.json
new file mode 100644
index 0000000..ea587fa
--- /dev/null
+++ b/FileModule/target/classes/student.json
@@ -0,0 +1,15 @@
+{
+ "age":18,
+ "hobby":[
+ "Coding",
+ "Reading",
+ "Playing"
+ ],
+ "info":{
+ "QQ":"123456789",
+ "WeChat":"987654321"
+ },
+ "major":"CS",
+ "name":"Genius",
+ "school":"HUST"
+}
\ No newline at end of file
diff --git a/FileModule/target/classes/student2.json b/FileModule/target/classes/student2.json
new file mode 100644
index 0000000..c4be758
--- /dev/null
+++ b/FileModule/target/classes/student2.json
@@ -0,0 +1 @@
+[{"age":18,"hobby":["Coding","Reading","Playing"],"info":{"QQ":"123456789","WeChat":"987654321"},"major":"CS","name":"Genius","school":"HUST"}]
\ No newline at end of file
diff --git a/FileModule/target/classes/test.json b/FileModule/target/classes/test.json
new file mode 100644
index 0000000..2378b53
--- /dev/null
+++ b/FileModule/target/classes/test.json
@@ -0,0 +1,10 @@
+{
+ "name": "ChopperBot",
+ "description": "A bot for the ChopperMC server",
+ "version": "1.0.0",
+ "module": {
+ "type": ["Account","Creeper","File","Hot","Publish","Section","SectionWork","VideoSection"],
+ "main": "console",
+ "ui": "console-ui"
+ }
+}
diff --git a/FileModule/target/classes/test2.json b/FileModule/target/classes/test2.json
new file mode 100644
index 0000000..ddb85d9
--- /dev/null
+++ b/FileModule/target/classes/test2.json
@@ -0,0 +1,19 @@
+{
+ "module":{
+ "ui":"console-ui",
+ "main":"console",
+ "type":[
+ "Account",
+ "Creeper",
+ "File",
+ "Hot",
+ "Publish",
+ "Section",
+ "SectionWork",
+ "VideoSection"
+ ]
+ },
+ "name":"ChopperBot",
+ "description":"A bot for the ChopperMC server",
+ "version":"1.0.0"
+}
\ No newline at end of file
diff --git a/FileModule/target/test-classes/org/example/AppTest.class b/FileModule/target/test-classes/org/example/AppTest.class
new file mode 100644
index 0000000..9021d1d
Binary files /dev/null and b/FileModule/target/test-classes/org/example/AppTest.class differ
diff --git a/FileModule/target/test-classes/org/example/bean/Student.class b/FileModule/target/test-classes/org/example/bean/Student.class
new file mode 100644
index 0000000..5468203
Binary files /dev/null and b/FileModule/target/test-classes/org/example/bean/Student.class differ
diff --git a/FileModule/target/test-classes/org/example/util/FileUtilTest.class b/FileModule/target/test-classes/org/example/util/FileUtilTest.class
new file mode 100644
index 0000000..49f6b31
Binary files /dev/null and b/FileModule/target/test-classes/org/example/util/FileUtilTest.class differ
diff --git a/FileModule/target/test-classes/org/example/util/JsonFileUtilTest.class b/FileModule/target/test-classes/org/example/util/JsonFileUtilTest.class
new file mode 100644
index 0000000..46f933c
Binary files /dev/null and b/FileModule/target/test-classes/org/example/util/JsonFileUtilTest.class differ
diff --git a/common/pom.xml b/common/pom.xml
new file mode 100644
index 0000000..4f9be75
--- /dev/null
+++ b/common/pom.xml
@@ -0,0 +1,28 @@
+
+
+ ChopperBot
+ org.example
+ 1.0-SNAPSHOT
+
+ 4.0.0
+
+ common
+ jar
+
+ common
+ http://maven.apache.org
+
+
+ UTF-8
+
+
+
+
+ junit
+ junit
+ 3.8.1
+ test
+
+
+
diff --git a/common/src/main/java/org/example/App.java b/common/src/main/java/org/example/App.java
new file mode 100644
index 0000000..5f21d2e
--- /dev/null
+++ b/common/src/main/java/org/example/App.java
@@ -0,0 +1,13 @@
+package org.example;
+
+/**
+ * Hello world!
+ *
+ */
+public class App
+{
+ public static void main( String[] args )
+ {
+ System.out.println( "Hello World!" );
+ }
+}
diff --git a/common/src/main/java/org/example/init/InitMachine.java b/common/src/main/java/org/example/init/InitMachine.java
new file mode 100644
index 0000000..45a2ac8
--- /dev/null
+++ b/common/src/main/java/org/example/init/InitMachine.java
@@ -0,0 +1,13 @@
+package org.example.init;
+
+
+/**
+ * @author Genius
+ * @date 2023/04/20 19:36
+ **/
+
+//模块初始化接口
+public interface InitMachine {
+
+ boolean init();
+}
diff --git a/common/src/test/java/org/example/AppTest.java b/common/src/test/java/org/example/AppTest.java
new file mode 100644
index 0000000..d5f435d
--- /dev/null
+++ b/common/src/test/java/org/example/AppTest.java
@@ -0,0 +1,38 @@
+package org.example;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest
+ extends TestCase
+{
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public AppTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite()
+ {
+ return new TestSuite( AppTest.class );
+ }
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testApp()
+ {
+ assertTrue( true );
+ }
+}
diff --git a/common/target/classes/org/example/App.class b/common/target/classes/org/example/App.class
new file mode 100644
index 0000000..98ea2dc
Binary files /dev/null and b/common/target/classes/org/example/App.class differ
diff --git a/common/target/classes/org/example/init/InitMachine.class b/common/target/classes/org/example/init/InitMachine.class
new file mode 100644
index 0000000..bf604c2
Binary files /dev/null and b/common/target/classes/org/example/init/InitMachine.class differ
diff --git a/config/moduleConfig.json b/config/moduleConfig.json
new file mode 100644
index 0000000..776ae56
--- /dev/null
+++ b/config/moduleConfig.json
@@ -0,0 +1,23 @@
+{
+ "account":{
+ "src":"./config/account"
+ },
+ "section":{
+ "src":"./config/section"
+ },
+ "hot":{
+ "src":"./config/hot"
+ },
+ "publish":{
+ "src":"./config/publish"
+ },
+ "creeper":{
+ "src":"./config/creeper"
+ },
+ "barrage":{
+ "src":"./config/barrage"
+ },
+ "videowork":{
+ "src":"./config/videowork"
+ }
+}
\ No newline at end of file
diff --git a/console/pom.xml b/console/pom.xml
index a457dec..cb4a981 100644
--- a/console/pom.xml
+++ b/console/pom.xml
@@ -17,4 +17,22 @@
UTF-8
+
+
+ org.example
+ FileModule
+ 1.0-SNAPSHOT
+
+
+ org.example
+ common
+ 1.0-SNAPSHOT
+
+
+ org.example
+ FileModule
+ 1.0-SNAPSHOT
+
+
+
diff --git a/console/src/main/java/org/example/ConsoleApplication.java b/console/src/main/java/org/example/ConsoleApplication.java
index 217d8c1..44b4e04 100644
--- a/console/src/main/java/org/example/ConsoleApplication.java
+++ b/console/src/main/java/org/example/ConsoleApplication.java
@@ -1,9 +1,13 @@
package org.example;
+import org.example.init.InitWorld;
+import org.example.init.ModuleConfigSrcInit;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import java.util.List;
+
/**
* @author Genius
* @date 2023/04/20 00:16
@@ -13,7 +17,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
public class ConsoleApplication {
public static void main(String[] args) {
- SpringApplication.run(ConsoleApplication.class, args);
+
+ if (InitWorld.getInstance()
+ .setInitMachines(List.of(new ModuleConfigSrcInit()))
+ .start()) {
+ SpringApplication.run(ConsoleApplication.class, args);
+ }
}
}
diff --git a/console/src/main/java/org/example/init/InitWorld.java b/console/src/main/java/org/example/init/InitWorld.java
new file mode 100644
index 0000000..94e1ea9
--- /dev/null
+++ b/console/src/main/java/org/example/init/InitWorld.java
@@ -0,0 +1,47 @@
+package org.example.init;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Genius
+ * @date 2023/04/20 19:36
+ **/
+
+//初始化整个项目,各个模块配置文件
+public class InitWorld {
+
+ private Logger logger = LoggerFactory.getLogger(InitWorld.class);
+ private static volatile InitWorld initWorld = new InitWorld();
+ private List initMachines;
+
+ private InitWorld(){
+ }
+
+ public InitWorld setInitMachines(List initMachines){
+ this.initMachines = initMachines;
+ return this;
+ }
+
+ public static InitWorld getInstance(){
+ return initWorld;
+ }
+
+ public boolean start(){
+ if(initWorld == null){
+ logger.error("已经初始化过了");
+ return true;
+ }
+ for(InitMachine initMachine : initMachines){
+ if(!initMachine.init()){
+ logger.error("{}初始化失败!!", initMachine.getClass().getName());
+ return false;
+ }
+ }
+
+ return true;
+ }
+}
diff --git a/pom.xml b/pom.xml
index 7f3496f..9e11714 100644
--- a/pom.xml
+++ b/pom.xml
@@ -16,6 +16,7 @@
HotModule
PublishModule
console
+ common
pom
@@ -35,6 +36,7 @@
2.3.9.RELEASE
+