Search in sources :

Example 21 with Report

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

the class JacksonDifferenceAnalyzerTest method doesntReportArraysAsWhole.

@Test
void doesntReportArraysAsWhole() {
    Archive ar = Mockito.mock(Archive.class);
    API api = API.of(ar).build();
    TestElement oldEl = new TestElement(api, ar, "file.js", JsonNodeFactory.instance.arrayNode().add(1), "here");
    TestElement newEl = new TestElement(api, ar, "file.js", JsonNodeFactory.instance.arrayNode().add(0).add(1), "here");
    TestDifferenceAnalyzer analyzer = new TestDifferenceAnalyzer();
    analyzer.beginAnalysis(oldEl, newEl);
    Report report = analyzer.endAnalysis(oldEl, newEl);
    assertSame(oldEl, report.getOldElement());
    assertSame(newEl, report.getNewElement());
    assertTrue(report.getDifferences().isEmpty());
}
Also used : Archive(org.revapi.Archive) Report(org.revapi.Report) API(org.revapi.API) Test(org.junit.jupiter.api.Test)

Example 22 with Report

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

the class BuildTimeReporter method getAllProblemsMessage.

public String getAllProblemsMessage() {
    StringBuilder errors = new StringBuilder("The following API problems caused the build to fail:\n");
    for (Report r : allProblems) {
        Element element = r.getNewElement();
        Archive archive;
        if (element == null) {
            element = r.getOldElement();
            assert element != null;
            archive = shouldOutputArchive(oldApi, element.getArchive()) ? element.getArchive() : null;
        } else {
            archive = shouldOutputArchive(newApi, element.getArchive()) ? element.getArchive() : null;
        }
        for (Difference d : r.getDifferences()) {
            if (isReportable(d)) {
                errors.append(d.code).append(": ").append(element.getFullHumanReadableString()).append(": ").append(d.description);
                if (archive != null) {
                    errors.append(" [").append(archive.getName()).append("]");
                }
                if (d.documentationLink != null) {
                    errors.append(" ").append(d.documentationLink);
                }
                errors.append("\n");
            }
        }
    }
    return errors.toString();
}
Also used : Archive(org.revapi.Archive) Report(org.revapi.Report) Element(org.revapi.Element) Difference(org.revapi.Difference)

Example 23 with Report

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

the class SupplementaryJarsTest method testExcludedClassesInAPI.

@Test
public void testExcludedClassesInAPI() throws Exception {
    List<Report> allReports;
    Revapi revapi = createRevapi(CollectingReporter.class);
    AnalysisContext ctx = AnalysisContext.builder(revapi).withOldAPI(API.of(new ShrinkwrapArchive(apiV1)).supportedBy(new ShrinkwrapArchive(supV1)).build()).withNewAPI(API.of(new ShrinkwrapArchive(apiV2)).supportedBy(new ShrinkwrapArchive(supV2)).build()).withConfigurationFromJSON("{\"revapi\": {" + "\"filter\": {\"elements\": {\"exclude\": [{\"matcher\": \"java\", \"match\": \"match %c | %b; class %c=C {} class %b=B.T$2 {}\"}]}}}}").build();
    try (AnalysisResult res = revapi.analyze(ctx)) {
        res.throwIfFailed();
        allReports = res.getExtensions().getFirstExtension(CollectingReporter.class, null).getReports();
    }
    Assert.assertEquals(3, allReports.size());
    Assert.assertFalse(containsDifference(allReports, null, "class B.T$1.Private", Code.CLASS_NON_PUBLIC_PART_OF_API.code()));
    Assert.assertFalse(containsDifference(allReports, null, "field B.T$2.f2", Code.FIELD_ADDED.code()));
    Assert.assertTrue(containsDifference(allReports, null, "field A.f3", Code.FIELD_ADDED.code()));
    Assert.assertFalse(containsDifference(allReports, "class B.T$2", "class B.T$2", Code.CLASS_NOW_FINAL.code()));
    Assert.assertTrue(containsDifference(allReports, null, "class B.T$3", Code.CLASS_EXTERNAL_CLASS_EXPOSED_IN_API.code()));
    Assert.assertTrue(containsDifference(allReports, null, "class B.PrivateUsedClass", Code.CLASS_NON_PUBLIC_PART_OF_API.code()));
    Assert.assertFalse(containsDifference(allReports, "class B.UsedByIgnoredClass", "class B.UsedByIgnoredClass", Code.CLASS_KIND_CHANGED.code()));
    Assert.assertFalse(containsDifference(allReports, "method void B.UsedByIgnoredClass::<init>()", null, Code.METHOD_REMOVED.code()));
}
Also used : Revapi(org.revapi.Revapi) Report(org.revapi.Report) AnalysisContext(org.revapi.AnalysisContext) AnalysisResult(org.revapi.AnalysisResult) Test(org.junit.Test)

