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.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
version
Specify the required version.
-
Constructor Summary
Constructors Constructor Description AbstractVersionEnforcer()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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)
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.void
setVersion(java.lang.String theVersion)
Specify the required 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
-
Methods inherited from interface org.apache.maven.enforcer.rule.api.EnforcerRule
execute
-
-
-
-
Field Detail
-
version
private java.lang.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
-
-
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 logvariableName
- 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 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
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.- 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 java.lang.String getVersion()
Gets the required version.- Returns:
- the required version
-
setVersion
public final void setVersion(java.lang.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
-
-