Class AbstractVersionEnforcer

java.lang.Object
org.apache.maven.plugins.enforcer.AbstractStandardEnforcerRule
org.apache.maven.plugins.enforcer.AbstractVersionEnforcer
All Implemented Interfaces:
EnforcerRule, EnforcerRule2
Direct Known Subclasses:
RequireJavaVersion, RequireMavenVersion

public abstract class AbstractVersionEnforcer extends AbstractStandardEnforcerRule
Contains the common code to compare a version against a version range.
Version:
$Id: AbstractVersionEnforcer.java 1634140 2014-10-24 21:23:01Z khmarbaise $
  • Field Details

    • version

      private String version
      Specify the required version. Some examples are:
      • 2.0.4 Version 2.0.4 and higher (different from Maven meaning)
      • [2.0,2.1) Versions 2.0 (included) to 2.1 (not included)
      • [2.0,2.1] Versions 2.0 to 2.1 (both included)
      • [2.0.5,) Versions 2.0.5 and higher
      • (,2.0.5],[2.1.1,) Versions up to 2.0.5 (included) and 2.1.1 or higher
  • Constructor Details

    • AbstractVersionEnforcer

      public AbstractVersionEnforcer()
  • Method Details

    • enforceVersion

      public void enforceVersion(org.apache.maven.plugin.logging.Log log, String variableName, String requiredVersionRange, org.apache.maven.artifact.versioning.ArtifactVersion actualVersion) throws EnforcerRuleException
      Compares the specified version to see if it is allowed by the defined version range.
      Parameters:
      log - the log
      variableName - name of variable to use in messages (Example: "Maven" or "Java" etc).
      requiredVersionRange - range of allowed versions.
      actualVersion - the version to be checked.
      Throws:
      EnforcerRuleException - the enforcer rule exception
    • containsVersion

      public static boolean containsVersion(org.apache.maven.artifact.versioning.VersionRange allowedRange, org.apache.maven.artifact.versioning.ArtifactVersion theVersion)
      Copied from Artifact.VersionRange. This is tweaked to handle singular ranges properly. Currently the default containsVersion method assumes a singular version means allow everything. This method assumes that "2.0.4" == "[2.0.4,)"
      Parameters:
      allowedRange - range of allowed versions.
      theVersion - the version to be checked.
      Returns:
      true if the version is contained by the range.
    • 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.
      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()
      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.
      Returns:
      true if rule is cacheable
    • isResultValid

      public boolean isResultValid(EnforcerRule theCachedRule)
      Description copied from interface: EnforcerRule
      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.
    • getVersion

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

      public final void setVersion(String theVersion)
      Specify the required version. Some examples are:
      • 2.0.4 Version 2.0.4 and higher (different from Maven meaning)
      • [2.0,2.1) Versions 2.0 (included) to 2.1 (not included)
      • [2.0,2.1] Versions 2.0 to 2.1 (both included)
      • [2.0.5,) Versions 2.0.5 and higher
      • (,2.0.5],[2.1.1,) Versions up to 2.0.5 (included) and 2.1.1 or higher
      Parameters:
      theVersion - the required version to set