use of io.github.classgraph.ClassInfoList in project junit5 by junit-team.
the class ApiReportGenerator method generateReport.
// -------------------------------------------------------------------------
ApiReport generateReport(String... packages) {
Logger logger = LoggerFactory.getLogger(ApiReportGenerator.class);
String EOL = System.lineSeparator();
ClassGraph classGraph = //
new ClassGraph().acceptPackages(//
packages).disableNestedJarScanning().enableAnnotationInfo();
String apiClasspath = System.getProperty("api.classpath");
if (apiClasspath != null) {
classGraph = classGraph.overrideClasspath(apiClasspath);
}
// Scan packages
try (ScanResult scanResult = classGraph.scan()) {
// Collect names
ClassInfoList classesWithApiAnnotation = scanResult.getClassesWithAnnotation(API.class.getCanonicalName());
List<String> names = classesWithApiAnnotation.getNames();
logger.debug(() -> {
StringBuilder builder = new StringBuilder(names.size() + " @API declarations (including meta) found in class-path:");
builder.append(EOL);
scanResult.getClasspathURLs().forEach(e -> builder.append(e).append(EOL));
return builder.toString();
});
// Collect types
List<Class<?>> types = classesWithApiAnnotation.loadClasses();
// only retain directly annotated types
types.removeIf(c -> !c.isAnnotationPresent(API.class));
types.sort(Comparator.comparing(Class::getName));
logger.debug(() -> {
StringBuilder builder = new StringBuilder("Listing of all " + types.size() + " annotated types:");
builder.append(EOL);
types.forEach(e -> builder.append(e).append(EOL));
return builder.toString();
});
// Build map
Map<Status, List<Class<?>>> declarationsMap = new EnumMap<>(Status.class);
for (Status status : Status.values()) {
declarationsMap.put(status, new ArrayList<>());
}
types.forEach(type -> declarationsMap.get(type.getAnnotation(API.class).status()).add(type));
// Create report
return new ApiReport(types, declarationsMap);
}
}
Aggregations