Search in sources :

Example 1 with API

use of org.revapi.API 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 2 with API

use of org.revapi.API 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 3 with API

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

the class AnnotatedElementFilterTest method testWith.

private void testWith(String configJSON, Consumer<List<Element>> test) throws Exception {
    ArchiveAndCompilationPath archive = createCompiledJar("test.jar", "annotationfilter/NonPublic.java", "annotationfilter/NonPublicClass.java", "annotationfilter/Public.java", "annotationfilter/PublicClass.java", "annotationfilter/UndecisiveClass.java");
    try {
        JavaArchiveAnalyzer analyzer = new JavaArchiveAnalyzer(new API(Arrays.asList(new ShrinkwrapArchive(archive.archive)), null), Executors.newSingleThreadExecutor(), null, false, InclusionFilter.acceptAll());
        JavaElementForest forest = analyzer.analyze();
        AnnotatedElementFilter filter = new AnnotatedElementFilter();
        Revapi r = new Revapi(emptySet(), emptySet(), emptySet(), singleton(AnnotatedElementFilter.class));
        AnalysisContext ctx = AnalysisContext.builder(r).withConfigurationFromJSON(configJSON).build();
        AnalysisContext filterCtx = r.prepareAnalysis(ctx).getFirstConfigurationOrNull(AnnotatedElementFilter.class);
        filter.initialize(filterCtx);
        List<Element> results = forest.search(Element.class, true, filter, null);
        analyzer.getCompilationValve().removeCompiledResults();
        test.accept(results);
    } finally {
        deleteDir(archive.compilationPath);
    }
}
Also used : JavaElementForest(org.revapi.java.model.JavaElementForest) Revapi(org.revapi.Revapi) Element(org.revapi.Element) MethodParameterElement(org.revapi.java.model.MethodParameterElement) MethodElement(org.revapi.java.model.MethodElement) AnnotatedElement(java.lang.reflect.AnnotatedElement) API(org.revapi.API) AnalysisContext(org.revapi.AnalysisContext) AnnotatedElementFilter(org.revapi.java.filters.AnnotatedElementFilter)

Example 4 with API

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

the class ClassFilterTest method testWith.

static void testWith(ArchiveAndCompilationPath archive, String configJSON, Set<String> expectedResults) throws Exception {
    try {
        JavaApiAnalyzer apiAnalyzer = new JavaApiAnalyzer(Collections.emptyList());
        Revapi r = new Revapi(singleton(JavaApiAnalyzer.class), emptySet(), emptySet(), emptySet());
        AnalysisContext ctx = AnalysisContext.builder(r).withConfigurationFromJSON(configJSON).build();
        AnalysisContext analyzerCtx = r.prepareAnalysis(ctx).getFirstConfigurationOrNull(JavaApiAnalyzer.class);
        apiAnalyzer.initialize(analyzerCtx);
        ArchiveAnalyzer archiveAnalyzer = apiAnalyzer.getArchiveAnalyzer(new API(Collections.singletonList(new ShrinkwrapArchive(archive.archive)), null));
        ElementForest forest = archiveAnalyzer.analyze();
        List<Element> results = forest.search(Element.class, true, new AcceptingFilter(), null);
        ((JavaArchiveAnalyzer) archiveAnalyzer).getCompilationValve().removeCompiledResults();
        List<String> expected = new ArrayList<>(expectedResults);
        List<String> actual = results.stream().filter(e -> {
            if (e.getArchive() == null) {
                return false;
            }
            if (!(e instanceof JavaModelElement)) {
                // exclude annotations
                return false;
            }
            JavaModelElement el = (JavaModelElement) e;
            return !el.isInherited();
        }).map(Element::getFullHumanReadableString).collect(toList());
        Collections.sort(expected);
        Collections.sort(actual);
        Assert.assertEquals(expected, actual);
    } finally {
        deleteDir(archive.compilationPath);
    }
}
Also used : ElementForest(org.revapi.ElementForest) Revapi(org.revapi.Revapi) JavaModelElement(org.revapi.java.spi.JavaModelElement) JavaModelElement(org.revapi.java.spi.JavaModelElement) Element(org.revapi.Element) ArrayList(java.util.ArrayList) ArchiveAnalyzer(org.revapi.ArchiveAnalyzer) AnalysisContext(org.revapi.AnalysisContext) API(org.revapi.API)

Example 5 with API

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

the class JavaArchiveAnalyzerTest method testSimple.

@Test
public void testSimple() throws Exception {
    ArchiveAndCompilationPath archive = createCompiledJar("test.jar", "misc/A.java", "misc/B.java", "misc/C.java", "misc/D.java", "misc/I.java");
    JavaArchiveAnalyzer analyzer = new JavaArchiveAnalyzer(new API(Arrays.asList(new ShrinkwrapArchive(archive.archive)), null), Executors.newSingleThreadExecutor(), null, false, InclusionFilter.acceptAll());
    try {
        JavaElementForest forest = analyzer.analyze();
        Assert.assertEquals(6, forest.getRoots().size());
    } finally {
        deleteDir(archive.compilationPath);
        analyzer.getCompilationValve().removeCompiledResults();
    }
}
Also used : JavaElementForest(org.revapi.java.model.JavaElementForest) API(org.revapi.API) Test(org.junit.Test)

Aggregations

API (org.revapi.API)10 AnalysisContext (org.revapi.AnalysisContext)5 Test (org.junit.Test)4 Element (org.revapi.Element)4 JavaElementForest (org.revapi.java.model.JavaElementForest)4 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Iterator (java.util.Iterator)2 Set (java.util.Set)2 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)2 Revapi (org.revapi.Revapi)2 TypeElement (org.revapi.java.model.TypeElement)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 AnnotatedElement (java.lang.reflect.AnnotatedElement)1