Class OsUtils

java.lang.Object
org.apache.sshd.common.util.OsUtils

public final class OsUtils extends Object
Operating system dependent utility methods.
  • Field Details

  • Constructor Details

    • OsUtils

      private OsUtils()
  • Method Details

    • isAndroid

      public static boolean isAndroid()
      Returns:
      true if currently running on Android. Note: isUNIX() is also probably true as well, so special care must be taken in code that consults these values
      See Also:
    • setAndroid

      public static void setAndroid(Boolean value)
      Override the value returned by isAndroid() programmatically
      Parameters:
      value - Value to set if null then value is auto-detected
    • isDalvikMachine

      public static boolean isDalvikMachine()
      Returns:
      true if currently running on a Dalvik machine. Note: isUNIX() and/or isAndroid() are also probably true as well, so special care must be taken in code that consults these values
      See Also:
    • setDalvikMachine

      public static void setDalvikMachine(Boolean value)
      Override the value returned by isDalvikMachine() programmatically
      Parameters:
      value - Value to set if null 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() or isDalvikMachine() from being true 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:
    • 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:
    • resolveAndroidSettingFlag

      private static boolean resolveAndroidSettingFlag(AtomicReference<Boolean> flagHolder, String overrideProp, Collection<String> detectionProps, Predicate<? super String> detector)
    • getOS

      private static String getOS()
      Returns:
      The resolved O/S type string if not already set (lowercase)
    • 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 - 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.
      See Also:
    • setCurrentWorkingDirectoryResolver

      public static void setCurrentWorkingDirectoryResolver(Supplier<? extends Path> cwdProvider)
      Allows the user to "plug-in" a resolver for the getCurrentWorkingDirectory() method
      Parameters:
      cwdProvider - The Supplier of the (C)urrent (W)orking (D)irectory Path - if null then "user.dir" system property is consulted
    • 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);invalid input: '&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