diff options
Diffstat (limited to 'enforcer-rule/src/main')
3 files changed, 20 insertions, 6 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)+">."); |