Package org.apache.sshd.common.util
Class OsUtils
- java.lang.Object
-
- org.apache.sshd.common.util.OsUtils
-
public final class OsUtils extends java.lang.Object
Operating system dependent utility methods.
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.List<java.lang.String>
ANDROID_DETECTION_PROPERTIES
System properties consulted in order to detectAndroid O/S
.private static java.util.concurrent.atomic.AtomicReference<java.lang.Boolean>
ANDROID_HOLDER
static java.lang.String
ANDROID_MODE_OVERRIDE_PROP
Property that can be used to override the reported value fromisAndroid()
.static java.util.function.Predicate<java.lang.String>
ANDROID_PROPERTY_VALUE_MATCHER
private static java.util.concurrent.atomic.AtomicReference<java.lang.String>
CURRENT_USER_HOLDER
static java.lang.String
CURRENT_USER_OVERRIDE_PROP
Property that can be used to override the reported value fromgetCurrentUser()
.private static java.util.concurrent.atomic.AtomicReference<java.util.function.Supplier<? extends java.nio.file.Path>>
CWD_PROVIDER_HOLDER
static java.util.List<java.lang.String>
DALVIK_DETECTION_PROPERTIES
System properties consulted in order to detectDalvik machine
.private static java.util.concurrent.atomic.AtomicReference<java.lang.Boolean>
DALVIK_HOLDER
static java.lang.String
DALVIK_MACHINE_OVERRIDE_PROP
Property that can be used to override the reported value fromisDalvikMachine()
.static java.util.function.Predicate<java.lang.String>
DALVIK_PROPERTY_VALUE_MATCHER
private static java.util.concurrent.atomic.AtomicReference<VersionInfo>
JAVA_VERSION_HOLDER
static java.lang.String
JAVA_VERSION_OVERRIDE_PROP
Property that can be used to override the reported value fromgetJavaVersion()
.static java.util.List<java.lang.String>
LINUX_COMMAND
static java.lang.String
LINUX_SHELL_COMMAND_NAME
private static java.util.concurrent.atomic.AtomicReference<java.lang.String>
OS_TYPE_HOLDER
static java.lang.String
OS_TYPE_OVERRIDE_PROP
Property that can be used to override the reported value fromisWin32()
.static java.lang.String
ROOT_USER
static java.util.List<java.lang.String>
WINDOWS_COMMAND
static java.lang.String
WINDOWS_SHELL_COMMAND_NAME
-
Constructor Summary
Constructors Modifier Constructor Description private
OsUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
getCanonicalUser(java.lang.String user)
RemoveWindows
domain and/or group prefix as well as "(User);" suffixstatic java.lang.String
getComparablePath(java.lang.String path)
static java.lang.String
getCurrentUser()
Get current user namestatic java.nio.file.Path
getCurrentWorkingDirectory()
static VersionInfo
getJavaVersion()
Resolves the reported Java version by consultingJAVA_VERSION_OVERRIDE_PROP
.private static java.lang.String
getOS()
static boolean
isAndroid()
static boolean
isDalvikMachine()
static boolean
isOSX()
static boolean
isUNIX()
static boolean
isWin32()
private static boolean
resolveAndroidSettingFlag(java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> flagHolder, java.lang.String overrideProp, java.util.Collection<java.lang.String> detectionProps, java.util.function.Predicate<? super java.lang.String> detector)
static java.lang.String
resolveCanonicalGroup(java.lang.String group, java.lang.String user)
Attempts to resolve canonical group name forWindows
static java.util.List<java.lang.String>
resolveDefaultInteractiveCommandElements()
static java.util.List<java.lang.String>
resolveDefaultInteractiveCommandElements(boolean winOS)
static java.lang.String
resolveDefaultInteractiveShellCommand()
static java.lang.String
resolveDefaultInteractiveShellCommand(boolean winOS)
static void
setAndroid(java.lang.Boolean value)
Override the value returned byisAndroid()
programmaticallystatic void
setCurrentUser(java.lang.String username)
Can be used to programmatically set the username reported bygetCurrentUser()
static void
setCurrentWorkingDirectoryResolver(java.util.function.Supplier<? extends java.nio.file.Path> cwdProvider)
Allows the user to "plug-in" a resolver for thegetCurrentWorkingDirectory()
methodstatic void
setDalvikMachine(java.lang.Boolean value)
Override the value returned byisDalvikMachine()
programmaticallystatic void
setJavaVersion(VersionInfo version)
Set programmatically the reported Java versionstatic void
setOS(java.lang.String os)
-
-
-
Field Detail
-
CURRENT_USER_OVERRIDE_PROP
public static final java.lang.String 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:
- Constant Field Values
-
JAVA_VERSION_OVERRIDE_PROP
public static final java.lang.String 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:
- Constant Field Values
-
OS_TYPE_OVERRIDE_PROP
public static final java.lang.String 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:
- Constant Field Values
-
ANDROID_MODE_OVERRIDE_PROP
public static final java.lang.String 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)
-
DALVIK_MACHINE_OVERRIDE_PROP
public static final java.lang.String 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:
- Constant Field Values
-
WINDOWS_SHELL_COMMAND_NAME
public static final java.lang.String WINDOWS_SHELL_COMMAND_NAME
- See Also:
- Constant Field Values
-
LINUX_SHELL_COMMAND_NAME
public static final java.lang.String LINUX_SHELL_COMMAND_NAME
- See Also:
- Constant Field Values
-
ROOT_USER
public static final java.lang.String ROOT_USER
- See Also:
- Constant Field Values
-
LINUX_COMMAND
public static final java.util.List<java.lang.String> LINUX_COMMAND
-
WINDOWS_COMMAND
public static final java.util.List<java.lang.String> WINDOWS_COMMAND
-
ANDROID_DETECTION_PROPERTIES
public static final java.util.List<java.lang.String> ANDROID_DETECTION_PROPERTIES
System properties consulted in order to detectAndroid O/S
.- See Also:
- Android Developer
-
ANDROID_PROPERTY_VALUE_MATCHER
public static final java.util.function.Predicate<java.lang.String> ANDROID_PROPERTY_VALUE_MATCHER
-
DALVIK_DETECTION_PROPERTIES
public static final java.util.List<java.lang.String> DALVIK_DETECTION_PROPERTIES
System properties consulted in order to detectDalvik machine
.- See Also:
- Android Developer
-
DALVIK_PROPERTY_VALUE_MATCHER
public static final java.util.function.Predicate<java.lang.String> DALVIK_PROPERTY_VALUE_MATCHER
-
CURRENT_USER_HOLDER
private static final java.util.concurrent.atomic.AtomicReference<java.lang.String> CURRENT_USER_HOLDER
-
JAVA_VERSION_HOLDER
private static final java.util.concurrent.atomic.AtomicReference<VersionInfo> JAVA_VERSION_HOLDER
-
OS_TYPE_HOLDER
private static final java.util.concurrent.atomic.AtomicReference<java.lang.String> OS_TYPE_HOLDER
-
ANDROID_HOLDER
private static final java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> ANDROID_HOLDER
-
DALVIK_HOLDER
private static final java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> DALVIK_HOLDER
-
CWD_PROVIDER_HOLDER
private static final java.util.concurrent.atomic.AtomicReference<java.util.function.Supplier<? extends java.nio.file.Path>> CWD_PROVIDER_HOLDER
-
-
Method Detail
-
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:
ANDROID_DETECTION_PROPERTIES
,ANDROID_MODE_OVERRIDE_PROP
,ANDROID_PROPERTY_VALUE_MATCHER
-
setAndroid
public static void setAndroid(java.lang.Boolean value)
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:
DALVIK_DETECTION_PROPERTIES
,DALVIK_MACHINE_OVERRIDE_PROP
,DALVIK_PROPERTY_VALUE_MATCHER
-
setDalvikMachine
public static void setDalvikMachine(java.lang.Boolean value)
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:
OS_TYPE_OVERRIDE_PROP
,setOS(String)
-
setOS
public static void setOS(java.lang.String os)
-
resolveAndroidSettingFlag
private static boolean resolveAndroidSettingFlag(java.util.concurrent.atomic.AtomicReference<java.lang.Boolean> flagHolder, java.lang.String overrideProp, java.util.Collection<java.lang.String> detectionProps, java.util.function.Predicate<? super java.lang.String> detector)
-
getOS
private static java.lang.String getOS()
- Returns:
- The resolved O/S type string if not already set (lowercase)
-
resolveDefaultInteractiveShellCommand
public static java.lang.String resolveDefaultInteractiveShellCommand()
-
resolveDefaultInteractiveShellCommand
public static java.lang.String resolveDefaultInteractiveShellCommand(boolean winOS)
-
resolveDefaultInteractiveCommandElements
public static java.util.List<java.lang.String> resolveDefaultInteractiveCommandElements()
-
resolveDefaultInteractiveCommandElements
public static java.util.List<java.lang.String> resolveDefaultInteractiveCommandElements(boolean winOS)
-
getCurrentWorkingDirectory
public static java.nio.file.Path getCurrentWorkingDirectory()
- Returns:
- The (C)urrent (W)orking (D)irectory
Path
-null
if cannot resolve it. Resolution occurs as follows:- Consult any currently registered
resolver
. - If no resolver registered, then "user.dir" system property is consulted.
- Consult any currently registered
- See Also:
setCurrentWorkingDirectoryResolver(Supplier)
-
setCurrentWorkingDirectoryResolver
public static void setCurrentWorkingDirectoryResolver(java.util.function.Supplier<? extends java.nio.file.Path> cwdProvider)
Allows the user to "plug-in" a resolver for thegetCurrentWorkingDirectory()
method- Parameters:
cwdProvider
- TheSupplier
of the (C)urrent (W)orking (D)irectoryPath
- ifnull
then "user.dir" system property is consulted
-
getCurrentUser
public static java.lang.String getCurrentUser()
Get current user name- Returns:
- Current user
- See Also:
CURRENT_USER_OVERRIDE_PROP
-
getCanonicalUser
public static java.lang.String getCanonicalUser(java.lang.String user)
RemoveWindows
domain and/or group prefix as well as "(User);" suffix- Parameters:
user
- The original username - ignored ifnull
/empty- Returns:
- The canonical user - unchanged if
Unix
O/S
-
resolveCanonicalGroup
public static java.lang.String resolveCanonicalGroup(java.lang.String group, java.lang.String user)
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
public static void setCurrentUser(java.lang.String username)
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
public static VersionInfo 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(VersionInfo)
-
setJavaVersion
public static void setJavaVersion(VersionInfo version)
Set programmatically the reported Java version- Parameters:
version
- The version - ifnull
then it will be automatically resolved
-
getComparablePath
public static java.lang.String getComparablePath(java.lang.String path)
- 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
-
-