Package org.apache.sshd.common.util
Class OsUtils
- java.lang.Object
-
- org.apache.sshd.common.util.OsUtils
-
public final class OsUtils extends java.lang.ObjectOperating system dependent utility methods.
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.List<java.lang.String>ANDROID_DETECTION_PROPERTIESSystem properties consulted in order to detectAndroid O/S.private static java.util.concurrent.atomic.AtomicReference<java.lang.Boolean>ANDROID_HOLDERstatic java.lang.StringANDROID_MODE_OVERRIDE_PROPProperty that can be used to override the reported value fromisAndroid().static java.util.function.Predicate<java.lang.String>ANDROID_PROPERTY_VALUE_MATCHERprivate static java.util.concurrent.atomic.AtomicReference<java.lang.String>CURRENT_USER_HOLDERstatic java.lang.StringCURRENT_USER_OVERRIDE_PROPProperty 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_HOLDERstatic java.util.List<java.lang.String>DALVIK_DETECTION_PROPERTIESSystem properties consulted in order to detectDalvik machine.private static java.util.concurrent.atomic.AtomicReference<java.lang.Boolean>DALVIK_HOLDERstatic java.lang.StringDALVIK_MACHINE_OVERRIDE_PROPProperty that can be used to override the reported value fromisDalvikMachine().static java.util.function.Predicate<java.lang.String>DALVIK_PROPERTY_VALUE_MATCHERprivate static java.util.concurrent.atomic.AtomicReference<VersionInfo>JAVA_VERSION_HOLDERstatic java.lang.StringJAVA_VERSION_OVERRIDE_PROPProperty that can be used to override the reported value fromgetJavaVersion().static java.util.List<java.lang.String>LINUX_COMMANDstatic java.lang.StringLINUX_SHELL_COMMAND_NAMEprivate static java.util.concurrent.atomic.AtomicReference<java.lang.String>OS_TYPE_HOLDERstatic java.lang.StringOS_TYPE_OVERRIDE_PROPProperty that can be used to override the reported value fromisWin32().static java.lang.StringROOT_USERstatic java.util.List<java.lang.String>WINDOWS_COMMANDstatic java.lang.StringWINDOWS_SHELL_COMMAND_NAME
-
Constructor Summary
Constructors Modifier Constructor Description privateOsUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringgetCanonicalUser(java.lang.String user)RemoveWindowsdomain and/or group prefix as well as "(User)" suffixstatic java.lang.StringgetComparablePath(java.lang.String path)static java.lang.StringgetCurrentUser()Get current user namestatic java.nio.file.PathgetCurrentWorkingDirectory()static VersionInfogetJavaVersion()Resolves the reported Java version by consultingJAVA_VERSION_OVERRIDE_PROP.private static java.lang.StringgetOS()static booleanisAndroid()static booleanisDalvikMachine()static booleanisOSX()static booleanisUNIX()static booleanisWin32()private static booleanresolveAndroidSettingFlag(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.StringresolveCanonicalGroup(java.lang.String group, java.lang.String user)Attempts to resolve canonical group name forWindowsstatic java.util.List<java.lang.String>resolveDefaultInteractiveCommandElements()static java.util.List<java.lang.String>resolveDefaultInteractiveCommandElements(boolean winOS)static java.lang.StringresolveDefaultInteractiveShellCommand()static java.lang.StringresolveDefaultInteractiveShellCommand(boolean winOS)static voidsetAndroid(java.lang.Boolean value)Override the value returned byisAndroid()programmaticallystatic voidsetCurrentUser(java.lang.String username)Can be used to programmatically set the username reported bygetCurrentUser()static voidsetCurrentWorkingDirectoryResolver(java.util.function.Supplier<? extends java.nio.file.Path> cwdProvider)Allows the user to "plug-in" a resolver for thegetCurrentWorkingDirectory()methodstatic voidsetDalvikMachine(java.lang.Boolean value)Override the value returned byisDalvikMachine()programmaticallystatic voidsetJavaVersion(VersionInfo version)Set programmatically the reported Java versionstatic voidsetOS(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_PROPERTIESare 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_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 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:
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(java.lang.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(java.lang.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(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-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(java.util.function.Supplier<? extends java.nio.file.Path> cwdProvider)
Allows the user to "plug-in" a resolver for thegetCurrentWorkingDirectory()method- Parameters:
cwdProvider- TheSupplierof the (C)urrent (W)orking (D)irectoryPath- ifnullthen "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)
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 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 - 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
-
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
-
-