Search in sources :

Example 1 with Delta

use of org.semver.Delta in project semantic-versioning by jeluard.

the class RequireBackwardCompatibility method enforce.

@Override
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.");
    }
    final Delta.CompatibilityType expectedCompatibilityType;
    try {
        expectedCompatibilityType = Delta.CompatibilityType.valueOf(this.compatibilityType);
    } catch (IllegalStateException e) {
        throw new EnforcerRuleException("Compatibility type value must be one of " + Delta.CompatibilityType.values());
    }
    final Delta.CompatibilityType detectedCompatibilityType = delta.computeCompatibilityType();
    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 + ">");
        }
    }
}
Also used : Delta(org.semver.Delta) EnforcerRuleException(org.apache.maven.enforcer.rule.api.EnforcerRuleException)

Example 2 with Delta

use of org.semver.Delta in project semantic-versioning by jeluard.

the class AbstractEnforcerRule method compareJars.

private void compareJars(final EnforcerRuleHelper helper, final Version previous, final File previousJar, final Version current, final File currentJar) throws EnforcerRuleException {
    helper.getLog().info("Using <" + previousJar + "> as previous JAR");
    helper.getLog().info("Using <" + currentJar + "> as current JAR");
    try {
        final DiffCriteria diffCriteria = publicOnly ? new PublicDiffCriteria() : new SimpleDiffCriteria();
        final Comparer comparer = new Comparer(diffCriteria, previousJar, currentJar, extractFilters(this.includes), extractFilters(this.excludes));
        final Delta delta = comparer.diff();
        enforce(helper, delta, previous, current);
    } catch (IOException e) {
        throw new EnforcerRuleException("Exception while checking compatibility: " + e.toString(), e);
    }
}
Also used : PublicDiffCriteria(org.osjava.jardiff.PublicDiffCriteria) Delta(org.semver.Delta) Comparer(org.semver.Comparer) EnforcerRuleException(org.apache.maven.enforcer.rule.api.EnforcerRuleException) SimpleDiffCriteria(org.osjava.jardiff.SimpleDiffCriteria) IOException(java.io.IOException) SimpleDiffCriteria(org.osjava.jardiff.SimpleDiffCriteria) PublicDiffCriteria(org.osjava.jardiff.PublicDiffCriteria) DiffCriteria(org.osjava.jardiff.DiffCriteria)

Aggregations

EnforcerRuleException (org.apache.maven.enforcer.rule.api.EnforcerRuleException)2 Delta (org.semver.Delta)2 IOException (java.io.IOException)1 DiffCriteria (org.osjava.jardiff.DiffCriteria)1 PublicDiffCriteria (org.osjava.jardiff.PublicDiffCriteria)1 SimpleDiffCriteria (org.osjava.jardiff.SimpleDiffCriteria)1 Comparer (org.semver.Comparer)1