From 1dc6e95340af0350f96f21b9e1f811f2409beb41 Mon Sep 17 00:00:00 2001 From: octopus_yan Date: Fri, 15 Nov 2024 22:33:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=89=93=E5=8C=85?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- pom.xml | 45 +++++++++++++++---- .../octopusyan/dmt/common/config/Context.java | 8 +++- .../java/cn/octopusyan/dmt/utils/PBOUtil.java | 16 +++++-- src/main/java/module-info.java | 1 + 5 files changed, 59 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 447ce98..a0b4643 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ ``` 2. 运行 ```bash - mvn clean javafx:run + mvn clean javafx:run -Pdev ``` #### 打包 @@ -64,7 +64,7 @@ ``` 2. 运行 ```bash - mvn clean package + mvn clean package -Pbuild ``` ### 可能会用到 diff --git a/pom.xml b/pom.xml index 322445c..0d34ca3 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ cn.octopusyan dmt - 0.0.2 + 0.1.2 dmt @@ -172,14 +172,41 @@ - - - - src/main/resources - true - - + + + dev + + -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 + + + + + src/main/resources + true + + + + + + build + + + + + + + src/main/resources + true + + bin/ + + + + + + + org.apache.maven.plugins @@ -233,7 +260,7 @@ - + diff --git a/src/main/java/cn/octopusyan/dmt/common/config/Context.java b/src/main/java/cn/octopusyan/dmt/common/config/Context.java index 8874323..4f17279 100644 --- a/src/main/java/cn/octopusyan/dmt/common/config/Context.java +++ b/src/main/java/cn/octopusyan/dmt/common/config/Context.java @@ -16,6 +16,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; +import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; import java.net.URL; import java.util.HashMap; import java.util.Map; @@ -39,11 +41,15 @@ public class Context { @Getter private static final Map> controllers = new HashMap<>(); - private Context() { throw new IllegalStateException("Utility class"); } + public static boolean isDebugMode() { + RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); + return runtimeMXBean.getInputArguments().toString().contains("-agentlib:jdwp"); + } + // 获取控制工厂 public static Callback, Object> getControlFactory() { return type -> { diff --git a/src/main/java/cn/octopusyan/dmt/utils/PBOUtil.java b/src/main/java/cn/octopusyan/dmt/utils/PBOUtil.java index a283305..86d556d 100644 --- a/src/main/java/cn/octopusyan/dmt/utils/PBOUtil.java +++ b/src/main/java/cn/octopusyan/dmt/utils/PBOUtil.java @@ -1,12 +1,15 @@ package cn.octopusyan.dmt.utils; import cn.octopusyan.dmt.common.config.Constants; +import cn.octopusyan.dmt.common.config.Context; import cn.octopusyan.dmt.common.util.ProcessesUtil; import cn.octopusyan.dmt.model.WordItem; import cn.octopusyan.dmt.view.ConsoleLog; import org.apache.commons.io.FileUtils; import org.apache.commons.io.LineIterator; import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; @@ -24,6 +27,7 @@ import java.util.stream.Collectors; * @author octopus_yan */ public class PBOUtil { + private static final Logger log = LoggerFactory.getLogger(PBOUtil.class); public static final ConsoleLog consoleLog = ConsoleLog.getInstance(PBOUtil.class); private static final ProcessesUtil processesUtil = ProcessesUtil.init(Constants.BIN_DIR_PATH); @@ -42,14 +46,20 @@ public class PBOUtil { public static void init() { - - String srcFilePath = Objects.requireNonNull(PBOUtil.class.getResource("/bin")).getPath(); try { File destDir = new File(Constants.BIN_DIR_PATH); + + if (destDir.exists()) return; + + if (!Context.isDebugMode()) + throw new RuntimeException("Util 初始化失败"); + + String srcFilePath = Resources.getResource("bin").getPath(); FileUtils.forceMkdir(destDir); FileUtils.copyDirectory(new File(srcFilePath), destDir); + } catch (IOException e) { - consoleLog.error("Util 初始化失败", e); + log.error("Util 初始化失败", e); } } diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 8369d15..ece8532 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -17,6 +17,7 @@ module cn.octopusyan.dmt { requires java.prefs; requires org.kordamp.ikonli.javafx; requires org.kordamp.ikonli.feather; + requires java.management; exports cn.octopusyan.dmt; exports cn.octopusyan.dmt.model to com.fasterxml.jackson.databind;