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();
}
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;
}
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);
}
}
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);
}
}
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();
}
}
Aggregations