Class RequireEnvironmentVariable

All Implemented Interfaces:
EnforcerRule, EnforcerRule2

public class RequireEnvironmentVariable extends AbstractPropertyEnforcerRule
This rule checks that certain environment variable is set.
  • Field Details

    • variableName

      private String variableName
      Specify the required variable.
  • Constructor Details

    • RequireEnvironmentVariable

      public RequireEnvironmentVariable()
  • Method Details

    • setVariableName

      public final void setVariableName(String variableName)
      Parameters:
      variableName - the variable name
      See Also:
    • getVariableName

      public final String getVariableName()
    • resolveValue

      public String resolveValue(EnforcerRuleHelper helper)
      Description copied from class: AbstractPropertyEnforcerRule
      Resolves the property value
      Specified by:
      resolveValue in class AbstractPropertyEnforcerRule
    • isCacheable

      public boolean isCacheable()
      Description copied from interface: EnforcerRule
      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.
      Specified by:
      isCacheable in interface EnforcerRule
      Overrides:
      isCacheable in class AbstractNonCacheableEnforcerRule
      Returns:
      true if rule is cacheable
    • isResultValid

      public boolean isResultValid(EnforcerRule cachedRule)
      Description copied from interface: EnforcerRule
      If the rule is cacheable and the same id is found in the cache, the stored results are passed to this method to allow double checking of the results. Most of the time this can be done by generating unique ids, but sometimes the results of objects returned by the helper need to be queried. You may for example, store certain objects in your rule and then query them later.
      Specified by:
      isResultValid in interface EnforcerRule
      Overrides:
      isResultValid in class AbstractNonCacheableEnforcerRule
      Parameters:
      cachedRule - 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.
    • getCacheId

      public String getCacheId()
      Description copied from interface: EnforcerRule
      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.
      Specified by:
      getCacheId in interface EnforcerRule
      Overrides:
      getCacheId in class AbstractNonCacheableEnforcerRule
      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]
    • getPropertyName

      public String getPropertyName()
      Description copied from class: AbstractPropertyEnforcerRule
      The name of the property currently being evaluated, this is used for default message purposes only
      Specified by:
      getPropertyName in class AbstractPropertyEnforcerRule
      Returns:
      the name of the property
    • getName

      public String getName()
      Description copied from class: AbstractPropertyEnforcerRule
      How the property that is being evaluated is called
      Specified by:
      getName in class AbstractPropertyEnforcerRule
      Returns:
      kind of property