From e0e8d8e6f64c15abc4b4170535ecc8c5460eb1e6 Mon Sep 17 00:00:00 2001 From: CoolLoong <1542536763@qq.com> Date: Sat, 25 May 2024 21:54:16 +0800 Subject: [PATCH] feat: bump 0.2.3 +b --- pom.xml | 6 +++--- src/main/java/cn/powernukkitx/cli/App.java | 2 -- .../cli/{share => }/CLIConstant.java | 4 ++-- src/main/java/cn/powernukkitx/cli/Main.java | 2 +- .../cn/powernukkitx/cli/cmd/StartCommand.java | 16 +++++----------- .../cli/data/locator/GraalJITLocator.java | 2 +- .../cli/data/locator/GraalModuleLocator.java | 2 +- .../cli/data/locator/JavaLocator.java | 2 +- .../cli/data/locator/LibsLocator.java | 2 +- .../cn/powernukkitx/cli/util/ConfigUtils.java | 9 ++++++++- .../java/cn/powernukkitx/cli/util/OSUtils.java | 2 +- .../cn/powernukkitx/cli/App_zh.properties | 5 ----- .../powernukkitx/cli/Preprocessor_zh.properties | 2 -- .../cn/powernukkitx/cli/cmd/Start_zh.properties | 9 --------- .../cli/cmd/SysInstall_zh.properties | 12 ------------ .../cn/powernukkitx/cli/cmd/Update_zh.properties | 7 ------- .../cn/powernukkitx/cli/util/Http_zh.properties | 6 ------ .../cn/powernukkitx/cli/util/Input_zh.properties | 2 -- 18 files changed, 24 insertions(+), 68 deletions(-) rename src/main/java/cn/powernukkitx/cli/{share => }/CLIConstant.java (82%) delete mode 100644 src/main/resources/cn/powernukkitx/cli/App_zh.properties delete mode 100644 src/main/resources/cn/powernukkitx/cli/Preprocessor_zh.properties delete mode 100644 src/main/resources/cn/powernukkitx/cli/cmd/Start_zh.properties delete mode 100644 src/main/resources/cn/powernukkitx/cli/cmd/SysInstall_zh.properties delete mode 100644 src/main/resources/cn/powernukkitx/cli/cmd/Update_zh.properties delete mode 100644 src/main/resources/cn/powernukkitx/cli/util/Http_zh.properties delete mode 100644 src/main/resources/cn/powernukkitx/cli/util/Input_zh.properties diff --git a/pom.xml b/pom.xml index 0ebc4f2..55683ff 100644 --- a/pom.xml +++ b/pom.xml @@ -6,11 +6,11 @@ cn.powernukkitx PNX-CLI - 0.2.2 + 0.2.3 - 17 - 17 + 21 + 21 UTF-8 UTF-8 diff --git a/src/main/java/cn/powernukkitx/cli/App.java b/src/main/java/cn/powernukkitx/cli/App.java index e0b625e..efc09cc 100644 --- a/src/main/java/cn/powernukkitx/cli/App.java +++ b/src/main/java/cn/powernukkitx/cli/App.java @@ -2,7 +2,6 @@ import cn.powernukkitx.cli.cmd.StartCommand; import cn.powernukkitx.cli.cmd.SysInstallCommand; -import cn.powernukkitx.cli.share.CLIConstant; import cn.powernukkitx.cli.util.*; import picocli.CommandLine; import picocli.CommandLine.Command; @@ -58,7 +57,6 @@ public Integer call() { return 1; } start.generateOnly = false; - start.restart = true; var ret = start.call(); if (ret != 0) { InputUtils.pressEnterToContinue(); diff --git a/src/main/java/cn/powernukkitx/cli/share/CLIConstant.java b/src/main/java/cn/powernukkitx/cli/CLIConstant.java similarity index 82% rename from src/main/java/cn/powernukkitx/cli/share/CLIConstant.java rename to src/main/java/cn/powernukkitx/cli/CLIConstant.java index f95cf00..e68b618 100644 --- a/src/main/java/cn/powernukkitx/cli/share/CLIConstant.java +++ b/src/main/java/cn/powernukkitx/cli/CLIConstant.java @@ -1,4 +1,4 @@ -package cn.powernukkitx.cli.share; +package cn.powernukkitx.cli; import cn.powernukkitx.cli.util.OSUtils; @@ -6,7 +6,7 @@ import java.util.List; public interface CLIConstant { - String version = "0.2.1"; + String version = "0.2.3"; List authors = List.of("超神的冰凉", "CoolLoong"); File userDir = new File(System.getProperty("user.dir")); File programDir = new File(OSUtils.getProgramDir()); diff --git a/src/main/java/cn/powernukkitx/cli/Main.java b/src/main/java/cn/powernukkitx/cli/Main.java index 1c3ad4c..9c41a5a 100644 --- a/src/main/java/cn/powernukkitx/cli/Main.java +++ b/src/main/java/cn/powernukkitx/cli/Main.java @@ -11,7 +11,7 @@ public final class Main { static Timer timer = null; - public static boolean pnxRunning = false; + public static volatile boolean pnxRunning = false; public static void main(String[] args) { AnsiConsole.systemInstall(); diff --git a/src/main/java/cn/powernukkitx/cli/cmd/StartCommand.java b/src/main/java/cn/powernukkitx/cli/cmd/StartCommand.java index 15c3b62..6da0d21 100644 --- a/src/main/java/cn/powernukkitx/cli/cmd/StartCommand.java +++ b/src/main/java/cn/powernukkitx/cli/cmd/StartCommand.java @@ -1,12 +1,12 @@ package cn.powernukkitx.cli.cmd; +import cn.powernukkitx.cli.CLIConstant; import cn.powernukkitx.cli.Main; import cn.powernukkitx.cli.data.builder.JVMStartCommandBuilder; import cn.powernukkitx.cli.data.locator.GraalJITLocator; import cn.powernukkitx.cli.data.locator.GraalModuleLocator; import cn.powernukkitx.cli.data.locator.JarLocator; import cn.powernukkitx.cli.data.locator.JavaLocator; -import cn.powernukkitx.cli.share.CLIConstant; import cn.powernukkitx.cli.util.*; import picocli.CommandLine.Command; import picocli.CommandLine.Option; @@ -43,9 +43,6 @@ public final class StartCommand implements Callable { @Override public Integer call() { var cmdBuilder = new JVMStartCommandBuilder(); - if (args != null && args.length > 0) { - cmdBuilder.setOtherArgs(args); - } var javaList = new JavaLocator("21", true).locate(); if (javaList.isEmpty()) { Logger.error(ansi().fgBrightRed().a(new Formatter().format(bundle.getString("no-java21"), OSUtils.getProgramName())).fgDefault()); @@ -90,7 +87,7 @@ public Integer call() { } catch (IOException e) { throw new RuntimeException(e); } - }else { + } else { Logger.warn(ansi().fgBrightRed().a(new Formatter().format(bundle.getString("no-libs"), OSUtils.getProgramName())).fgDefault()); return 1; } @@ -128,6 +125,9 @@ public Integer call() { for (var module : graalModules) { cmdBuilder.addModulePath(module.getFile().getAbsolutePath()); } + for (var each : ConfigUtils.vmParams()) { + cmdBuilder.addOtherArgs(each); + } for (var each : ConfigUtils.addOpens()) { cmdBuilder.addAddOpen(each); } @@ -194,12 +194,6 @@ private int start() { } var process = builder.start(); Main.pnxRunning = true; - Runtime.getRuntime().addShutdownHook(new Thread(() -> { - if (process.isAlive()) { - process.destroy(); - Main.pnxRunning = false; - } - })); if (useStdinFile) { var stdinFile = new File(CLIConstant.userDir, stdin); if (stdinFile.exists() && stdinFile.isFile() && stdinFile.canRead() && stdinFile.canWrite()) { diff --git a/src/main/java/cn/powernukkitx/cli/data/locator/GraalJITLocator.java b/src/main/java/cn/powernukkitx/cli/data/locator/GraalJITLocator.java index 06ea83a..64f1030 100644 --- a/src/main/java/cn/powernukkitx/cli/data/locator/GraalJITLocator.java +++ b/src/main/java/cn/powernukkitx/cli/data/locator/GraalJITLocator.java @@ -1,6 +1,6 @@ package cn.powernukkitx.cli.data.locator; -import cn.powernukkitx.cli.share.CLIConstant; +import cn.powernukkitx.cli.CLIConstant; import java.io.File; import java.util.Arrays; diff --git a/src/main/java/cn/powernukkitx/cli/data/locator/GraalModuleLocator.java b/src/main/java/cn/powernukkitx/cli/data/locator/GraalModuleLocator.java index f3749b5..177d2e5 100644 --- a/src/main/java/cn/powernukkitx/cli/data/locator/GraalModuleLocator.java +++ b/src/main/java/cn/powernukkitx/cli/data/locator/GraalModuleLocator.java @@ -1,6 +1,6 @@ package cn.powernukkitx.cli.data.locator; -import cn.powernukkitx.cli.share.CLIConstant; +import cn.powernukkitx.cli.CLIConstant; import java.io.File; import java.util.Arrays; diff --git a/src/main/java/cn/powernukkitx/cli/data/locator/JavaLocator.java b/src/main/java/cn/powernukkitx/cli/data/locator/JavaLocator.java index 3992a53..d44ef33 100644 --- a/src/main/java/cn/powernukkitx/cli/data/locator/JavaLocator.java +++ b/src/main/java/cn/powernukkitx/cli/data/locator/JavaLocator.java @@ -1,6 +1,6 @@ package cn.powernukkitx.cli.data.locator; -import cn.powernukkitx.cli.share.CLIConstant; +import cn.powernukkitx.cli.CLIConstant; import cn.powernukkitx.cli.util.CollectionUtils; import cn.powernukkitx.cli.util.ConfigUtils; import cn.powernukkitx.cli.util.StringUtils; diff --git a/src/main/java/cn/powernukkitx/cli/data/locator/LibsLocator.java b/src/main/java/cn/powernukkitx/cli/data/locator/LibsLocator.java index ac97ef6..23de603 100644 --- a/src/main/java/cn/powernukkitx/cli/data/locator/LibsLocator.java +++ b/src/main/java/cn/powernukkitx/cli/data/locator/LibsLocator.java @@ -1,7 +1,7 @@ package cn.powernukkitx.cli.data.locator; +import cn.powernukkitx.cli.CLIConstant; import cn.powernukkitx.cli.data.remote.VersionListHelper; -import cn.powernukkitx.cli.share.CLIConstant; import java.io.File; import java.io.IOException; diff --git a/src/main/java/cn/powernukkitx/cli/util/ConfigUtils.java b/src/main/java/cn/powernukkitx/cli/util/ConfigUtils.java index 681d1f0..c00a261 100644 --- a/src/main/java/cn/powernukkitx/cli/util/ConfigUtils.java +++ b/src/main/java/cn/powernukkitx/cli/util/ConfigUtils.java @@ -1,6 +1,7 @@ package cn.powernukkitx.cli.util; -import cn.powernukkitx.cli.share.CLIConstant; +import cn.powernukkitx.cli.CLIConstant; +import cn.powernukkitx.cli.Main; import com.sun.management.OperatingSystemMXBean; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -21,6 +22,7 @@ public final class ConfigUtils { public static void init() { parseConfigFile(globalConfigFile); Runtime.getRuntime().addShutdownHook(new Thread(() -> { + Main.pnxRunning = false; if (hasChanged.get()) { try (var writer = new BufferedWriter(new FileWriter(globalConfigFile))) { INIParser.writeINI(configMap, writer); @@ -127,6 +129,11 @@ public static String maxVMMemory() { } } + public static String[] vmParams() { + return Arrays.stream(configMap.getOrDefault("vmParams", "").split(" ")) + .filter(e -> !e.isBlank()).distinct().toArray(String[]::new); + } + public static String[] addOpens() { return Arrays.stream(configMap.getOrDefault("add-opens", "").split(" ")) .filter(e -> !e.isBlank()).distinct().toArray(String[]::new); diff --git a/src/main/java/cn/powernukkitx/cli/util/OSUtils.java b/src/main/java/cn/powernukkitx/cli/util/OSUtils.java index 917eccc..efb8d17 100644 --- a/src/main/java/cn/powernukkitx/cli/util/OSUtils.java +++ b/src/main/java/cn/powernukkitx/cli/util/OSUtils.java @@ -1,6 +1,6 @@ package cn.powernukkitx.cli.util; -import cn.powernukkitx.cli.share.CLIConstant; +import cn.powernukkitx.cli.CLIConstant; import java.io.*; import java.nio.charset.Charset; diff --git a/src/main/resources/cn/powernukkitx/cli/App_zh.properties b/src/main/resources/cn/powernukkitx/cli/App_zh.properties deleted file mode 100644 index 91fb2b2..0000000 --- a/src/main/resources/cn/powernukkitx/cli/App_zh.properties +++ /dev/null @@ -1,5 +0,0 @@ -lang = \u9009\u62E9\u6267\u884C\u6B64\u6B21\u547D\u4EE4\u6240\u7528\u7684\u8BED\u8A00\u4EE3\u7801\u3002 -args = \u82E5\u8981\u4F7F\u7528\u81EA\u5B9A\u4E49\u53C2\u6570\u542F\u52A8PNX\uFF0C\u0020\u8BF7\u4F7F\u7528`%1s start YOUR_ARGS`\u547D\u4EE4\u3002 -config-path = \u6307\u5B9A\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84\uFF08\u9ED8\u8BA4\u4E3Apnx-cli-config.ini\uFF09 -invalid-file = \u627E\u4E0D\u5230\u6216\u6CA1\u6709\u914D\u7F6E\u6587\u4EF6 %1s \u7684IO\u6743\u9650 -update=\u662F\u5426\u68C0\u67E5PNX-CLI\u66F4\u65B0\u3002 \ No newline at end of file diff --git a/src/main/resources/cn/powernukkitx/cli/Preprocessor_zh.properties b/src/main/resources/cn/powernukkitx/cli/Preprocessor_zh.properties deleted file mode 100644 index 3786116..0000000 --- a/src/main/resources/cn/powernukkitx/cli/Preprocessor_zh.properties +++ /dev/null @@ -1,2 +0,0 @@ -lang = \u9009\u62E9\u6267\u884C\u6B64\u6B21\u547D\u4EE4\u6240\u7528\u7684\u8BED\u8A00\u4EE3\u7801\u3002 -update=\u662F\u5426\u68C0\u67E5PNX-CLI\u66F4\u65B0\u3002 \ No newline at end of file diff --git a/src/main/resources/cn/powernukkitx/cli/cmd/Start_zh.properties b/src/main/resources/cn/powernukkitx/cli/cmd/Start_zh.properties deleted file mode 100644 index 4c085d5..0000000 --- a/src/main/resources/cn/powernukkitx/cli/cmd/Start_zh.properties +++ /dev/null @@ -1,9 +0,0 @@ -usage.description = \u751f\u6210\u542f\u52a8\u547d\u4ee4\u5e76\u542f\u52a8\u0050\u004e\u0058\u670d\u52a1\u5668\u3002 -generate-only = \u4ec5\u751f\u6210\u542f\u52a8\u547d\u4ee4\uff0c\u5e76\u4e0d\u542f\u52a8\u0050\u004e\u0058\u670d\u52a1\u5668\u3002 -no-java21=\u627e\u4e0d\u5230\u004a\u0044\u004b\u0032\u0031\u002c\u65e0\u6cd5\u542f\u52a8\u0050\u004e\u0058\u002e -using-jvm=\u4f7f\u7528\u7684\u004a\u0056\u004d\uff1a%1s -no-pnx=\u627e\u4e0d\u5230\u0050\u004e\u0058\u0020\u0063\u006f\u0072\u0065\uff0c\u8bf7\u624b\u52a8\u4e0b\u8f7d\u0060\u0050\u006f\u0077\u0065\u0072\u004e\u0075\u006b\u006b\u0069\u0074\u0058\u002d\u0043\u006f\u0072\u0065\u0060\u0020\u4ece\u0068\u0074\u0074\u0070\u0073\u003a\u002f\u002f\u0067\u0069\u0074\u0068\u0075\u0062\u002e\u0063\u006f\u006d\u002f\u0050\u006f\u0077\u0065\u0072\u004e\u0075\u006b\u006b\u0069\u0074\u0058\u002f\u0050\u006f\u0077\u0065\u0072\u004e\u0075\u006b\u006b\u0069\u0074\u0058\u002f\u0061\u0063\u0074\u0069\u006f\u006e\u0073 -using-pnx=\u4f7f\u7528\u7684\u0050\u004e\u0058\u6838\u5fc3\uff1a%1s -restart = \u5982\u679c\u0070\u006e\u0078\u670d\u52a1\u5668\u5d29\u6e83\uff0c\u5219\u81ea\u52a8\u91cd\u65b0\u542f\u52a8\u3002 -stdin=\u4ece\u6307\u5b9a\u6587\u4ef6\u4e2d\u8bfb\u53d6\u63a7\u5236\u53f0\u8f93\u5165 -no-libs=\u627e\u4e0d\u5230\u0050\u004e\u0058\u0020\u006c\u0069\u0062\u0073\uff0c\u8bf7\u624b\u52a8\u4e0b\u8f7d\u0060\u0050\u006f\u0077\u0065\u0072\u004e\u0075\u006b\u006b\u0069\u0074\u0058\u002d\u004c\u0069\u0062\u0073\u0060\u0020\u4ece\u0068\u0074\u0074\u0070\u0073\u003a\u002f\u002f\u0067\u0069\u0074\u0068\u0075\u0062\u002e\u0063\u006f\u006d\u002f\u0050\u006f\u0077\u0065\u0072\u004e\u0075\u006b\u006b\u0069\u0074\u0058\u002f\u0050\u006f\u0077\u0065\u0072\u004e\u0075\u006b\u006b\u0069\u0074\u0058\u002f\u0061\u0063\u0074\u0069\u006f\u006e\u0073 diff --git a/src/main/resources/cn/powernukkitx/cli/cmd/SysInstall_zh.properties b/src/main/resources/cn/powernukkitx/cli/cmd/SysInstall_zh.properties deleted file mode 100644 index 9c02a1f..0000000 --- a/src/main/resources/cn/powernukkitx/cli/cmd/SysInstall_zh.properties +++ /dev/null @@ -1,12 +0,0 @@ -usage.description = \u5728\u7cfb\u7edf\u8def\u5f84\u4e2d\u5b89\u88c5\u6216\u5378\u8f7d\u0050\u004e\u0058\u3002 -executable-only = \u4f60\u53ea\u80fd\u5728\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\u5c06\u0070\u006e\u0078\u5b89\u88c5\u5230\u7cfb\u7edf\u8def\u5f84\u3002 -unsupportedOS = \u5728\u0025\u0031\u0073\u7cfb\u7edf\u4e0a\u6682\u4e0d\u652f\u6301\u5b89\u88c5\u5230\u7cfb\u7edf\u8def\u5f84\u3002 -already = \u0050\u004e\u0058\u002d\u0043\u004c\u0049\u5df2\u7ecf\u6210\u529f\u5730\u5b89\u88c5\u5230\u4e86\u7cfb\u7edf\u8def\u5f84\u4e2d\u3002 -windows-cmd = \u91cd\u542f\u0063\u006d\u0064\u6216\u0070\u006f\u0077\u0065\u0072\u0073\u0068\u0065\u006c\u006c\u4ee5\u5b8c\u6210\u5b89\u88c5\u6216\u5378\u8f7d\u3002 -have-not = \u4f60\u8fd8\u6ca1\u6709\u5b89\u88c5\u0050\u004e\u0058\u002d\u0043\u004c\u0049\u5230\u7cfb\u7edf\u8def\u5f84\u4e2d\uff01 -success = \u6210\u529f\u5c06\u5b89\u88c5\u0050\u004e\u0058\u002d\u0043\u004c\u0049\u5230\u7cfb\u7edf\u8def\u5f84\u4e2d\u3002 -success-uninstall = \u6210\u529f\u4ece\u7cfb\u7edf\u8def\u5f84\u4e2d\u79fb\u9664\u0050\u004e\u0058\u002d\u0043\u004c\u0049\u3002 -fail = \u5728\u7cfb\u7edf\u8def\u5f84\u4e2d\u5b89\u88c5\u0050\u004e\u0058\u002d\u0043\u004c\u0049\u5931\u8d25\u3002 -fail-uninstall = \u5728\u7cfb\u7edf\u8def\u5f84\u4e2d\u79fb\u9664\u0050\u004e\u0058\u002d\u0043\u004c\u0049\u5931\u8d25\u3002 -uninstall = \u4ece\u7cfb\u7edf\u8def\u5f84\u4e2d\u79fb\u9664\u0050\u004e\u0058\u002d\u0043\u004c\u0049\u3002 -linux-cmd = \u91cd\u542f\u7ec8\u7aef\u6216\u4f7f\u7528\u547d\u4ee4`source %1s`\u5b8c\u6210\u5b89\u88c5\u6216\u5378\u8f7d\u3002 \ No newline at end of file diff --git a/src/main/resources/cn/powernukkitx/cli/cmd/Update_zh.properties b/src/main/resources/cn/powernukkitx/cli/cmd/Update_zh.properties deleted file mode 100644 index 113a0df..0000000 --- a/src/main/resources/cn/powernukkitx/cli/cmd/Update_zh.properties +++ /dev/null @@ -1,7 +0,0 @@ -available-version=\u53EF\u7528\u7248\u672C\uFF1A -invalid-index=\u7D22\u5F15\u8D85\u51FA\u8303\u56F4\uFF01\u8BF7\u8F93\u5165\u4E00\u4E2A\u4ECB\u4E8E1\u548C%1s\u4E4B\u95F4\u7684\u7D22\u5F15\u3002 -choose-version=\u9009\u62e9\u4f60\u60f3\u5b89\u88c5\u7684\u7248\u672c\u003a -update-core=\u66f4\u65b0\u0050\u004e\u0058\u7684\u6838\u5fc3\u002e -update-libs=\u66f4\u65b0\u0050\u004e\u0058\u7684\u4f9d\u8d56\u5e93\u002e -update-all=\u66f4\u65b0\u0050\u004e\u0058\u7684\u4f9d\u8d56\u5e93\u548c\u6838\u5fc3\u002e -update-latest=\u81ea\u52a8\u4e3a\u60a8\u9009\u62e9\u6700\u65b0\u7248\u002e \ No newline at end of file diff --git a/src/main/resources/cn/powernukkitx/cli/util/Http_zh.properties b/src/main/resources/cn/powernukkitx/cli/util/Http_zh.properties deleted file mode 100644 index afb3b07..0000000 --- a/src/main/resources/cn/powernukkitx/cli/util/Http_zh.properties +++ /dev/null @@ -1,6 +0,0 @@ -detecting=\u6B63\u5728\u68C0\u6D4B\u5230PNX\u670D\u52A1\u5668\u5404\u7AEF\u70B9\u7684\u7F51\u7EDC\u60C5\u51B5... -connecting = \u6B63\u5728\u8FDE\u63A5 %1s ... -using-source=\u6B63\u5728\u4F7F\u7528 %1s \u7AEF\u70B9\u3002 -selected-source-lag=\u5DF2\u9009\u62E9 %1s \u7AEF\u70B9\uFF0C\u5EF6\u8FDF %2d ms\u3002 -success = \u6210\u529F\u4E0B\u8F7D %1s\uFF01 -fail = \u4E0B\u8F7D %1s \u5931\u8D25\u3002 \ No newline at end of file diff --git a/src/main/resources/cn/powernukkitx/cli/util/Input_zh.properties b/src/main/resources/cn/powernukkitx/cli/util/Input_zh.properties deleted file mode 100644 index 202275b..0000000 --- a/src/main/resources/cn/powernukkitx/cli/util/Input_zh.properties +++ /dev/null @@ -1,2 +0,0 @@ -press-enter-to-continue = \u6309\u56de\u8f66\u952e\u7ee7\u7eed... -press-enter-to-stop-with-time-limit = \u8bf7\u5728\u0031\u0030\u0073\u5185\u952e\u5165\u56de\u8f66\u4ee5\u505c\u6b62\u91cd\u542f... \ No newline at end of file