From b09f51180ea57feadd9ca553433508f5bd650736 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Mon, 13 Jan 2025 14:42:21 +0100 Subject: [PATCH] Rename isRunningInCI(), improve isCISetToTrue(). --- .../com/oracle/svm/core/SubstrateUtil.java | 26 +++++++++---------- .../src/com/oracle/svm/driver/MemoryUtil.java | 2 +- .../com/oracle/svm/driver/NativeImage.java | 4 +-- .../oracle/svm/hosted/ProgressReporter.java | 3 +-- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateUtil.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateUtil.java index 0bdbb2744b49..513897f69ff7 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateUtil.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateUtil.java @@ -82,17 +82,17 @@ public class SubstrateUtil { public static String getArchitectureName() { String arch = System.getProperty("os.arch"); - switch (arch) { - case "x86_64": - arch = "amd64"; - break; - case "arm64": - arch = "aarch64"; - break; - } - return arch; + return switch (arch) { + case "x86_64" -> "amd64"; + case "arm64" -> "aarch64"; + default -> arch; + }; } + /* + * [GR-55515]: Accessing isTerminal() reflectively only for 21 JDK compatibility. After dropping + * JDK 21, use it directly. + */ private static final Method IS_TERMINAL_METHOD = ReflectionUtil.lookupMethod(true, Console.class, "isTerminal"); private static boolean isTTY() { @@ -111,12 +111,12 @@ private static boolean isTTY() { } } - public static boolean isRunningInCI() { - return !isTTY() || isCISet(); + public static boolean isNonInteractiveTerminal() { + return isCISetToTrue() || !isTTY(); } - public static boolean isCISet() { - return "true".equals(System.getenv("CI")); + public static boolean isCISetToTrue() { + return Boolean.parseBoolean(System.getenv("CI")); } /** diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/MemoryUtil.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/MemoryUtil.java index 85843ceb7be7..7e84bfc1bedc 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/MemoryUtil.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/MemoryUtil.java @@ -128,7 +128,7 @@ private static List determineMemoryUsageFlags(Function t String memoryUsageReason = "unknown"; final boolean isDedicatedMemoryUsage; - if (SubstrateUtil.isCISet()) { + if (SubstrateUtil.isCISetToTrue()) { isDedicatedMemoryUsage = true; memoryUsageReason = "$CI set to 'true'"; } else if (isContainerized()) { diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java index 78b4eabe4a24..0abe93bbf52b 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java @@ -2504,12 +2504,12 @@ private static boolean isDumbTerm() { } private static boolean hasColorSupport() { - return !isDumbTerm() && !SubstrateUtil.isRunningInCI() && OS.getCurrent() != OS.WINDOWS && + return !isDumbTerm() && !SubstrateUtil.isNonInteractiveTerminal() && OS.getCurrent() != OS.WINDOWS && System.getenv("NO_COLOR") == null /* https://no-color.org/ */; } private static boolean hasProgressSupport(List imageBuilderArgs) { - if (isDumbTerm() || SubstrateUtil.isRunningInCI()) { + if (isDumbTerm() || SubstrateUtil.isNonInteractiveTerminal()) { return false; } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java index 8edd0c8c8f33..9355e699419d 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java @@ -107,7 +107,6 @@ import jdk.graal.compiler.util.json.JsonWriter; public class ProgressReporter implements FeatureSingleton, UnsavedSingleton { - private static final boolean IS_CI = SubstrateUtil.isRunningInCI(); private static final int CHARACTERS_PER_LINE; private static final String HEADLINE_SEPARATOR; private static final String LINE_SEPARATOR; @@ -169,7 +168,7 @@ private enum BuildStage { } static { - CHARACTERS_PER_LINE = IS_CI ? ProgressReporterCHelper.MAX_CHARACTERS_PER_LINE : ProgressReporterCHelper.getTerminalWindowColumnsClamped(); + CHARACTERS_PER_LINE = SubstrateUtil.isNonInteractiveTerminal() ? ProgressReporterCHelper.MAX_CHARACTERS_PER_LINE : ProgressReporterCHelper.getTerminalWindowColumnsClamped(); HEADLINE_SEPARATOR = Utils.stringFilledWith(CHARACTERS_PER_LINE, "="); LINE_SEPARATOR = Utils.stringFilledWith(CHARACTERS_PER_LINE, "-"); }