Search in sources :

Example 1 with DefaultFileSystemResourceLoader

use of io.micronaut.core.io.file.DefaultFileSystemResourceLoader in project micronaut-core by micronaut-projects.

the class DefaultEnvironment method readPropertySourceList.

/**
 * @param name The name to resolver property sources
 * @return The list of property sources
 */
protected List<PropertySource> readPropertySourceList(String name) {
    List<PropertySource> propertySources = new ArrayList<>();
    for (String configLocation : configLocations) {
        ResourceLoader resourceLoader;
        if (configLocation.equals("classpath:/")) {
            resourceLoader = this;
        } else if (configLocation.startsWith("classpath:")) {
            resourceLoader = this.forBase(configLocation);
        } else if (configLocation.startsWith("file:")) {
            configLocation = configLocation.substring(5);
            Path configLocationPath = Paths.get(configLocation);
            if (Files.exists(configLocationPath) && Files.isDirectory(configLocationPath) && Files.isReadable(configLocationPath)) {
                resourceLoader = new DefaultFileSystemResourceLoader(configLocationPath);
            } else {
                // Skip not existing config location
                continue;
            }
        } else {
            throw new ConfigurationException("Unsupported config location format: " + configLocation);
        }
        readPropertySourceList(name, resourceLoader, propertySources);
    }
    return propertySources;
}
Also used : Path(java.nio.file.Path) DefaultFileSystemResourceLoader(io.micronaut.core.io.file.DefaultFileSystemResourceLoader) ResourceLoader(io.micronaut.core.io.ResourceLoader) FileSystemResourceLoader(io.micronaut.core.io.file.FileSystemResourceLoader) ClassPathResourceLoader(io.micronaut.core.io.scan.ClassPathResourceLoader) ConfigurationException(io.micronaut.context.exceptions.ConfigurationException) ArrayList(java.util.ArrayList) DefaultFileSystemResourceLoader(io.micronaut.core.io.file.DefaultFileSystemResourceLoader)

Example 2 with DefaultFileSystemResourceLoader

use of io.micronaut.core.io.file.DefaultFileSystemResourceLoader in project micronaut-maven-plugin by micronaut-projects.

the class ApplicationConfigurationService method parseApplicationConfiguration.

private Map<String, Object> parseApplicationConfiguration() {
    Map<String, Object> configuration = new HashMap<>();
    PropertySourceLoader[] loaders = { new YamlPropertySourceLoader(), new PropertiesPropertySourceLoader() };
    for (PropertySourceLoader loader : loaders) {
        Optional<PropertySource> propertySource = loader.load("application", new DefaultFileSystemResourceLoader(new File(mavenProject.getBasedir(), "src/main/resources")));
        if (propertySource.isPresent()) {
            MapPropertySource mapPropertySource = (MapPropertySource) propertySource.get();
            configuration.putAll(mapPropertySource.asMap());
        }
    }
    MapPropertySource[] propertySources = { new EnvironmentPropertySource(), new SystemPropertiesPropertySource() };
    for (MapPropertySource propertySource : propertySources) {
        configuration.putAll(propertySource.asMap());
    }
    return configuration;
}
Also used : HashMap(java.util.HashMap) YamlPropertySourceLoader(io.micronaut.context.env.yaml.YamlPropertySourceLoader) DefaultFileSystemResourceLoader(io.micronaut.core.io.file.DefaultFileSystemResourceLoader) YamlPropertySourceLoader(io.micronaut.context.env.yaml.YamlPropertySourceLoader) File(java.io.File)

Aggregations

DefaultFileSystemResourceLoader (io.micronaut.core.io.file.DefaultFileSystemResourceLoader)2 YamlPropertySourceLoader (io.micronaut.context.env.yaml.YamlPropertySourceLoader)1 ConfigurationException (io.micronaut.context.exceptions.ConfigurationException)1 ResourceLoader (io.micronaut.core.io.ResourceLoader)1 FileSystemResourceLoader (io.micronaut.core.io.file.FileSystemResourceLoader)1 ClassPathResourceLoader (io.micronaut.core.io.scan.ClassPathResourceLoader)1 File (java.io.File)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1