From 20447ddef86295f3bf986d8d81d76fb5fc56e360 Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Tue, 11 Jun 2024 16:12:05 -0400 Subject: [PATCH] refactor --- .../com/commonwealthrobotics/JvmManager.java | 62 ++++++++++--------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/lib/src/main/java/com/commonwealthrobotics/JvmManager.java b/lib/src/main/java/com/commonwealthrobotics/JvmManager.java index bf7d8d9..3cfb13c 100644 --- a/lib/src/main/java/com/commonwealthrobotics/JvmManager.java +++ b/lib/src/main/java/com/commonwealthrobotics/JvmManager.java @@ -59,28 +59,7 @@ public static String getCommandString(String project, String repo, String versio HashMap database = gson.fromJson(jsonText, TT_mapStringString); String key = "UNKNOWN"; - if (LatestFromGithubLaunchUI.isLin()) { - if (LatestFromGithubLaunchUI.isArm()) { - key = "Linux-aarch64"; - } else { - key = "Linux-x64"; - } - } - - if (LatestFromGithubLaunchUI.isMac()) { - if (LatestFromGithubLaunchUI.isArm()) { - key = "Mac-aarch64"; - } else { - key = "Mac-x64"; - } - } - if (LatestFromGithubLaunchUI.isWin()) { - if (LatestFromGithubLaunchUI.isArm()) { - key = "UNKNOWN"; - } else { - key = "Windows-x64"; - } - } + key = discoverKey(key); Map vm = (Map) database.get(key); String baseURL = vm.get("url").toString(); String type = vm.get("type").toString(); @@ -111,12 +90,39 @@ public static String getCommandString(String project, String repo, String versio return cmd + " -jar "; } - public static boolean isExecutable(ZipArchiveEntry entry) { - int unixMode = entry.getUnixMode(); - // Check if any of the executable bits are set for user, group, or others. - // User executable: 0100 (0x40), Group executable: 0010 (0x10), Others executable: 0001 (0x01) - return (unixMode & 0x49) != 0; - } + private static String discoverKey(String key) { + if (LatestFromGithubLaunchUI.isLin()) { + if (LatestFromGithubLaunchUI.isArm()) { + key = "Linux-aarch64"; + } else { + key = "Linux-x64"; + } + } + + if (LatestFromGithubLaunchUI.isMac()) { + if (LatestFromGithubLaunchUI.isArm()) { + key = "Mac-aarch64"; + } else { + key = "Mac-x64"; + } + } + if (LatestFromGithubLaunchUI.isWin()) { + if (LatestFromGithubLaunchUI.isArm()) { + key = "UNKNOWN"; + } else { + key = "Windows-x64"; + } + } + return key; + } + + public static boolean isExecutable(ZipArchiveEntry entry) { + int unixMode = entry.getUnixMode(); + // Check if any of the executable bits are set for user, group, or others. + // User executable: 0100 (0x40), Group executable: 0010 (0x10), Others + // executable: 0001 (0x01) + return (unixMode & 0x49) != 0; + } private static void unzip(File path, String dir) throws Exception { String fileBaseName = FilenameUtils.getBaseName(path.getName().toString()); Path destFolderPath = new File(dir).toPath();