Search in sources :

Example 1 with AOTModule

use of io.micronaut.aot.core.AOTModule in project micronaut-aot by micronaut-projects.

the class MicronautAotOptimizer method exportConfiguration.

/**
 * Scans the list of available optimization services and generates
 * a configuration file which includes all entries.
 *
 * @param runtime the runtime for which to generate a properties file
 * @param propertiesFile the generated properties file
 */
public static void exportConfiguration(String runtime, File propertiesFile) {
    List<AOTModule> list = SourceGeneratorLoader.list(Runtime.valueOf(runtime.toUpperCase(Locale.ENGLISH)));
    try (PrintWriter wrt = new PrintWriter(new FileOutputStream(propertiesFile))) {
        Deque<AOTModule> queue = new ArrayDeque<>(list);
        while (!queue.isEmpty()) {
            AOTModule generator = queue.pop();
            if (!generator.description().isEmpty()) {
                Arrays.stream(generator.description().split("\r?\n")).forEach(line -> wrt.println("# " + line));
            }
            wrt.println(generator.id() + ".enabled = true");
            Arrays.stream(generator.subgenerators()).map(MetadataUtils::findMetadata).filter(Optional::isPresent).map(Optional::get).sorted(Collections.reverseOrder()).forEachOrdered(queue::addFirst);
            for (Option option : generator.options()) {
                wrt.println(toPropertiesSample(option));
            }
            wrt.println();
        }
        // Add options which are generic to all AOT modules
        wrt.println("# " + Environments.TARGET_ENVIRONMENTS_DESCRIPTION);
        wrt.println(Environments.TARGET_ENVIRONMENTS_NAMES + " = " + Environments.TARGET_ENVIRONMENTS_SAMPLE);
    } catch (FileNotFoundException e) {
        throw new RuntimeException(e);
    }
}
Also used : Optional(java.util.Optional) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) Option(io.micronaut.aot.core.Option) AOTModule(io.micronaut.aot.core.AOTModule) MetadataUtils(io.micronaut.aot.core.config.MetadataUtils) ArrayDeque(java.util.ArrayDeque) PrintWriter(java.io.PrintWriter)

Aggregations

AOTModule (io.micronaut.aot.core.AOTModule)1 Option (io.micronaut.aot.core.Option)1 MetadataUtils (io.micronaut.aot.core.config.MetadataUtils)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 PrintWriter (java.io.PrintWriter)1 ArrayDeque (java.util.ArrayDeque)1 Optional (java.util.Optional)1