org.apache.maven.plugins.enforcer
Class AbstractVersionEnforcer

java.lang.Object
  extended by org.apache.maven.plugins.enforcer.AbstractStandardEnforcerRule
      extended by org.apache.maven.plugins.enforcer.AbstractVersionEnforcer
All Implemented Interfaces:
EnforcerRule
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 675992 2008-07-11 15:42:48Z hboutemy $
Author:
Brian Fox

Field Summary
 java.lang.String version
          Specify the required version.
 
Fields inherited from class org.apache.maven.plugins.enforcer.AbstractStandardEnforcerRule
message
 
Constructor Summary
AbstractVersionEnforcer()
           
 
Method Summary
static boolean containsVersion(org.apache.maven.artifact.versioning.VersionRange allowedRange, org.apache.maven.artifact.versioning.ArtifactVersion theVersion)
          Copied from Artifact.VersionRange.
 void enforceVersion(org.apache.maven.plugin.logging.Log log, java.lang.String variableName, java.lang.String requiredVersionRange, org.apache.maven.artifact.versioning.ArtifactVersion actualVersion)
          Compares the specified version to see if it is allowed by the defined version range.
 java.lang.String getCacheId()
          If the rule is to be cached, this id is used as part of the key.
 java.lang.String getVersion()
          Gets the required version.
 boolean isCacheable()
          This method tells the enforcer if the rule results may be cached.
 boolean isResultValid(EnforcerRule theCachedRule)
          Checks if cached result is valid.
 void setVersion(java.lang.String theVersion)
          Sets the required version.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.maven.enforcer.rule.api.EnforcerRule
execute
 

Field Detail

version

public java.lang.String version
Specify the required version. Some examples are:

Constructor Detail

AbstractVersionEnforcer

public AbstractVersionEnforcer()
Method Detail

enforceVersion

public void enforceVersion(org.apache.maven.plugin.logging.Log log,
                           java.lang.String variableName,
                           java.lang.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:
org.apache.maven.plugin.MojoExecutionException - if the version is not allowed.
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 java.lang.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 java.lang.String getVersion()
Gets the required version.

Returns:
the required version

setVersion

public void setVersion(java.lang.String theVersion)
Sets the required version.

Parameters:
theVersion - the required version to set


Copyright © 2007-2011 Apache Software Foundation. All Rights Reserved.