use of org.revapi.AnalysisResult in project revapi by revapi.
the class MissingClassReportingTest method testIgnoresMissingClasses.
@Test
public void testIgnoresMissingClasses() throws Exception {
AnalysisResult res = revapi.analyze(AnalysisContext.builder(revapi).withOldAPI(API.of(new ShrinkwrapArchive(apiV1)).build()).withNewAPI(API.of(new ShrinkwrapArchive(apiV2)).build()).withConfigurationFromJSON("{\"revapi\" : { \"java\" : { \"missing-classes\" : {\"behavior\" : \"ignore\" }}}}").build());
List<Report> allReports = res.getExtensions().getFirstExtension(CollectingReporter.class, null).getReports();
Assert.assertEquals(1, allReports.size());
Assert.assertTrue(containsDifference(allReports, null, "field A.f3", Code.FIELD_ADDED.code()));
}
use of org.revapi.AnalysisResult 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();
}
// 11 removed methods when kind of class changes to interface
Assert.assertEquals(8 + 11, 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_ADDED.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, "method void B.UsedByIgnoredClass::<init>()", null, Code.METHOD_REMOVED.code()));
// eleven methods removed when kind changed, because interface doesn't have the methods of Object
Assert.assertEquals(11, allReports.stream().filter(r -> {
javax.lang.model.element.TypeElement oldType = null;
if (r.getOldElement() == null || !(r.getOldElement() instanceof JavaModelElement)) {
return false;
}
javax.lang.model.element.Element old = ((JavaModelElement) r.getOldElement()).getDeclaringElement();
do {
if (old instanceof javax.lang.model.element.TypeElement) {
oldType = (javax.lang.model.element.TypeElement) old;
break;
}
old = old.getEnclosingElement();
} while (old != null);
if (oldType == null) {
return false;
}
return oldType.getQualifiedName().contentEquals("java.lang.Object");
}).flatMap(r -> r.getDifferences().stream()).count());
}
use of org.revapi.AnalysisResult 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\": {\"java\": {" + "\"filter\": {\"classes\": {\"exclude\": [\"C\"]}}}}}").build();
try (AnalysisResult res = revapi.analyze(ctx)) {
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_ADDED.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.AnalysisResult in project revapi by revapi.
the class CheckMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) {
return;
}
try (AnalysisResult res = analyze(BuildTimeReporter.class, BuildTimeReporter.BREAKING_SEVERITY_KEY, failSeverity.asDifferenceSeverity())) {
res.throwIfFailed();
BuildTimeReporter reporter = res.getExtensions().getFirstExtension(BuildTimeReporter.class, null);
if (reporter != null && reporter.hasBreakingProblems()) {
if (failBuildOnProblemsFound) {
throw new MojoFailureException(reporter.getAllProblemsMessage());
} else {
getLog().info("API problems found but letting the build pass as configured.");
}
} else {
getLog().info("API checks completed without failures.");
}
} catch (MojoFailureException e) {
throw e;
} catch (Exception e) {
throw new MojoExecutionException("Failed to execute the API analysis.", e);
}
}
use of org.revapi.AnalysisResult in project revapi by revapi.
the class ReportAggregateMojo method executeReport.
@Override
protected void executeReport(Locale locale) throws MavenReportException {
if (skip) {
return;
}
if (!canGenerateReport()) {
return;
}
List<MavenProject> dependents = mavenSession.getProjectDependencyGraph().getDownstreamProjects(project, true);
Collections.sort(dependents, (a, b) -> {
String as = a.getArtifact().toString();
String bs = b.getArtifact().toString();
return as.compareTo(bs);
});
Map<MavenProject, ProjectVersions> projectVersions = dependents.stream().collect(Collectors.toMap(Function.identity(), this::getRunConfig));
projectVersions.put(project, getRunConfig(project));
ResourceBundle messages = getBundle(locale);
Sink sink = getSink();
if (generateSiteReport) {
startReport(sink, messages);
}
try {
Analyzer topAnalyzer = prepareAnalyzer(null, project, locale, projectVersions.get(project));
Revapi sharedRevapi = topAnalyzer == null ? null : topAnalyzer.getRevapi();
for (MavenProject p : dependents) {
Analyzer projectAnalyzer = prepareAnalyzer(sharedRevapi, p, locale, projectVersions.get(p));
if (projectAnalyzer != null) {
try (AnalysisResult res = projectAnalyzer.analyze()) {
res.throwIfFailed();
ReportTimeReporter reporter = res.getExtensions().getFirstExtension(ReportTimeReporter.class, null);
if (generateSiteReport && reporter != null) {
reportBody(reporter, projectAnalyzer.getResolvedOldApi(), projectAnalyzer.getResolvedNewApi(), sink, messages);
}
}
}
}
if (generateSiteReport) {
endReport(sink);
}
} catch (Exception e) {
throw new MavenReportException("Failed to generate the report.", e);
}
}
Aggregations