Package org.apache.sshd.common.util
Class OsUtils
- java.lang.Object
-
- org.apache.sshd.common.util.OsUtils
-
public final class OsUtils extends Object
Operating system dependent utility methods.- Author:
- Apache MINA SSHD Project
-
-
Field Summary
Fields Modifier and Type Field Description static List<String>ANDROID_DETECTION_PROPERTIESSystem properties consulted in order to detectAndroid O/S.static StringANDROID_MODE_OVERRIDE_PROPProperty that can be used to override the reported value fromisAndroid().static Predicate<String>ANDROID_PROPERTY_VALUE_MATCHERstatic StringCURRENT_USER_OVERRIDE_PROPProperty that can be used to override the reported value fromgetCurrentUser().static List<String>DALVIK_DETECTION_PROPERTIESSystem properties consulted in order to detectDalvik machine.static StringDALVIK_MACHINE_OVERRIDE_PROPProperty that can be used to override the reported value fromisDalvikMachine().static Predicate<String>DALVIK_PROPERTY_VALUE_MATCHERstatic StringJAVA_VERSION_OVERRIDE_PROPProperty that can be used to override the reported value fromgetJavaVersion().static List<String>LINUX_COMMANDstatic StringLINUX_SHELL_COMMAND_NAMEstatic StringOS_TYPE_OVERRIDE_PROPProperty that can be used to override the reported value fromisWin32().static StringROOT_USERstatic List<String>WINDOWS_COMMANDstatic StringWINDOWS_SHELL_COMMAND_NAME
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringgetCanonicalUser(String user)RemoveWindowsdomain and/or group prefix as well as "(User);" suffixstatic StringgetComparablePath(String path)static StringgetCurrentUser()Get current user namestatic PathgetCurrentWorkingDirectory()static VersionInfogetJavaVersion()Resolves the reported Java version by consultingJAVA_VERSION_OVERRIDE_PROP.static booleanisAndroid()static booleanisDalvikMachine()static booleanisOSX()static booleanisUNIX()static booleanisWin32()static StringresolveCanonicalGroup(String group, String user)Attempts to resolve canonical group name forWindowsstatic List<String>resolveDefaultInteractiveCommandElements()static List<String>resolveDefaultInteractiveCommandElements(boolean winOS)static StringresolveDefaultInteractiveShellCommand()static 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 voidsetOS(String os)
-
-
-
Field Detail
-
CURRENT_USER_OVERRIDE_PROP
public static final 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 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 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 String 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)
-
DALVIK_MACHINE_OVERRIDE_PROP
public static final String 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:
- Constant Field Values
-
WINDOWS_SHELL_COMMAND_NAME
public static final String WINDOWS_SHELL_COMMAND_NAME
- See Also:
- Constant Field Values
-
LINUX_SHELL_COMMAND_NAME
public static final String LINUX_SHELL_COMMAND_NAME
- See Also:
- Constant Field Values
-
ROOT_USER
public static final String ROOT_USER
- See Also:
- Constant Field Values
-
ANDROID_DETECTION_PROPERTIES
public static final List<String> ANDROID_DETECTION_PROPERTIES
System properties consulted in order to detectAndroid O/S.- See Also:
- Android Developer
-
DALVIK_DETECTION_PROPERTIES
public static final List<String> DALVIK_DETECTION_PROPERTIES
System properties consulted in order to detectDalvik machine.- See Also:
- Android Developer
-
-
Method Detail
-
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:
ANDROID_DETECTION_PROPERTIES,ANDROID_MODE_OVERRIDE_PROP,ANDROID_PROPERTY_VALUE_MATCHER
-
setAndroid
public static void setAndroid(Boolean value)
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:
DALVIK_DETECTION_PROPERTIES,DALVIK_MACHINE_OVERRIDE_PROP,DALVIK_PROPERTY_VALUE_MATCHER
-
setDalvikMachine
public static void setDalvikMachine(Boolean value)
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:
OS_TYPE_OVERRIDE_PROP,setOS(String)
-
setOS
public static void setOS(String os)
-
resolveDefaultInteractiveShellCommand
public static String resolveDefaultInteractiveShellCommand()
-
resolveDefaultInteractiveShellCommand
public static String resolveDefaultInteractiveShellCommand(boolean winOS)
-
resolveDefaultInteractiveCommandElements
public static List<String> resolveDefaultInteractiveCommandElements()
-
resolveDefaultInteractiveCommandElements
public static List<String> resolveDefaultInteractiveCommandElements(boolean winOS)
-
getCurrentWorkingDirectory
public static Path getCurrentWorkingDirectory()
- Returns:
- The (C)urrent (W)orking (D)irectory
Path-nullif 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(Supplier<? extends Path> cwdProvider)
Allows the user to "plug-in" a resolver for thegetCurrentWorkingDirectory()method
-
getCurrentUser
public static String getCurrentUser()
Get current user name- Returns:
- Current user
- See Also:
CURRENT_USER_OVERRIDE_PROP
-
getCanonicalUser
public static String getCanonicalUser(String user)
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
public static String resolveCanonicalGroup(String group, 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(String username)
Can be used to programmatically set the username reported bygetCurrentUser()- Parameters:
username- The username to set - ifnullthenCURRENT_USER_OVERRIDE_PROPwill 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 - ifnullthen it will be automatically resolved
-
-