Search in sources :

Example 1 with Status

use of org.apiguardian.api.API.Status in project junit5 by junit-team.

the class ApiReportGenerator method generateReport.

// -------------------------------------------------------------------------
ApiReport generateReport(String... packages) {
    final Logger logger = LoggerFactory.getLogger(ApiReportGenerator.class);
    final String EOL = System.lineSeparator();
    // Scan packages
    ScanResult scanResult = new FastClasspathScanner(packages).scan();
    // Collect names
    List<String> names = new ArrayList<>();
    names.addAll(scanResult.getNamesOfClassesWithAnnotation(API.class));
    names.addAll(scanResult.getNamesOfAnnotationsWithMetaAnnotation(API.class));
    logger.debug(() -> {
        StringBuilder builder = new StringBuilder(names.size() + " @API declarations (including meta) found in class-path:");
        builder.append(EOL);
        scanResult.getUniqueClasspathElements().forEach(e -> builder.append(e).append(EOL));
        return builder.toString();
    });
    // Collect types
    List<Class<?>> types = scanResult.classNamesToClassRefs(names);
    // only retain directly annotated types
    types.removeIf(c -> !c.isAnnotationPresent(API.class));
    types.sort(Comparator.comparing(type -> type.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);
}
Also used : PrintWriter(java.io.PrintWriter) FastClasspathScanner(io.github.lukehutch.fastclasspathscanner.FastClasspathScanner) EnumMap(java.util.EnumMap) ScanResult(io.github.lukehutch.fastclasspathscanner.scanner.ScanResult) Logger(org.junit.platform.commons.logging.Logger) API(org.apiguardian.api.API) LoggerFactory(org.junit.platform.commons.logging.LoggerFactory) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Status(org.apiguardian.api.API.Status) Comparator(java.util.Comparator) EnumSet(java.util.EnumSet) Status(org.apiguardian.api.API.Status) ScanResult(io.github.lukehutch.fastclasspathscanner.scanner.ScanResult) FastClasspathScanner(io.github.lukehutch.fastclasspathscanner.FastClasspathScanner) ArrayList(java.util.ArrayList) Logger(org.junit.platform.commons.logging.Logger) API(org.apiguardian.api.API) ArrayList(java.util.ArrayList) List(java.util.List) EnumMap(java.util.EnumMap)

Aggregations

FastClasspathScanner (io.github.lukehutch.fastclasspathscanner.FastClasspathScanner)1 ScanResult (io.github.lukehutch.fastclasspathscanner.scanner.ScanResult)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 EnumMap (java.util.EnumMap)1 EnumSet (java.util.EnumSet)1 List (java.util.List)1 Map (java.util.Map)1 API (org.apiguardian.api.API)1 Status (org.apiguardian.api.API.Status)1 Logger (org.junit.platform.commons.logging.Logger)1 LoggerFactory (org.junit.platform.commons.logging.LoggerFactory)1