Utils: Use enum for caching of operating system too.

This commit is contained in:
Andreas Schildbach 2019-01-02 16:37:47 +01:00
parent cdbf9ecc9f
commit 74b642844d

View file

@ -554,7 +554,12 @@ public class Utils {
ANDROID, OPENJDK, ORACLE_JAVA ANDROID, OPENJDK, ORACLE_JAVA
} }
private enum OS {
LINUX, WINDOWS, MAC_OS
}
private static Runtime runtime = null; private static Runtime runtime = null;
private static OS os = null;
static { static {
String runtimeProp = System.getProperty("java.runtime.name").toLowerCase(Locale.US); String runtimeProp = System.getProperty("java.runtime.name").toLowerCase(Locale.US);
if (runtimeProp == null) if (runtimeProp == null)
@ -567,6 +572,18 @@ public class Utils {
runtime = Runtime.ORACLE_JAVA; runtime = Runtime.ORACLE_JAVA;
else else
log.info("Unknown java.runtime.name '{}'", runtimeProp); log.info("Unknown java.runtime.name '{}'", runtimeProp);
String osProp = System.getProperty("os.name").toLowerCase(Locale.US);
if (osProp == null)
os = null;
else if (osProp.contains("linux"))
os = OS.LINUX;
else if (osProp.contains("win"))
os = OS.WINDOWS;
else if (osProp.contains("mac"))
os = OS.MAC_OS;
else
log.info("Unknown os.name '{}'", runtimeProp);
} }
public static boolean isAndroidRuntime() { public static boolean isAndroidRuntime() {
@ -582,14 +599,14 @@ public class Utils {
} }
public static boolean isLinux() { public static boolean isLinux() {
return System.getProperty("os.name").toLowerCase().contains("linux"); return os == OS.LINUX;
} }
public static boolean isWindows() { public static boolean isWindows() {
return System.getProperty("os.name").toLowerCase().contains("win"); return os == OS.WINDOWS;
} }
public static boolean isMac() { public static boolean isMac() {
return System.getProperty("os.name").toLowerCase().contains("mac"); return os == OS.MAC_OS;
} }
} }