Search in sources :

Example 1 with DefaultClassPathResourceLoader

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

the class YamlPropertySourceGenerator method createMapProperty.

private void createMapProperty(YamlPropertySourceLoader loader, AOTContext context, String resource) {
    Optional<PropertySource> optionalSource = loader.load(resource, new DefaultClassPathResourceLoader(this.getClass().getClassLoader()));
    if (optionalSource.isPresent()) {
        LOGGER.info("Converting {} into Java based configuration", resource + ".yml");
        context.registerExcludedResource(resource + ".yml");
        context.registerExcludedResource(resource + ".yaml");
        PropertySource ps = optionalSource.get();
        if (ps instanceof MapPropertySource) {
            MapPropertySource mps = (MapPropertySource) ps;
            Map<String, Object> values = mps.asMap();
            MapPropertySourceGenerator generator = new MapPropertySourceGenerator(resource, values);
            generator.generate(context);
        } else {
            throw new UnsupportedOperationException("Unknown property source type:" + ps.getClass());
        }
    }
}
Also used : MapPropertySource(io.micronaut.context.env.MapPropertySource) DefaultClassPathResourceLoader(io.micronaut.core.io.scan.DefaultClassPathResourceLoader) PropertySource(io.micronaut.context.env.PropertySource) MapPropertySource(io.micronaut.context.env.MapPropertySource)

Aggregations

MapPropertySource (io.micronaut.context.env.MapPropertySource)1 PropertySource (io.micronaut.context.env.PropertySource)1 DefaultClassPathResourceLoader (io.micronaut.core.io.scan.DefaultClassPathResourceLoader)1