Class RequireOS

All Implemented Interfaces:
EnforcerRule, EnforcerRule2

public class RequireOS extends AbstractStandardEnforcerRule
This rule checks that the OS is allowed by combinations of family, name, version and cpu architecture. The behavior is exactly the same as the Maven Os profile activation so the same values are allowed here.
Version:
$Id: RequireOS.java 1634140 2014-10-24 21:23:01Z khmarbaise $
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private String
    The OS architecture desired.
    private boolean
    Display detected OS information.
    private String
    The OS family type desired
    Possible values: dos mac netware os/2 tandem unix windows win9x z/os os/400
    private String
    The OS name desired.
    private String
    The OS version desired.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Instantiates a new RequireOS.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Helper method to check that at least one of family, name, version or arch is set.
    private org.apache.maven.model.Activation
    Creates an Activation object that contains the ActivationOS information.
    private org.apache.maven.model.ActivationOS
    Creates an ActivationOS object containing family, name, version and arch.
    private org.apache.maven.model.Profile
    Creates a Profile object that contains the activation information.
    void
    displayOSInfo(org.apache.maven.plugin.logging.Log log, boolean info)
    Log the current OS information.
    void
    This is the interface into the rule.
    Gets the arch.
    If the rule is to be cached, this id is used as part of the key.
    Gets the family.
    Gets the name.
    Gets the version.
    boolean
    Helper method to determine if the current OS is allowed based on the injected values for family, name, version and arch.
    boolean
    This method tells the enforcer if the rule results may be cached.
    final boolean
     
    boolean
    isResultValid(EnforcerRule theCachedRule)
    Checks if cached result is valid.
    boolean
    isValidFamily(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 Note: '!' is allowed at the beginning of the string and still considered valid.
    void
    setArch(String theArch)
    Sets the arch.
    final void
    setDisplay(boolean display)
     
    void
    setFamily(String theFamily)
    Sets the family.
    void
    setName(String theName)
    Sets the name.
    void
    setVersion(String theVersion)
    Sets the version.

    Methods inherited from class org.apache.maven.plugins.enforcer.AbstractStandardEnforcerRule

    getLevel, getMessage, setLevel, setMessage

    Methods inherited from class java.lang.Object

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

    • family

      private String family
      The OS family type desired
      Possible values:
      • dos
      • mac
      • netware
      • os/2
      • tandem
      • unix
      • windows
      • win9x
      • z/os
      • os/400
    • name

      private String name
      The OS name desired.
    • version

      private String version
      The OS version desired.
    • arch

      private String arch
      The OS architecture desired.
    • display

      private boolean display
      Display detected OS information.
  • Constructor Details

    • RequireOS

      public RequireOS()
      Instantiates a new RequireOS.
  • Method Details

    • execute

      public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException
      This is the interface into the rule. This method should throw an exception containing a reason message if the rule fails the check. The plugin will then decide based on the fail flag if it should stop or just log the message as a warning.
      Parameters:
      helper - The helper provides access to the log, MavenSession and has helpers to get common components. It is also able to lookup components by class name.
      Throws:
      EnforcerRuleException - the enforcer rule exception
    • displayOSInfo

      public void displayOSInfo(org.apache.maven.plugin.logging.Log log, boolean info)
      Log the current OS information.
      Parameters:
      log - the log
      info - the info
    • isAllowed

      public boolean isAllowed()
      Helper method to determine if the current OS is allowed based on the injected values for family, name, version and arch.
      Returns:
      true if the version is allowed.
    • allParamsEmpty

      public boolean allParamsEmpty()
      Helper method to check that at least one of family, name, version or arch is set.
      Returns:
      true if all parameters are empty.
    • createProfile

      private org.apache.maven.model.Profile createProfile()
      Creates a Profile object that contains the activation information.
      Returns:
      a properly populated profile to be used for OS validation.
    • createActivation

      private org.apache.maven.model.Activation createActivation()
      Creates an Activation object that contains the ActivationOS information.
      Returns:
      a properly populated Activation object.
    • createOsBean

      private org.apache.maven.model.ActivationOS createOsBean()
      Creates an ActivationOS object containing family, name, version and arch.
      Returns:
      a properly populated ActivationOS object.
    • isValidFamily

      public boolean isValidFamily(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
      Note: '!' is allowed at the beginning of the string and still considered valid.
      Parameters:
      theFamily - the family to check.
      Returns:
      true if one of the valid families.
    • getArch

      public String getArch()
      Gets the arch.
      Returns:
      the arch
    • setArch

      public void setArch(String theArch)
      Sets the arch.
      Parameters:
      theArch - the arch to set
    • getFamily

      public String getFamily()
      Gets the family.
      Returns:
      the family
    • setFamily

      public void setFamily(String theFamily)
      Sets the family.
      Parameters:
      theFamily - the family to set
    • getName

      public String getName()
      Gets the name.
      Returns:
      the name
    • setName

      public void setName(String theName)
      Sets the name.
      Parameters:
      theName - the name to set
    • getVersion

      public String getVersion()
      Gets the version.
      Returns:
      the version
    • setVersion

      public void setVersion(String theVersion)
      Sets the version.
      Parameters:
      theVersion - the version to set
    • setDisplay

      public final void setDisplay(boolean display)
      Parameters:
      display - The value for the display.
    • isDisplay

      public final boolean isDisplay()
    • getCacheId

      public String getCacheId()
      If the rule is to be cached, this id is used as part of the key. This can allow rules to take parameters that allow multiple results of the same rule to be cached.
      Returns:
      id to be used by the enforcer to determine uniqueness of cache results. The ids only need to be unique within a given rule implementation as the full key will be [classname]-[id]
    • isCacheable

      public boolean isCacheable()
      This method tells the enforcer if the rule results may be cached. If the result is true, the results will be remembered for future executions in the same build (ie children). Subsequent iterations of the rule will be queried to see if they are also cacheable. This will allow the rule to be uncached further down the tree if needed.
      Returns:
      true if rule is cacheable
    • isResultValid

      public boolean isResultValid(EnforcerRule theCachedRule)
      Checks if cached result is valid.
      Parameters:
      theCachedRule - the last cached instance of the rule. This is to be used by the rule to potentially determine if the results are still valid (ie if the configuration has been overridden)
      Returns:
      true if the stored results are valid for the same id.