From 564b364382d3f15804a80027cdf0c729c25e00e6 Mon Sep 17 00:00:00 2001 From: "jiashuaizhang@126.com" Date: Sun, 19 Dec 2021 21:48:18 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=86=E8=8A=82=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yyetshistory/YyetsHistoryApplication.java | 4 +--- .../yyetshistory/util/NativeConfigUtil.java | 6 +++--- .../yyetshistory/util/NativeOperationUtils.java | 10 ++++------ yyets-history/src/main/resources/application.yml | 2 +- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/YyetsHistoryApplication.java b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/YyetsHistoryApplication.java index 1f83c47..93e0347 100644 --- a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/YyetsHistoryApplication.java +++ b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/YyetsHistoryApplication.java @@ -3,8 +3,6 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import java.util.concurrent.atomic.AtomicBoolean; - import static com.zhangjiashuai.yyetshistory.util.NativeOperationUtils.onStartFinish; import static com.zhangjiashuai.yyetshistory.util.NativeOperationUtils.onStartPrepare; @@ -14,7 +12,7 @@ public class YyetsHistoryApplication { public static void main(String[] args) { onStartPrepare(args); SpringApplication.run(YyetsHistoryApplication.class, args); - onStartFinish(args); + onStartFinish(); } } diff --git a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/util/NativeConfigUtil.java b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/util/NativeConfigUtil.java index 4cd0b60..116f172 100644 --- a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/util/NativeConfigUtil.java +++ b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/util/NativeConfigUtil.java @@ -142,13 +142,13 @@ static boolean isStartPrepareEvent(String[] args) { return eventCheck(key, args); } - static boolean isStartFinishEvent(String[] args) { + static boolean isStartFinishEvent() { String key = "yyets-history.start-finish-event"; Object configValue = getProperty(key); if(configValue != null) { return Boolean.parseBoolean(configValue.toString()); } - return eventCheck(key, args); + return true; } private static boolean eventCheck(String key, String[] args) { @@ -157,7 +157,7 @@ private static boolean eventCheck(String key, String[] args) { for (String arg : args) { if(StrUtil.startWith(arg, COMMAND_LINE_ARG_PREFIX + key)) { Pair pair = getCommandLineArg(arg); - strValue = pair.getValue(); + strValue = Optional.ofNullable(pair).map(Pair::getValue).orElse(null); break; } } diff --git a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/util/NativeOperationUtils.java b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/util/NativeOperationUtils.java index d74ef1f..381ae9a 100644 --- a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/util/NativeOperationUtils.java +++ b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/util/NativeOperationUtils.java @@ -47,7 +47,6 @@ private static void buildUri(String host, int port) { */ public static void onStartPrepare(String[] args) { String classLoader = NativeOperationUtils.class.getClassLoader().getClass().getSimpleName(); - log.debug("onStartPrepare, classloader {}", classLoader); if(classLoader.endsWith("RestartClassLoader")) { return; } @@ -58,15 +57,15 @@ public static void onStartPrepare(String[] args) { NativeConfigUtil.loadCommandLineArgs(args); String host = NativeConfigUtil.getHost(); int port = NativeConfigUtil.getPort(); - buildUri(host, port); if(!telnet(host, port)) { return; } log.info("探测到项目访问路径上有服务运行"); + buildUri(host, port); Pair processInfo = getRunningProcessInfo(); if (APPLICATION_INFO.equals(processInfo.getKey())) { log.info("服务已在另一进程运行,pid: {}", processInfo.getValue()); - onStartFinish(args); + onStartFinish(); } else { openErrorDialog ("端口冲突","当前地址: " + uri + " 已被占用"); } @@ -75,10 +74,9 @@ public static void onStartPrepare(String[] args) { /** * 启动成功触发事件 - * @param uri 项目访问地址 */ - public static void onStartFinish(String[] args) { - if(!NativeConfigUtil.isStartFinishEvent(args)) { + public static void onStartFinish() { + if(!NativeConfigUtil.isStartFinishEvent()) { return; } if(uri == null) { diff --git a/yyets-history/src/main/resources/application.yml b/yyets-history/src/main/resources/application.yml index d62e33e..292d66c 100644 --- a/yyets-history/src/main/resources/application.yml +++ b/yyets-history/src/main/resources/application.yml @@ -21,7 +21,7 @@ pagehelper: server: port: 9000 yyets-history: - link-way-filter: #保留的链接类型 + link-way-filter: # 保留的链接类型 - 电驴 - 磁力 host: localhost # 域名