Search in sources :

Example 11 with Report

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

the class MissingClassReportingTest method testReportMissingSuperType.

@Test
public void testReportMissingSuperType() throws Exception {
    ArchiveAndCompilationPath v1 = null, v2 = null;
    try {
        v1 = createCompiledJar("superType1", "v1/supplementary/superType/A.java", "v1/supplementary/superType/B.java");
        v2 = createCompiledJar("superType2", "v2/supplementary/superType/A.java", "v2/supplementary/superType/B.java");
        JavaArchive a1 = ShrinkWrap.create(JavaArchive.class, "superTypeV1.jar").addAsResource(v1.compilationPath.resolve("A.class").toFile(), "A.class").addAsResource(v1.compilationPath.resolve("B.class").toFile(), "B.class");
        JavaArchive a2 = ShrinkWrap.create(JavaArchive.class, "superTypeV2.jar").addAsResource(v2.compilationPath.resolve("B.class").toFile(), "B.class");
        API oldApi = API.of(new ShrinkwrapArchive(a1)).build();
        API newApi = API.of(new ShrinkwrapArchive(a2)).build();
        AnalysisResult res = revapi.analyze(AnalysisContext.builder().withOldAPI(oldApi).withNewAPI(newApi).build());
        List<Report> allReports = res.getExtensions().getFirstExtension(CollectingReporter.class, null).getReports();
        Assert.assertEquals(2, allReports.size());
        Assert.assertTrue(containsDifference(allReports, "class B", "class B", Code.MISSING_NEW_SUPERTYPE.code()));
        Assert.assertTrue(containsDifference(allReports, "class A", null, Code.CLASS_REMOVED.code()));
        res = revapi.analyze(AnalysisContext.builder().withOldAPI(newApi).withNewAPI(oldApi).build());
        allReports = res.getExtensions().getFirstExtension(CollectingReporter.class, null).getReports();
        Assert.assertEquals(2, allReports.size());
        Assert.assertTrue(containsDifference(allReports, "class B", "class B", Code.MISSING_OLD_SUPERTYPE.code()));
        Assert.assertTrue(containsDifference(allReports, null, "class A", Code.CLASS_ADDED.code()));
    } finally {
        compilationPaths = new ArrayList<>(compilationPaths);
        if (v1 != null) {
            compilationPaths.add(v1.compilationPath);
        }
        if (v2 != null) {
            compilationPaths.add(v2.compilationPath);
        }
    }
}
Also used : Report(org.revapi.Report) API(org.revapi.API) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) AnalysisResult(org.revapi.AnalysisResult) Test(org.junit.Test)

Example 12 with Report

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

the class SupplementaryJarsTest method testExcludedClassesDontDragUsedTypesIntoAPI.

@Test
public void testExcludedClassesDontDragUsedTypesIntoAPI() 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\": \"class C {}\"}]}}}}").build();
    try (AnalysisResult res = revapi.analyze(ctx)) {
        res.throwIfFailed();
        allReports = res.getExtensions().getFirstExtension(CollectingReporter.class, null).getReports();
    }
    Assert.assertEquals(6, allReports.size());
    Assert.assertTrue(containsDifference(allReports, null, "class B.T$1.Private", Code.CLASS_NON_PUBLIC_PART_OF_API.code()));
    Assert.assertTrue(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.assertTrue(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 13 with Report

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

the class SupplementaryJarsTest method testSupplementaryJarsAreTakenIntoAccountWhenComputingAPI.

@Test
public void testSupplementaryJarsAreTakenIntoAccountWhenComputingAPI() 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()).build();
    try (AnalysisResult res = revapi.analyze(ctx)) {
        Assert.assertTrue(res.isSuccess());
        allReports = res.getExtensions().getFirstExtension(CollectingReporter.class, null).getReports();
    }
    Assert.assertEquals(8, allReports.size());
    Assert.assertTrue(containsDifference(allReports, null, "class B.T$1.Private", Code.CLASS_NON_PUBLIC_PART_OF_API.code()));
    Assert.assertTrue(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.assertTrue(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.assertTrue(containsDifference(allReports, "class B.UsedByIgnoredClass", "interface B.UsedByIgnoredClass", Code.CLASS_KIND_CHANGED.code()));
    Assert.assertTrue(containsDifference(allReports, "class B.UsedByIgnoredClass", "interface B.UsedByIgnoredClass", Code.CLASS_NOW_ABSTRACT.code()));
    Assert.assertTrue(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 14 with Report

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

the class JsonReporterTest method buildReports.

private List<Report> buildReports() {
    List<Report> ret = new ArrayList<>();
    Report report = Report.builder().withOld(new DummyElement("old2")).withNew(new DummyElement("new2")).addDifference().withCode("code2").withDescription("descr2").withName("name2").addClassification(CompatibilityType.BINARY, DifferenceSeverity.BREAKING).addAttachment("at2", "at2val").done().build();
    ret.add(report);
    report = Report.builder().withOld(new DummyElement("old1")).withNew(new DummyElement("new1")).addDifference().withCode("code1").withDescription("descr1").withName("name1").addClassification(CompatibilityType.SOURCE, DifferenceSeverity.BREAKING).addAttachment("at1", "at1val").done().build();
    ret.add(report);
    return ret;
}
Also used : Report(org.revapi.Report) ArrayList(java.util.ArrayList)

Example 15 with Report

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

the class BuildTimeReporterTest method testNoNonIdentifyingAttachmentsOutputIfConfigured.

@Test
public void testNoNonIdentifyingAttachmentsOutputIfConfigured() {
    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.OUTPUT_NON_IDENTIFYING_ATTACHMENTS, false).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).addAttachment("nonIdentifying", "{\"a\", \"b\"}").withCriticality(Criticality.ERROR).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.assertEquals(-1, commentStart);
    Assert.assertEquals(-1, commentEnd);
    Assert.assertEquals(-1, nonIdentifyingIndex);
}
Also used : Report(org.revapi.Report) API(org.revapi.API) AnalysisContext(org.revapi.AnalysisContext) 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