public final class OsUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static List<String> |
ANDROID_DETECTION_PROPERTIES
System properties consulted in order to detect
Android O/S. |
static String |
ANDROID_MODE_OVERRIDE_PROP
Property that can be used to override the reported value from
isAndroid(). |
static Predicate<String> |
ANDROID_PROPERTY_VALUE_MATCHER |
static String |
CURRENT_USER_OVERRIDE_PROP
Property that can be used to override the reported value from
getCurrentUser(). |
static List<String> |
DALVIK_DETECTION_PROPERTIES
System properties consulted in order to detect
Dalvik machine. |
static String |
DALVIK_MACHINE_OVERRIDE_PROP
Property that can be used to override the reported value from
isDalvikMachine(). |
static Predicate<String> |
DALVIK_PROPERTY_VALUE_MATCHER |
static String |
JAVA_VERSION_OVERRIDE_PROP
Property that can be used to override the reported value from
getJavaVersion(). |
static List<String> |
LINUX_COMMAND |
static String |
LINUX_SHELL_COMMAND_NAME |
static String |
OS_TYPE_OVERRIDE_PROP
Property that can be used to override the reported value from
isWin32(). |
static String |
ROOT_USER |
static List<String> |
WINDOWS_COMMAND |
static String |
WINDOWS_SHELL_COMMAND_NAME |
| Modifier and Type | Method and Description |
|---|---|
static String |
getCanonicalUser(String user)
Remove
Windows domain and/or group prefix as well as "(User);" suffix |
static String |
getComparablePath(String path) |
static String |
getCurrentUser()
Get current user name
|
static Path |
getCurrentWorkingDirectory() |
static VersionInfo |
getJavaVersion()
Resolves the reported Java version by consulting
JAVA_VERSION_OVERRIDE_PROP. |
static boolean |
isAndroid() |
static boolean |
isDalvikMachine() |
static boolean |
isOSX() |
static boolean |
isUNIX() |
static boolean |
isWin32() |
static String |
resolveCanonicalGroup(String group,
String user)
Attempts to resolve canonical group name for
Windows |
static List<String> |
resolveDefaultInteractiveCommandElements() |
static List<String> |
resolveDefaultInteractiveCommandElements(boolean winOS) |
static String |
resolveDefaultInteractiveShellCommand() |
static String |
resolveDefaultInteractiveShellCommand(boolean winOS) |
static void |
setAndroid(Boolean value)
Override the value returned by
isAndroid() programmatically |
static void |
setCurrentUser(String username)
Can be used to programmatically set the username reported by
getCurrentUser() |
static void |
setCurrentWorkingDirectoryResolver(Supplier<? extends Path> cwdProvider)
Allows the user to "plug-in" a resolver for the
getCurrentWorkingDirectory() method |
static void |
setDalvikMachine(Boolean value)
Override the value returned by
isDalvikMachine() programmatically |
static void |
setJavaVersion(VersionInfo version)
Set programmatically the reported Java version
|
static void |
setOS(String os)
|
public static final String CURRENT_USER_OVERRIDE_PROP
getCurrentUser(). If not set then
"user.name" system property is usedpublic static final String JAVA_VERSION_OVERRIDE_PROP
getJavaVersion(). If not set then
"java.version" system property is usedpublic static final String OS_TYPE_OVERRIDE_PROP
isWin32(). If not set then
"os.name" system property is usedpublic static final String ANDROID_MODE_OVERRIDE_PROP
isAndroid(). If not set then
ANDROID_DETECTION_PROPERTIES are used to determine its value. Otherwise, it must contain the string
"android" (case-insensitive)public static final String DALVIK_MACHINE_OVERRIDE_PROP
isDalvikMachine(). If not set then
DALVIK_DETECTION_PROPERTIES are used to determine its value. Otherwise, it must contain the string
"dalvik" (case-insensitive)public static final String WINDOWS_SHELL_COMMAND_NAME
public static final String LINUX_SHELL_COMMAND_NAME
public static final String ROOT_USER
public static final List<String> ANDROID_DETECTION_PROPERTIES
Android O/S.public static final List<String> DALVIK_DETECTION_PROPERTIES
Dalvik machine.public static boolean isAndroid()
true if currently running on Android. Note: isUNIX() is also probably
true as well, so special care must be taken in code that consults these valuesANDROID_DETECTION_PROPERTIES,
ANDROID_MODE_OVERRIDE_PROP,
ANDROID_PROPERTY_VALUE_MATCHERpublic static void setAndroid(Boolean value)
isAndroid() programmaticallyvalue - Value to set if null then value is auto-detectedpublic static boolean isDalvikMachine()
true if currently running on a Dalvik machine. Note: isUNIX() and/or
isAndroid() are also probably true as well, so special care must be taken in code that
consults these valuesDALVIK_DETECTION_PROPERTIES,
DALVIK_MACHINE_OVERRIDE_PROP,
DALVIK_PROPERTY_VALUE_MATCHERpublic static void setDalvikMachine(Boolean value)
isDalvikMachine() programmaticallyvalue - Value to set if null then value is auto-detectedpublic static boolean isUNIX()
isAndroid() or isDalvikMachine() from being true as well.public static boolean isOSX()
public static boolean isWin32()
OS_TYPE_OVERRIDE_PROP,
setOS(String)public static void setOS(String os)
public static String resolveDefaultInteractiveShellCommand()
public static String resolveDefaultInteractiveShellCommand(boolean winOS)
public static List<String> resolveDefaultInteractiveCommandElements()
public static List<String> resolveDefaultInteractiveCommandElements(boolean winOS)
public static Path getCurrentWorkingDirectory()
Path - null if cannot resolve it. Resolution occurs
as follows:
resolver.setCurrentWorkingDirectoryResolver(Supplier)public static void setCurrentWorkingDirectoryResolver(Supplier<? extends Path> cwdProvider)
getCurrentWorkingDirectory() methodpublic static String getCurrentUser()
CURRENT_USER_OVERRIDE_PROPpublic static String getCanonicalUser(String user)
Windows domain and/or group prefix as well as "(User);" suffixuser - The original username - ignored if null/emptyUnix O/Spublic static String resolveCanonicalGroup(String group, String user)
Windowsgroup - The original group name - used if not null/emptyuser - The owner name - sometimes it contains a group namepublic static void setCurrentUser(String username)
getCurrentUser()username - The username to set - if null then CURRENT_USER_OVERRIDE_PROP will be consultedpublic static VersionInfo getJavaVersion()
JAVA_VERSION_OVERRIDE_PROP. If not set, then
"java.version" property is usedVersionInfo - never nullsetJavaVersion(VersionInfo)public static void setJavaVersion(VersionInfo version)
version - The version - if null then it will be automatically resolvedCopyright © 2018–2024 The Apache Software Foundation. All rights reserved.