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
Contains the common code to compare a version against a version range.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancontainsVersion(org.apache.maven.artifact.versioning.VersionRange allowedRange, org.apache.maven.artifact.versioning.ArtifactVersion theVersion) Copied from Artifact.VersionRange.voidenforceVersion(org.apache.maven.plugin.logging.Log log, String variableName, String requiredVersionRange, org.apache.maven.artifact.versioning.ArtifactVersion actualVersion) Compares the specified version to see if it is allowed by the defined version range.If the rule is to be cached, this id is used as part of the key.final StringGets the required version.booleanThis method tells the enforcer if the rule results may be cached.booleanisResultValid(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.final voidsetVersion(String theVersion) Specify the required version.Methods inherited from class org.apache.maven.plugins.enforcer.AbstractStandardEnforcerRule
getLevel, getMessage, setLevel, setMessageMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.maven.enforcer.rule.api.EnforcerRule
execute
-
Field Details
-
version
Specify the required version. Some examples are:2.0.4Version 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 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
Description copied from interface:EnforcerRuleIf 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:EnforcerRuleThis 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:
trueif rule is cacheable
-
isResultValid
Description copied from interface:EnforcerRuleIf 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:
trueif the stored results are valid for the same id.
-
getVersion
Gets the required version.- Returns:
- the required version
-
setVersion
Specify the required version. Some examples are:2.0.4Version 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
-