Package org.apache.sshd.common.util
Class OsUtils
java.lang.Object
org.apache.sshd.common.util.OsUtils
Operating system dependent utility methods.
-
Field Summary
FieldsModifier and TypeFieldDescriptionSystem properties consulted in order to detectAndroid O/S
.private static final AtomicReference
<Boolean> static final String
Property that can be used to override the reported value fromisAndroid()
.private static final AtomicReference
<String> static final String
Property that can be used to override the reported value fromgetCurrentUser()
.private static final AtomicReference
<Supplier<? extends Path>> System properties consulted in order to detectDalvik machine
.private static final AtomicReference
<Boolean> static final String
Property that can be used to override the reported value fromisDalvikMachine()
.private static final AtomicReference
<VersionInfo> static final String
Property that can be used to override the reported value fromgetJavaVersion()
.static final String
private static final AtomicReference
<String> static final String
Property that can be used to override the reported value fromisWin32()
.static final String
static final String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
getCanonicalUser
(String user) RemoveWindows
domain and/or group prefix as well as "(User);invalid input: '"' suffixstatic String
getComparablePath
(String path) static String
Get current user namestatic Path
static VersionInfo
Resolves the reported Java version by consultingJAVA_VERSION_OVERRIDE_PROP
.private static String
getOS()
static boolean
static boolean
static boolean
isOSX()
static boolean
isUNIX()
static boolean
isWin32()
private static boolean
resolveAndroidSettingFlag
(AtomicReference<Boolean> flagHolder, String overrideProp, Collection<String> detectionProps, Predicate<? super String> detector) static String
resolveCanonicalGroup
(String group, String user) Attempts to resolve canonical group name forWindows
resolveDefaultInteractiveCommandElements
(boolean winOS) static String
static String
resolveDefaultInteractiveShellCommand
(boolean winOS) static void
setAndroid
(Boolean value) Override the value returned byisAndroid()
programmaticallystatic void
setCurrentUser
(String username) Can be used to programmatically set the username reported bygetCurrentUser()
static void
setCurrentWorkingDirectoryResolver
(Supplier<? extends Path> cwdProvider) Allows the user to "plug-in" a resolver for thegetCurrentWorkingDirectory()
methodstatic void
setDalvikMachine
(Boolean value) Override the value returned byisDalvikMachine()
programmaticallystatic void
setJavaVersion
(VersionInfo version) Set programmatically the reported Java versionstatic void
-
Field Details
-
CURRENT_USER_OVERRIDE_PROP
Property that can be used to override the reported value fromgetCurrentUser()
. If not set then "user.name" system property is used- See Also:
-
JAVA_VERSION_OVERRIDE_PROP
Property that can be used to override the reported value fromgetJavaVersion()
. If not set then "java.version" system property is used- See Also:
-
OS_TYPE_OVERRIDE_PROP
Property that can be used to override the reported value fromisWin32()
. If not set then "os.name" system property is used- See Also:
-
ANDROID_MODE_OVERRIDE_PROP
Property that can be used to override the reported value fromisAndroid()
. If not set thenANDROID_DETECTION_PROPERTIES
are used to determine its value. Otherwise, it must contain the string "android" (case-insensitive)- See Also:
-
DALVIK_MACHINE_OVERRIDE_PROP
Property that can be used to override the reported value fromisDalvikMachine()
. If not set thenDALVIK_DETECTION_PROPERTIES
are used to determine its value. Otherwise, it must contain the string "dalvik" (case-insensitive)- See Also:
-
WINDOWS_SHELL_COMMAND_NAME
- See Also:
-
LINUX_SHELL_COMMAND_NAME
- See Also:
-
ROOT_USER
- See Also:
-
LINUX_COMMAND
-
WINDOWS_COMMAND
-
ANDROID_DETECTION_PROPERTIES
System properties consulted in order to detectAndroid O/S
.- See Also:
-
ANDROID_PROPERTY_VALUE_MATCHER
-
DALVIK_DETECTION_PROPERTIES
System properties consulted in order to detectDalvik machine
.- See Also:
-
DALVIK_PROPERTY_VALUE_MATCHER
-
CURRENT_USER_HOLDER
-
JAVA_VERSION_HOLDER
-
OS_TYPE_HOLDER
-
ANDROID_HOLDER
-
DALVIK_HOLDER
-
CWD_PROVIDER_HOLDER
-
-
Constructor Details
-
OsUtils
private OsUtils()
-
-
Method Details
-
isAndroid
public static boolean isAndroid()- Returns:
true
if currently running on Android. Note:isUNIX()
is also probablytrue
as well, so special care must be taken in code that consults these values- See Also:
-
setAndroid
Override the value returned byisAndroid()
programmatically- Parameters:
value
- Value to set ifnull
then value is auto-detected
-
isDalvikMachine
public static boolean isDalvikMachine()- Returns:
true
if currently running on a Dalvik machine. Note:isUNIX()
and/orisAndroid()
are also probablytrue
as well, so special care must be taken in code that consults these values- See Also:
-
setDalvikMachine
Override the value returned byisDalvikMachine()
programmatically- Parameters:
value
- Value to set ifnull
then value is auto-detected
-
isUNIX
public static boolean isUNIX()- Returns:
- true if the host is a UNIX system (and not Windows). Note: this does not preclude
isAndroid()
orisDalvikMachine()
from beingtrue
as well.
-
isOSX
public static boolean isOSX()- Returns:
- true if the host is a OSX (and not Windows or Unix).
-
isWin32
public static boolean isWin32()- Returns:
- true if the host is Windows (and not UNIX).
- See Also:
-
setOS
- Parameters:
os
- The value to set - ifnull
then O/S type is auto-detected- See Also:
-
resolveAndroidSettingFlag
private static boolean resolveAndroidSettingFlag(AtomicReference<Boolean> flagHolder, String overrideProp, Collection<String> detectionProps, Predicate<? super String> detector) -
getOS
- Returns:
- The resolved O/S type string if not already set (lowercase)
-
resolveDefaultInteractiveShellCommand
-
resolveDefaultInteractiveShellCommand
-
resolveDefaultInteractiveCommandElements
-
resolveDefaultInteractiveCommandElements
-
getCurrentWorkingDirectory
-
setCurrentWorkingDirectoryResolver
Allows the user to "plug-in" a resolver for thegetCurrentWorkingDirectory()
method -
getCurrentUser
Get current user name- Returns:
- Current user
- See Also:
-
getCanonicalUser
RemoveWindows
domain and/or group prefix as well as "(User);invalid input: '"' suffix- Parameters:
user
- The original username - ignored ifnull
/empty- Returns:
- The canonical user - unchanged if
Unix
O/S
-
resolveCanonicalGroup
Attempts to resolve canonical group name forWindows
- Parameters:
group
- The original group name - used if notnull
/emptyuser
- The owner name - sometimes it contains a group name- Returns:
- The canonical group name
-
setCurrentUser
Can be used to programmatically set the username reported bygetCurrentUser()
- Parameters:
username
- The username to set - ifnull
thenCURRENT_USER_OVERRIDE_PROP
will be consulted
-
getJavaVersion
Resolves the reported Java version by consultingJAVA_VERSION_OVERRIDE_PROP
. If not set, then "java.version" property is used- Returns:
- The resolved
VersionInfo
- nevernull
- See Also:
-
setJavaVersion
Set programmatically the reported Java version- Parameters:
version
- The version - ifnull
then it will be automatically resolved
-
getComparablePath
- Parameters:
path
- The original path- Returns:
- A path that can be compared with another one where case sensitivity of the underlying O/S has been
taken into account - never
null
-