Search in sources :

Example 1 with AnalysisContext

use of org.revapi.AnalysisContext in project revapi by revapi.

the class JavaApiAnalyzer method initialize.

@Override
public void initialize(@Nonnull AnalysisContext analysisContext) {
    this.analysisContext = analysisContext;
    this.configuration = AnalysisConfiguration.fromModel(analysisContext.getConfiguration());
    for (Check c : checks) {
        if (c.getExtensionId() != null) {
            ModelNode checkConfig = analysisContext.getConfiguration().get("checks", c.getExtensionId());
            AnalysisContext checkCtx = analysisContext.copyWithConfiguration(checkConfig);
            c.initialize(checkCtx);
        }
    }
}
Also used : Check(org.revapi.java.spi.Check) AnalysisContext(org.revapi.AnalysisContext) ModelNode(org.jboss.dmr.ModelNode)

Example 2 with AnalysisContext

use of org.revapi.AnalysisContext in project revapi by revapi.

the class RevapiTask method initAnalysisContext.

private AnalysisContext initAnalysisContext(Revapi revapi) {
    API oldApi = API.of(FileArchive.from(oldArchives)).addSupportArchives(FileArchive.from(oldSupplementaryArchives)).build();
    API newApi = API.of(FileArchive.from(newArchives)).addSupportArchives(FileArchive.from(newSupplementaryArchives)).build();
    AnalysisContext.Builder builder = AnalysisContext.builder(revapi).withOldAPI(oldApi).withNewAPI(newApi).withLocale(Locale.getDefault());
    if (configuration != null) {
        builder.withConfigurationFromJSON(configuration);
    }
    builder.withData(AntReporter.ANT_REPORTER_LOGGER_KEY, this);
    builder.withData(AntReporter.MIN_SEVERITY_KEY, FailSeverity.valueOf(breakingSeverity).asDifferenceSeverity());
    return builder.build();
}
Also used : API(org.revapi.API) AnalysisContext(org.revapi.AnalysisContext)

Example 3 with AnalysisContext

use of org.revapi.AnalysisContext in project revapi by revapi.

the class SemverIgnoreTransformTest method getTestTransform.

private DifferenceTransform<Element> getTestTransform(String oldVersion, String newVersion, String configuration) {
    API oldApi = oldVersion != null ? API.of(new Ar(oldVersion)).build() : API.of().build();
    API newApi = newVersion != null ? API.of(new Ar(newVersion)).build() : API.of().build();
    AnalysisContext ctx = Util.setAnalysisContextFullConfig(AnalysisContext.builder().withOldAPI(oldApi).withNewAPI(newApi), SemverIgnoreTransform.class, configuration);
    SemverIgnoreTransform tr = new SemverIgnoreTransform();
    tr.initialize(ctx);
    return tr;
}
Also used : API(org.revapi.API) AnalysisContext(org.revapi.AnalysisContext)

Example 4 with AnalysisContext

use of org.revapi.AnalysisContext in project revapi by revapi.

the class IgnoreDifferenceTransformTest method testAttachmentMatch.

@Test
public void testAttachmentMatch() throws Exception {
    DummyElement oldE = new DummyElement("a");
    DummyElement newE = new DummyElement("b");
    Difference difference = Difference.builder().withCode("c").addAttachment("kachna", "nedobra").build();
    Difference anotherDiff = Difference.builder().withCode("d").build();
    Difference matchingDiff = Difference.builder().withCode("c").addAttachment("kachna", "dobra").build();
    try (IgnoreDifferenceTransform t = new IgnoreDifferenceTransform()) {
        AnalysisContext config = getAnalysisContextFromFullConfig(IgnoreDifferenceTransform.class, "[{\"extension\": \"revapi.ignore\", \"configuration\": [{\"code\":\"c\", \"kachna\": \"dobra\", \"justification\" : \"because\"}]}]");
        t.initialize(config);
        difference = t.transform(oldE, newE, difference);
        Assert.assertNotNull(difference);
        anotherDiff = t.transform(oldE, newE, anotherDiff);
        Assert.assertNotNull(anotherDiff);
        matchingDiff = t.transform(oldE, newE, matchingDiff);
        Assert.assertNull(matchingDiff);
    }
}
Also used : Difference(org.revapi.Difference) AnalysisContext(org.revapi.AnalysisContext) Test(org.junit.Test)

Example 5 with AnalysisContext

use of org.revapi.AnalysisContext in project revapi by revapi.

the class IgnoreDifferenceTransformTest method testSimpleTextMatch.

@Test
public void testSimpleTextMatch() 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\": [{\"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)

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