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