Class Os


  • public class Os
    extends java.lang.Object

    NOTE: This class was copied from plexus-utils, to allow this library to stand completely self-contained.

    Condition that tests the OS type.

    Since:
    1.0
    • Constructor Summary

      Constructors 
      Constructor Description
      Os()
      Default constructor
      Os​(java.lang.String family)
      Constructor that sets the family attribute
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean eval()
      Determines if the current OS matches the type of that set in setFamily.
      private static java.lang.String getOsFamily()
      Helper method to determine the current OS family.
      static java.util.Set<java.lang.String> getValidFamilies()  
      static boolean isArch​(java.lang.String arch)
      Determines if the current OS matches the given OS architecture.
      static boolean isFamily​(java.lang.String family)
      Determines if the current OS matches the given OS family.
      static boolean isName​(java.lang.String name)
      Determines if the current OS matches the given OS name.
      static boolean isOs​(java.lang.String family, java.lang.String name, java.lang.String arch, java.lang.String version)
      Determines if the current OS matches the given OS family, name, architecture and version.
      static boolean isValidFamily​(java.lang.String theFamily)
      Helper method to check if the given family is in the following list: dos mac netware os/2 tandem unix windows win9x z/os os/400 openvms
      static boolean isVersion​(java.lang.String version)
      Determines if the current OS matches the given OS version.
      void setArch​(java.lang.String arch)
      Sets the desired OS architecture
      void setFamily​(java.lang.String f)
      Sets the desired OS family type
      void setName​(java.lang.String name)
      Sets the desired OS name
      private static java.util.Set<java.lang.String> setValidFamilies()
      Initializes the set of valid families.
      void setVersion​(java.lang.String version)
      Sets the desired OS version
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • validFamilies

        private static final java.util.Set<java.lang.String> validFamilies
      • PATH_SEP

        private static final java.lang.String PATH_SEP
      • OS_NAME

        public static final java.lang.String OS_NAME
      • OS_ARCH

        public static final java.lang.String OS_ARCH
      • OS_VERSION

        public static final java.lang.String OS_VERSION
      • OS_FAMILY

        public static final java.lang.String OS_FAMILY
      • family

        private java.lang.String family
      • name

        private java.lang.String name
      • version

        private java.lang.String version
      • arch

        private java.lang.String arch
    • Constructor Detail

      • Os

        public Os()
        Default constructor
      • Os

        public Os​(java.lang.String family)
        Constructor that sets the family attribute
        Parameters:
        family - a String value
    • Method Detail

      • setValidFamilies

        private static java.util.Set<java.lang.String> setValidFamilies()
        Initializes the set of valid families.
      • setFamily

        public void setFamily​(java.lang.String f)
        Sets the desired OS family type
        Parameters:
        f - The OS family type desired Possible values:
        • dos
        • mac
        • netware
        • os/2
        • tandem
        • unix
        • windows
        • win9x
        • z/os
        • os/400
        • openvms
      • setName

        public void setName​(java.lang.String name)
        Sets the desired OS name
        Parameters:
        name - The OS name
      • setArch

        public void setArch​(java.lang.String arch)
        Sets the desired OS architecture
        Parameters:
        arch - The OS architecture
      • setVersion

        public void setVersion​(java.lang.String version)
        Sets the desired OS version
        Parameters:
        version - The OS version
      • eval

        public boolean eval()
                     throws java.lang.Exception
        Determines if the current OS matches the type of that set in setFamily.
        Returns:
        true/false.
        Throws:
        java.lang.Exception - in case of an error.
        See Also:
        setFamily(String)
      • isFamily

        public static boolean isFamily​(java.lang.String family)
        Determines if the current OS matches the given OS family.
        Parameters:
        family - the family to check for
        Returns:
        true if the OS matches
        Since:
        1.0
      • isName

        public static boolean isName​(java.lang.String name)
        Determines if the current OS matches the given OS name.
        Parameters:
        name - the OS name to check for
        Returns:
        true if the OS matches
        Since:
        1.0
      • isArch

        public static boolean isArch​(java.lang.String arch)
        Determines if the current OS matches the given OS architecture.
        Parameters:
        arch - the OS architecture to check for
        Returns:
        true if the OS matches
        Since:
        1.0
      • isVersion

        public static boolean isVersion​(java.lang.String version)
        Determines if the current OS matches the given OS version.
        Parameters:
        version - the OS version to check for
        Returns:
        true if the OS matches
        Since:
        1.0
      • isOs

        public static boolean isOs​(java.lang.String family,
                                   java.lang.String name,
                                   java.lang.String arch,
                                   java.lang.String version)
        Determines if the current OS matches the given OS family, name, architecture and version. The name, archictecture and version are compared to the System properties os.name, os.version and os.arch in a case-independent way.
        Parameters:
        family - The OS family
        name - The OS name
        arch - The OS architecture
        version - The OS version
        Returns:
        true if the OS matches
        Since:
        1.0
      • getOsFamily

        private static java.lang.String getOsFamily()
        Helper method to determine the current OS family.
        Returns:
        name of current OS family.
        Since:
        1.4.2
      • isValidFamily

        public static boolean isValidFamily​(java.lang.String theFamily)
        Helper method to check if the given family is in the following list:
        • dos
        • mac
        • netware
        • os/2
        • tandem
        • unix
        • windows
        • win9x
        • z/os
        • os/400
        • openvms
        Parameters:
        theFamily - the family to check.
        Returns:
        true if one of the valid families.
        Since:
        1.4.2
      • getValidFamilies

        public static java.util.Set<java.lang.String> getValidFamilies()
        Returns:
        a copy of the valid families
        Since:
        1.4.2