Search in sources :

Example 21 with AnalysisContext

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()));
}
Also used : Revapi(org.revapi.Revapi) Report(org.revapi.Report) AnalysisContext(org.revapi.AnalysisContext) AnalysisResult(org.revapi.AnalysisResult) Test(org.junit.Test)

Example 22 with AnalysisContext

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);
    }
}
Also used : Revapi(org.revapi.Revapi) AnalysisContext(org.revapi.AnalysisContext) BuildException(org.apache.tools.ant.BuildException) AnalysisResult(org.revapi.AnalysisResult) MalformedURLException(java.net.MalformedURLException) BuildException(org.apache.tools.ant.BuildException)

Example 23 with AnalysisContext

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;
    }
}
Also used : Difference(org.revapi.Difference) AnalysisContext(org.revapi.AnalysisContext) Test(org.junit.Test)

Example 24 with AnalysisContext

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);
    }
}
Also used : Difference(org.revapi.Difference) AnalysisContext(org.revapi.AnalysisContext) Test(org.junit.Test)

Example 25 with AnalysisContext

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);
}
Also used : Revapi(org.revapi.Revapi) AnalysisContext(org.revapi.AnalysisContext) Test(org.junit.Test)

Aggregations

AnalysisContext (org.revapi.AnalysisContext)25 Test (org.junit.Test)15 Revapi (org.revapi.Revapi)13 Difference (org.revapi.Difference)7 API (org.revapi.API)6 AnalysisResult (org.revapi.AnalysisResult)6 Report (org.revapi.Report)6 ModelNode (org.jboss.dmr.ModelNode)4 File (java.io.File)3 PrintWriter (java.io.PrintWriter)3 Element (org.revapi.Element)3 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 Nonnull (javax.annotation.Nonnull)2 JavaModelElement (org.revapi.java.spi.JavaModelElement)2 FileArchive (org.revapi.simple.FileArchive)2 ClassTemplateLoader (freemarker.cache.ClassTemplateLoader)1 MultiTemplateLoader (freemarker.cache.MultiTemplateLoader)1 TemplateLoader (freemarker.cache.TemplateLoader)1 Configuration (freemarker.template.Configuration)1