Search in sources :

Example 1 with DifferenceSeverity

use of org.revapi.DifferenceSeverity in project revapi by revapi.

the class SemverIgnoreTransform method initialize.

@Override
public void initialize(@Nonnull AnalysisContext analysisContext) {
    ModelNode node = analysisContext.getConfiguration();
    if (hasMultipleElements(analysisContext.getOldApi().getArchives()) || hasMultipleElements(analysisContext.getNewApi().getArchives())) {
        throw new IllegalArgumentException("The semver extension doesn't handle changes in multiple archives at once.");
    }
    enabled = node.get("enabled").isDefined() && node.get("enabled").asBoolean();
    if (enabled) {
        Iterator<? extends Archive> oldArchives = analysisContext.getOldApi().getArchives().iterator();
        Iterator<? extends Archive> newArchives = analysisContext.getNewApi().getArchives().iterator();
        if (!oldArchives.hasNext() || !newArchives.hasNext()) {
            enabled = false;
            return;
        }
        Archive oldArchive = oldArchives.next();
        Archive newArchive = newArchives.next();
        if (!(oldArchive instanceof Archive.Versioned)) {
            throw new IllegalArgumentException("Old archive doesn't support extracting the version.");
        }
        if (!(newArchive instanceof Archive.Versioned)) {
            throw new IllegalArgumentException("New archive doesn't support extracting the version.");
        }
        String oldVersionString = ((Archive.Versioned) oldArchive).getVersion();
        String newVersionString = ((Archive.Versioned) newArchive).getVersion();
        Version oldVersion = Version.parse(oldVersionString);
        Version newVersion = Version.parse(newVersionString);
        if (newVersion.major == 0 && oldVersion.major == 0 && !node.get("versionIncreaseAllows").isDefined()) {
            DifferenceSeverity minorChangeAllowed = asSeverity(node.get("versionIncreaseAllows", "minor"), DifferenceSeverity.BREAKING);
            DifferenceSeverity patchVersionAllowed = asSeverity(node.get("versionIncreaseAllows", "patch"), DifferenceSeverity.NON_BREAKING);
            if (newVersion.minor > oldVersion.minor) {
                allowedSeverity = minorChangeAllowed;
            } else if (newVersion.minor == oldVersion.minor && newVersion.patch > oldVersion.patch) {
                allowedSeverity = patchVersionAllowed;
            } else {
                allowedSeverity = null;
            }
        } else {
            DifferenceSeverity majorChangeAllowed = asSeverity(node.get("versionIncreaseAllows", "major"), DifferenceSeverity.BREAKING);
            DifferenceSeverity minorChangeAllowed = asSeverity(node.get("versionIncreaseAllows", "minor"), DifferenceSeverity.NON_BREAKING);
            DifferenceSeverity patchVersionAllowed = asSeverity(node.get("versionIncreaseAllows", "patch"), DifferenceSeverity.EQUIVALENT);
            if (newVersion.major > oldVersion.major) {
                allowedSeverity = majorChangeAllowed;
            } else if (newVersion.major == oldVersion.major && newVersion.minor > oldVersion.minor) {
                allowedSeverity = minorChangeAllowed;
            } else {
                allowedSeverity = patchVersionAllowed;
            }
        }
        passThroughDifferences = Collections.emptyList();
        if (node.get("passThroughDifferences").isDefined()) {
            passThroughDifferences = node.get("passThroughDifferences").asList().stream().map(ModelNode::asString).collect(toList());
        }
    }
}
Also used : Archive(org.revapi.Archive) DifferenceSeverity(org.revapi.DifferenceSeverity) ModelNode(org.jboss.dmr.ModelNode)

Example 2 with DifferenceSeverity

use of org.revapi.DifferenceSeverity in project revapi by revapi.

the class AntReporter method report.

@Override
public void report(@Nonnull Report report) {
    Element element = report.getOldElement();
    if (element == null) {
        element = report.getNewElement();
    }
    if (element == null) {
        throw new IllegalStateException("This should not ever happen. Both elements in a report were null.");
    }
    for (Difference difference : report.getDifferences()) {
        DifferenceSeverity maxSeverity = DifferenceSeverity.NON_BREAKING;
        for (Map.Entry<CompatibilityType, DifferenceSeverity> e : difference.classification.entrySet()) {
            if (e.getValue().compareTo(maxSeverity) >= 0) {
                maxSeverity = e.getValue();
            }
        }
        if (maxSeverity.compareTo(minSeverity) < 0) {
            continue;
        }
        StringBuilder message = new StringBuilder();
        message.append(element.getFullHumanReadableString()).append(": ").append(difference.code).append(": ").append(difference.description).append(" [");
        for (Map.Entry<CompatibilityType, DifferenceSeverity> e : difference.classification.entrySet()) {
            message.append(e.getKey()).append(": ").append(e.getValue()).append(", ");
        }
        message.replace(message.length() - 2, message.length(), "]");
        logger.log(message.toString(), Project.MSG_ERR);
    }
}
Also used : DifferenceSeverity(org.revapi.DifferenceSeverity) CompatibilityType(org.revapi.CompatibilityType) Element(org.revapi.Element) Difference(org.revapi.Difference) Map(java.util.Map)

Example 3 with DifferenceSeverity

use of org.revapi.DifferenceSeverity in project revapi by revapi.

the class TextReporter method report.

@Override
public void report(@Nonnull Report report) {
    if (report.getDifferences().isEmpty()) {
        return;
    }
    DifferenceSeverity maxReportedSeverity = DifferenceSeverity.NON_BREAKING;
    for (Difference d : report.getDifferences()) {
        for (DifferenceSeverity c : d.classification.values()) {
            if (c.compareTo(maxReportedSeverity) > 0) {
                maxReportedSeverity = c;
            }
        }
    }
    if (maxReportedSeverity.compareTo(minLevel) < 0) {
        return;
    }
    reports.add(report);
}
Also used : DifferenceSeverity(org.revapi.DifferenceSeverity) Difference(org.revapi.Difference)

Aggregations

DifferenceSeverity (org.revapi.DifferenceSeverity)3 Difference (org.revapi.Difference)2 Map (java.util.Map)1 ModelNode (org.jboss.dmr.ModelNode)1 Archive (org.revapi.Archive)1 CompatibilityType (org.revapi.CompatibilityType)1 Element (org.revapi.Element)1