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 StringProperty that can be used to override the reported value fromisAndroid().private static final AtomicReference<String> static final StringProperty 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 StringProperty that can be used to override the reported value fromisDalvikMachine().private static final AtomicReference<VersionInfo> static final StringProperty that can be used to override the reported value fromgetJavaVersion().static final Stringprivate static final AtomicReference<String> static final StringProperty that can be used to override the reported value fromisWin32().static final Stringstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetCanonicalUser(String user) RemoveWindowsdomain and/or group prefix as well as "(User);" suffixstatic StringgetComparablePath(String path) static StringGet current user namestatic Pathstatic VersionInfoResolves the reported Java version by consultingJAVA_VERSION_OVERRIDE_PROP.private static StringgetOS()static booleanstatic booleanstatic booleanisOSX()static booleanisUNIX()static booleanisWin32()private static booleanresolveAndroidSettingFlag(AtomicReference<Boolean> flagHolder, String overrideProp, Collection<String> detectionProps, Predicate<? super String> detector) static StringresolveCanonicalGroup(String group, String user) Attempts to resolve canonical group name forWindowsresolveDefaultInteractiveCommandElements(boolean winOS) static Stringstatic StringresolveDefaultInteractiveShellCommand(boolean winOS) static voidsetAndroid(Boolean value) Override the value returned byisAndroid()programmaticallystatic voidsetCurrentUser(String username) Can be used to programmatically set the username reported bygetCurrentUser()static voidsetCurrentWorkingDirectoryResolver(Supplier<? extends Path> cwdProvider) Allows the user to "plug-in" a resolver for thegetCurrentWorkingDirectory()methodstatic voidsetDalvikMachine(Boolean value) Override the value returned byisDalvikMachine()programmaticallystatic voidsetJavaVersion(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_PROPERTIESare 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_PROPERTIESare 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:
trueif currently running on Android. Note:isUNIX()is also probablytrueas 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 ifnullthen value is auto-detected
-
isDalvikMachine
public static boolean isDalvikMachine()- Returns:
trueif currently running on a Dalvik machine. Note:isUNIX()and/orisAndroid()are also probablytrueas 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 ifnullthen 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 beingtrueas 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 - ifnullthen 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
RemoveWindowsdomain and/or group prefix as well as "(User);" suffix- Parameters:
user- The original username - ignored ifnull/empty- Returns:
- The canonical user - unchanged if
UnixO/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 - ifnullthenCURRENT_USER_OVERRIDE_PROPwill 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 - ifnullthen 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
-