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 Details

    • CURRENT_USER_OVERRIDE_PROP

      public static final String CURRENT_USER_OVERRIDE_PROP
      Property that can be used to override the reported value from getCurrentUser(). If not set then "user.name" system property is used
      See Also:
    • JAVA_VERSION_OVERRIDE_PROP

      public static final String JAVA_VERSION_OVERRIDE_PROP
      Property that can be used to override the reported value from getJavaVersion(). If not set then "java.version" system property is used
      See Also:
    • OS_TYPE_OVERRIDE_PROP

      public static final String OS_TYPE_OVERRIDE_PROP
      Property that can be used to override the reported value from isWin32(). If not set then "os.name" system property is used
      See Also:
    • WINDOWS_SHELL_COMMAND_NAME

      public static final String WINDOWS_SHELL_COMMAND_NAME
      See Also:
    • LINUX_SHELL_COMMAND_NAME

      public static final String LINUX_SHELL_COMMAND_NAME
      See Also:
    • ROOT_USER

      public static final String ROOT_USER
      See Also:
    • LINUX_COMMAND

      public static final List<String> LINUX_COMMAND
    • WINDOWS_COMMAND

      public static final List<String> WINDOWS_COMMAND
  • Method Details

    • isUNIX

      public static boolean isUNIX()
      Returns:
      true if the host is a UNIX system (and not Windows).
    • 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

      public static void setOS(String os)
      Can be used to enforce Win32 or Linux report from isWin32(), isOSX() or isUNIX()
      Parameters:
      os - The value to set - if null then O/S type is auto-detected
      See Also:
    • 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)
    • getCurrentUser

      public static String getCurrentUser()
      Get current user name
      Returns:
      Current user
      See Also:
    • getCanonicalUser

      public static String getCanonicalUser(String user)
      Remove Windows domain and/or group prefix as well as "(User);&quot suffix
      Parameters:
      user - The original username - ignored if null/empty
      Returns:
      The canonical user - unchanged if Unix O/S
    • resolveCanonicalGroup

      public static String resolveCanonicalGroup(String group, String user)
      Attempts to resolve canonical group name for Windows
      Parameters:
      group - The original group name - used if not null/empty
      user - 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 by getCurrentUser()
      Parameters:
      username - The username to set - if null then CURRENT_USER_OVERRIDE_PROP will be consulted
    • getJavaVersion

      public static VersionInfo getJavaVersion()
      Resolves the reported Java version by consulting JAVA_VERSION_OVERRIDE_PROP. If not set, then "java.version" property is used
      Returns:
      The resolved VersionInfo - never null
      See Also:
    • setJavaVersion

      public static void setJavaVersion(VersionInfo version)
      Set programmatically the reported Java version
      Parameters:
      version - The version - if null then it will be automatically resolved
    • getComparablePath

      public static String getComparablePath(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