Skip to content
Snippets Groups Projects
Commit e37afe48 authored by Simon Barner's avatar Simon Barner
Browse files

Implement cache for is*() predicates


- Methods can be used in UI to implement OS-specific workarounds
- Better avoid extensive querying of system properties and environment

Issue-Ref: 2443
Signed-off-by: default avatarSimon Barner <barner@fortiss.org>
parent 5227aeb9
No related branches found
No related tags found
1 merge request!32443 os architecture case distinctions
...@@ -13,6 +13,6 @@ PointUtils.java b21c92cc8e80ece9d87ede8a750f4de314379743 GREEN ...@@ -13,6 +13,6 @@ PointUtils.java b21c92cc8e80ece9d87ede8a750f4de314379743 GREEN
PointsUtils.java bad69811c59004948929f6a57edd5a79c0bf8643 GREEN PointsUtils.java bad69811c59004948929f6a57edd5a79c0bf8643 GREEN
RectangleLayoutUtils.java cdd61d162761da7f3e1d3512264135b9b0d564ff GREEN RectangleLayoutUtils.java cdd61d162761da7f3e1d3512264135b9b0d564ff GREEN
SnapToGridUtils.java 413785d7a8655db31a129b6f821e1d5f859aa726 GREEN SnapToGridUtils.java 413785d7a8655db31a129b6f821e1d5f859aa726 GREEN
SystemUtils.java bd40519b5e286f274f47815ccc8d320fd65c2c0a YELLOW SystemUtils.java 622dd176fa0febc1e92845cb0f988e503cc30efb YELLOW
VisualizationModelElementFactory.java 18e67450ee4cf4a03dc88a10becb0fb6ce4c1bad GREEN VisualizationModelElementFactory.java 18e67450ee4cf4a03dc88a10becb0fb6ce4c1bad GREEN
ZoomUtils.java a339613fde18281bed3b55b529a053d348545bc7 GREEN ZoomUtils.java a339613fde18281bed3b55b529a053d348545bc7 GREEN
...@@ -26,37 +26,71 @@ import static java.util.UUID.randomUUID; ...@@ -26,37 +26,71 @@ import static java.util.UUID.randomUUID;
*/ */
public class SystemUtils { public class SystemUtils {
/** Cache for {@link #isWindowsPlatform()}. */
private static Boolean isWindowsPlatform = null;
/** Cache for {@link #isLinuxPlatform()}. */
private static Boolean isLinuxPlatform = null;
/** Cache for {@link #isMacOSXPlatform()}. */
private static Boolean isMacOSXPlatform = null;
/** Cache for {@link #isVm64BitArch()}. */
private static Boolean isVm64BitArch;
/** Cache for {@link #isOs64BitArch()}. */
private static Boolean isOs64BitArch;
/** Predicate if the current platform is Windows. */ /** Predicate if the current platform is Windows. */
public static boolean isWindowsPlatform() { public static boolean isWindowsPlatform() {
if(isWindowsPlatform != null) {
return isWindowsPlatform;
}
String osName = System.getProperty("os.name"); String osName = System.getProperty("os.name");
return osName != null && osName.contains("Windows"); isWindowsPlatform = osName != null && osName.contains("Windows");
return isWindowsPlatform;
} }
/** Predicate if the current platform is Linux. */ /** Predicate if the current platform is Linux. */
public static boolean isLinuxPlatform() { public static boolean isLinuxPlatform() {
if(isLinuxPlatform != null) {
return isLinuxPlatform;
}
String osName = System.getProperty("os.name"); String osName = System.getProperty("os.name");
return osName != null && osName.contains("Linux"); isLinuxPlatform = osName != null && osName.contains("Linux");
return isLinuxPlatform;
} }
/** Predicate if the current platform is Mac OS X. */ /** Predicate if the current platform is Mac OS X. */
public static boolean isMacOSXPlatform() { public static boolean isMacOSXPlatform() {
if(isMacOSXPlatform != null) {
return isMacOSXPlatform;
}
String osName = System.getProperty("os.name"); String osName = System.getProperty("os.name");
return osName != null && osName.contains("Mac OS X."); isMacOSXPlatform = osName != null && osName.contains("Mac OS X.");
return isMacOSXPlatform;
} }
/** Predicate if the current <b>Java VM</b> architecture is 64 bit. */ /** Predicate if the current <b>Java VM</b> architecture is 64 bit. */
public static boolean isVm64BitArch() { public static boolean isVm64BitArch() {
if(isVm64BitArch != null) {
return isVm64BitArch;
}
String osArch = System.getProperty("os.arch"); String osArch = System.getProperty("os.arch");
return osArch != null && osArch.contains("64"); isVm64BitArch = osArch != null && osArch.contains("64");
return isVm64BitArch;
} }
/** Predicate if the current <b>OS</b> architecture is 64 bit. */ /** Predicate if the current <b>OS</b> architecture is 64 bit. */
public static boolean isOs64BitArch() { public static boolean isOs64BitArch() {
if(isWindowsPlatform()) { if(isOs64BitArch != null) {
return System.getenv("ProgramFiles(x86)") != null; return isOs64BitArch;
} }
return isVm64BitArch(); String progFilesX86 = System.getenv("ProgramFiles(x86)");
isOs64BitArch = isWindowsPlatform() ? progFilesX86 != null : isVm64BitArch();
return isOs64BitArch;
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment