Skip to content

Commit

Permalink
Rename isRunningInCI(), improve isCISetToTrue().
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Jan 13, 2025
1 parent 9f1dd7e commit b09f511
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private static List<String> determineMemoryUsageFlags(Function<Double, String> t

String memoryUsageReason = "unknown";
final boolean isDedicatedMemoryUsage;
if (SubstrateUtil.isCISet()) {
if (SubstrateUtil.isCISetToTrue()) {
isDedicatedMemoryUsage = true;
memoryUsageReason = "$CI set to 'true'";
} else if (isContainerized()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> imageBuilderArgs) {
if (isDumbTerm() || SubstrateUtil.isRunningInCI()) {
if (isDumbTerm() || SubstrateUtil.isNonInteractiveTerminal()) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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, "-");
}
Expand Down

0 comments on commit b09f511

Please sign in to comment.