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);
}
}
}
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()));
}
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()));
}
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;
}
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);
}
Aggregations