aboutsummaryrefslogtreecommitdiffstats
path: root/enforcer-rule
diff options
context:
space:
mode:
authorJulien Eluard <[email protected]>2011-02-13 10:54:33 -0800
committerJulien Eluard <[email protected]>2011-02-13 10:54:33 -0800
commitd32040ba665ca8d87c44310ab9d51a2f862a8886 (patch)
tree00956c9d084415f816354f69841809d372aa92e1 /enforcer-rule
parent91d9ef87331c9bbfa6eb6fefdfa37f71a7c71b98 (diff)
Introduced strict compatibility checking.
Diffstat (limited to 'enforcer-rule')
-rwxr-xr-xenforcer-rule/src/main/java/org/semver/enforcer/AbstractEnforcerRule.java4
-rwxr-xr-xenforcer-rule/src/main/java/org/semver/enforcer/RequireBackwardCompatibility.java19
-rwxr-xr-xenforcer-rule/src/main/java/org/semver/enforcer/RequireSemanticVersioningConformance.java3
-rwxr-xr-xenforcer-rule/src/site/apt/examples/backward-compatibility.apt.vm58
4 files changed, 77 insertions, 7 deletions
diff --git a/enforcer-rule/src/main/java/org/semver/enforcer/AbstractEnforcerRule.java b/enforcer-rule/src/main/java/org/semver/enforcer/AbstractEnforcerRule.java
index 670a7b0..d276b7f 100755
--- a/enforcer-rule/src/main/java/org/semver/enforcer/AbstractEnforcerRule.java
+++ b/enforcer-rule/src/main/java/org/semver/enforcer/AbstractEnforcerRule.java
@@ -151,13 +151,13 @@ public abstract class AbstractEnforcerRule implements EnforcerRule {
final Comparer comparer = new Comparer(previousJar, currentJar, extractFilters(this.includes), extractFilters(this.excludes));
final Delta delta = comparer.diff();
- enforce(delta, previous, current);
+ enforce(helper, delta, previous, current);
} catch (IOException e) {
throw new EnforcerRuleException("Exception while checking compatibility: "+e.toString(), e);
}
}
- protected abstract void enforce(final Delta delta, final Version previous, final Version current) throws EnforcerRuleException;
+ protected abstract void enforce(final EnforcerRuleHelper helper, final Delta delta, final Version previous, final Version current) throws EnforcerRuleException;
protected final void fail(final Delta delta, final String message) throws EnforcerRuleException {
if (this.dumpDetails) {
diff --git a/enforcer-rule/src/main/java/org/semver/enforcer/RequireBackwardCompatibility.java b/enforcer-rule/src/main/java/org/semver/enforcer/RequireBackwardCompatibility.java
index e601515..3dc3850 100755
--- a/enforcer-rule/src/main/java/org/semver/enforcer/RequireBackwardCompatibility.java
+++ b/enforcer-rule/src/main/java/org/semver/enforcer/RequireBackwardCompatibility.java
@@ -20,6 +20,7 @@ package org.semver.enforcer;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
import org.semver.Delta;
import org.semver.Version;
@@ -39,8 +40,10 @@ public final class RequireBackwardCompatibility extends AbstractEnforcerRule {
*/
private String compatibilityType;
+ private boolean strictChecking = false;
+
@Override
- protected void enforce(final Delta delta, final Version previous, final Version current) throws EnforcerRuleException {
+ protected void enforce(final EnforcerRuleHelper helper, final Delta delta, final Version previous, final Version current) throws EnforcerRuleException {
if (this.compatibilityType == null) {
throw new IllegalArgumentException("A value for compatibilityType attribute must be provided.");
}
@@ -53,8 +56,18 @@ public final class RequireBackwardCompatibility extends AbstractEnforcerRule {
}
final Delta.CompatibilityType detectedCompatibilityType = delta.computeCompatibilityType();
- if (detectedCompatibilityType.compareTo(expectedCompatibilityType) > 0) {
- fail(delta, "Current codebase is not backward compatible ("+this.compatibilityType+") with version <"+previous+">. Compatibility type has been detected as <"+detectedCompatibilityType+">");
+ if (this.strictChecking) {
+ if (detectedCompatibilityType != expectedCompatibilityType) {
+ fail(delta, "Current codebase is not strictly backward compatible ("+this.compatibilityType+") with version <"+previous+">. Compatibility type has been detected as <"+detectedCompatibilityType+">");
+ }
+ } else {
+ if (expectedCompatibilityType == Delta.CompatibilityType.NON_BACKWARD_COMPATIBLE) {
+ helper.getLog().warn("Rule will never fail as compatibility type "+Delta.CompatibilityType.NON_BACKWARD_COMPATIBLE+" is used with non-strict checking.");
+ }
+
+ if (detectedCompatibilityType.compareTo(expectedCompatibilityType) > 0) {
+ fail(delta, "Current codebase is not backward compatible ("+this.compatibilityType+") with version <"+previous+">. Compatibility type has been detected as <"+detectedCompatibilityType+">");
+ }
}
}
diff --git a/enforcer-rule/src/main/java/org/semver/enforcer/RequireSemanticVersioningConformance.java b/enforcer-rule/src/main/java/org/semver/enforcer/RequireSemanticVersioningConformance.java
index 608557e..98d7c99 100755
--- a/enforcer-rule/src/main/java/org/semver/enforcer/RequireSemanticVersioningConformance.java
+++ b/enforcer-rule/src/main/java/org/semver/enforcer/RequireSemanticVersioningConformance.java
@@ -20,6 +20,7 @@ package org.semver.enforcer;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
import org.semver.Delta;
import org.semver.Version;
@@ -33,7 +34,7 @@ import org.semver.Version;
public final class RequireSemanticVersioningConformance extends AbstractEnforcerRule {
@Override
- protected void enforce(final Delta delta, final Version previous, final Version current) throws EnforcerRuleException {
+ protected void enforce(final EnforcerRuleHelper helper, final Delta delta, final Version previous, final Version current) throws EnforcerRuleException {
final boolean compatible = delta.validate(previous, current);
if (!compatible) {
fail(delta, "Current codebase is incompatible with version <"+previous+">. Version should be at least <"+delta.infer(previous)+">.");
diff --git a/enforcer-rule/src/site/apt/examples/backward-compatibility.apt.vm b/enforcer-rule/src/site/apt/examples/backward-compatibility.apt.vm
index 5251a22..41faf0b 100755
--- a/enforcer-rule/src/site/apt/examples/backward-compatibility.apt.vm
+++ b/enforcer-rule/src/site/apt/examples/backward-compatibility.apt.vm
@@ -21,7 +21,7 @@ Checking a project's compatibility against older releases
* Basic example
In order to check your project's compatibility against an older release, you must add the enforcer rule as a dependency to
- the maven-enforcer-plugin and then configure your the maven-enforcer-plugin to run the rule.
+ the maven-enforcer-plugin and then configure your the maven-enforcer-plugin to run the rule. Rule will succeed if specified compatibility type is compatible with specified one (less permissive compatibility types will be accepted).
By default current artifact will be checked against most recently released version (retrieved from either local or one of configured remote repositories). Setting dumpDetails to true will output differences to standard output.
@@ -303,3 +303,59 @@ Checking a project's compatibility against older releases
...
</project>
---
+* Strict checking against a specific released version
+
+ You can stricly check your project (backward compatibility type MUST match specified one) against a specific released version:
+
+---
+<project>
+ ...
+ <build>
+ ...
+ <plugins>
+ ...
+ <plugin>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <version>1.0-beta-1</version>
+ ...
+ <dependencies>
+ ...
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>${project.artifactId}</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ ...
+ </dependencies>
+ ...
+ <executions>
+ ....
+ <execution>
+ <id>check-version</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>enforce</goal>
+ </goals>
+ <configuration>
+ <rules>
+ <requireBackwardCompatibility implementation="org.semver.enforcer.RequireBackwardCompatibility">
+ ...
+ <compatibilityType>NON_BACKWARD_COMPATIBLE</compatibilityType>
+ <strictChecking>true</strictChecking>
+ <previousVersion>1.0.0</previousVersion>
+ ...
+ </requireBackwardCompatibility>
+ </rules>
+ </configuration>
+ </execution>
+ ...
+ </executions>
+ ...
+ </plugin>
+ ...
+ </plugins>
+ ...
+ </build>
+ ...
+</project>
+--- \ No newline at end of file