use of org.revapi.AnalysisContext 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\": {\"java\": {" + "\"filter\": {\"classes\": {\"exclude\": [\"C\", \"B.T$2\"]}}}}}").build();
try (AnalysisResult res = revapi.analyze(ctx)) {
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_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.AnalysisContext in project revapi by revapi.
the class RevapiTask method execute.
@Override
public void execute() throws BuildException {
Revapi revapi = initRevapi();
AnalysisContext context = initAnalysisContext(revapi);
log("Running API analysis");
log("Old API: " + context.getOldApi().toString());
log("New API: " + context.getNewApi().toString());
try (AnalysisResult res = revapi.analyze(context)) {
res.throwIfFailed();
} catch (Exception e) {
throw new BuildException("API analysis failed.", e);
}
}
use of org.revapi.AnalysisContext in project revapi by revapi.
the class ClassificationTransformTest method test.
@Test
public void test() throws Exception {
DummyElement oldE = new DummyElement("old");
DummyElement newE = new DummyElement("new");
Difference difference = Difference.builder().withCode("code").addClassification(CompatibilityType.BINARY, DifferenceSeverity.NON_BREAKING).addClassification(CompatibilityType.SOURCE, DifferenceSeverity.POTENTIALLY_BREAKING).build();
AnalysisContext config = getAnalysisContextFromFullConfig(ClassificationTransform.class, "[{\"extension\": \"revapi.reclassify\", \"configuration\":[{\"code\":\"code\", \"classify\": {\"BINARY\" : \"BREAKING\"}}]}]");
try (ClassificationTransform t = new ClassificationTransform()) {
t.initialize(config);
difference = t.transform(oldE, newE, difference);
assert difference != null && difference.classification.get(CompatibilityType.BINARY) == DifferenceSeverity.BREAKING;
assert difference != null && difference.classification.get(CompatibilityType.SOURCE) == DifferenceSeverity.POTENTIALLY_BREAKING;
}
}
use of org.revapi.AnalysisContext in project revapi by revapi.
the class IgnoreDifferenceTransformTest method testRegexMatch.
@Test
public void testRegexMatch() throws Exception {
DummyElement oldE = new DummyElement("a");
DummyElement newE = new DummyElement("b");
Difference difference = Difference.builder().withCode("c").build();
try (IgnoreDifferenceTransform t = new IgnoreDifferenceTransform()) {
AnalysisContext config = getAnalysisContextFromFullConfig(IgnoreDifferenceTransform.class, "[{\"extension\": \"revapi.ignore\", \"configuration\": [{\"regex\": true, \"code\":\"c\", \"justification\" : \"because\"}]}]");
t.initialize(config);
difference = t.transform(oldE, newE, difference);
Assert.assertNull(difference);
}
}
use of org.revapi.AnalysisContext in project revapi by revapi.
the class ConfigurationValidatorTest method testRevapiValidation_mergeWithIds.
@Test
public void testRevapiValidation_mergeWithIds() throws Exception {
String config1 = "[" + "{\"extension\": \"my-config\", \"id\": \"c1\", \"configuration\": {\"id\": 3, \"kachna\": \"duck\"}}" + "]";
String config2 = "[" + "{\"extension\": \"my-config\", \"id\": \"c2\", \"configuration\": {\"id\": 4, \"kachna\": \"no duck\"}}," + "{\"extension\": \"other-config\", \"configuration\": 1}" + "]";
Revapi revapi = Revapi.builder().withFilters(TestFilter.class).withReporters(TestReporter.class).withAnalyzers(DummyApiAnalyzer.class).build();
AnalysisContext ctx = AnalysisContext.builder(revapi).withConfigurationFromJSON(config1).mergeConfigurationFromJSON(config2).build();
ValidationResult res = revapi.validateConfiguration(ctx);
Assert.assertFalse(res.isSuccessful());
Assert.assertNotNull(res.getErrors());
Assert.assertEquals(1, res.getErrors().length);
Assert.assertEquals("/[2]/configuration", res.getErrors()[0].dataPath);
}
Aggregations