Example 24 with Report

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

the class BuildTimeReporterTest method testNonIdentifyingAttachmentsHiddenInsideComment.

@Test
public void testNonIdentifyingAttachmentsHiddenInsideComment() {
    BuildTimeReporter reporter = new BuildTimeReporter();
    API oldApi = API.builder().build();
    API newApi = API.builder().build();
    AnalysisContext ctx = AnalysisContext.builder().withOldAPI(oldApi).withNewAPI(newApi).withData(BuildTimeReporter.BREAKING_CRITICALITY_KEY, Criticality.ALLOWED).withData(BuildTimeReporter.SUGGESTIONS_BUILDER_KEY, new JsonSuggestionsBuilder()).build();
    reporter.initialize(ctx);
    DummyElement oldEl = new DummyElement(oldApi);
    DummyElement newEl = new DummyElement(newApi);
    Report report = Report.builder().withNew(newEl).withOld(oldEl).addDifference().withCode("diffs\\myDiff").withDescription("the problem").addClassification(CompatibilityType.BINARY, DifferenceSeverity.BREAKING).withCriticality(Criticality.ERROR).addAttachment("nonIdentifying", "{\"a\", \"b\"}").done().build();
    reporter.report(report);
    String resultMessage = reporter.getIgnoreSuggestion();
    Assert.assertNotNull(resultMessage);
    int commentStart = resultMessage.indexOf("/*");
    int commentEnd = resultMessage.indexOf("*/");
    int nonIdentifyingIndex = resultMessage.indexOf("nonIdentifying");
    Assert.assertTrue(commentStart < nonIdentifyingIndex);
    Assert.assertTrue(commentEnd > nonIdentifyingIndex);
}
Also used : Report(org.revapi.Report) API(org.revapi.API) AnalysisContext(org.revapi.AnalysisContext) Test(org.junit.Test)

Example 25 with Report

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

the class AnnotatedElementFilterTest method testChangesReportedOnAnnotationElements.

@Test
public void testChangesReportedOnAnnotationElements() throws Exception {
    CollectingReporter reporter = runAnalysis(CollectingReporter.class, "{\"revapi\": {\"filter\": {\"elements\": {\"include\":[" + "{\"matcher\": \"java\", \"match\": \"match %c|%a; @Attributes.Anno(**) %a=*; class %c=Attributes{}\"}]}}}}", "v1/annotations/Attributes.java", "v2/annotations/Attributes.java");
    List<Report> reports = reporter.getReports();
    Assert.assertEquals(2, reports.size());
    Report parameterChange = reports.stream().filter(r -> r.getNewElement() instanceof MethodParameterElement).findFirst().orElse(null);
    Report annotationChanges = reports.stream().filter(r -> r.getNewElement() instanceof MethodElement).findFirst().orElse(null);
    Assert.assertEquals(1, parameterChange.getDifferences().size());
    Assert.assertEquals("java.method.parameterTypeChanged", parameterChange.getDifferences().get(0).code);
    Assert.assertEquals(3, annotationChanges.getDifferences().size());
    Assert.assertEquals(new HashSet<>(Arrays.asList("java.annotation.attributeValueChanged", "java.annotation.attributeAdded", "java.element.nowDeprecated")), annotationChanges.getDifferences().stream().map(d -> d.code).collect(Collectors.toSet()));
}
Also used : Report(org.revapi.Report) MethodParameterElement(org.revapi.java.model.MethodParameterElement) MethodElement(org.revapi.java.model.MethodElement) Test(org.junit.Test)

Aggregations

Report (org.revapi.Report)26 Test (org.junit.Test)13 API (org.revapi.API)9 AnalysisContext (org.revapi.AnalysisContext)9 Difference (org.revapi.Difference)9 Archive (org.revapi.Archive)6 Test (org.junit.jupiter.api.Test)5 AnalysisResult (org.revapi.AnalysisResult)5 ArrayList (java.util.ArrayList)4 Revapi (org.revapi.Revapi)3 HashMap (java.util.HashMap)2 Check (org.revapi.java.spi.Check)2 Map (java.util.Map)1 ModelNode (org.jboss.dmr.ModelNode)1 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)1 Element (org.revapi.Element)1 MethodElement (org.revapi.java.model.MethodElement)1 MethodParameterElement (org.revapi.java.model.MethodParameterElement)1 TypeElement (org.revapi.java.model.TypeElement)1 JavaModelElement (org.revapi.java.spi.JavaModelElement)1