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
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 1345332 2012-06-01 20:14:13Z rfscholte $
Author:
Brian Fox

Field Summary
 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(VersionRange allowedRange, ArtifactVersion theVersion)
          Copied from Artifact.VersionRange.
 void enforceVersion(Log log, String variableName, String requiredVersionRange, ArtifactVersion actualVersion)
          Compares the specified version to see if it is allowed by the defined version range.
 String getCacheId()
           
 String getVersion()
          Gets the required version.
 boolean isCacheable()
           
 boolean isResultValid(EnforcerRule theCachedRule)
           
 void setVersion(String theVersion)
          Sets the required version.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

version

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

Constructor Detail

AbstractVersionEnforcer

public AbstractVersionEnforcer()
Method Detail

enforceVersion

public void enforceVersion(Log log,
                           String variableName,
                           String requiredVersionRange,
                           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:
MojoExecutionException - if the version is not allowed.
EnforcerRuleException - the enforcer rule exception

containsVersion

public static boolean containsVersion(VersionRange allowedRange,
                                      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()

isCacheable

public boolean isCacheable()

isResultValid

public boolean isResultValid(EnforcerRule theCachedRule)

getVersion

public String getVersion()
Gets the required version.

Returns:
the required version

setVersion

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

Parameters:
theVersion - the required version to set


Copyright © 2007-2012 The Apache Software Foundation. All Rights Reserved.