Search in sources :

Example 6 with PropertySource

use of org.springframework.core.env.PropertySource in project grails-core by grails.

the class EnvironmentAwarePropertySource method initialize.

private void initialize() {
    if (propertyNames == null) {
        propertyNames = new ArrayList<>();
        Environment env = Environment.getCurrent();
        String key = "environments." + env.getName();
        for (PropertySource propertySource : source) {
            if ((propertySource != this) && // plugin default configuration is not allowed to be environment aware (GRAILS-12123)
            !propertySource.getName().contains("plugin") && propertySource instanceof EnumerablePropertySource) {
                EnumerablePropertySource enumerablePropertySource = (EnumerablePropertySource) propertySource;
                for (String propertyName : enumerablePropertySource.getPropertyNames()) {
                    if (propertyName.startsWith(key) && propertyName.length() > key.length()) {
                        propertyNames.add(propertyName.substring(key.length() + 1));
                    }
                }
            }
        }
    }
}
Also used : EnumerablePropertySource(org.springframework.core.env.EnumerablePropertySource) Environment(grails.util.Environment) PropertySource(org.springframework.core.env.PropertySource) EnumerablePropertySource(org.springframework.core.env.EnumerablePropertySource)

Example 7 with PropertySource

use of org.springframework.core.env.PropertySource in project grails-core by grails.

the class EnvironmentAwarePropertySource method getProperty.

@Override
public Object getProperty(String name) {
    initialize();
    if (!propertyNames.contains(name)) {
        return null;
    }
    Environment env = Environment.getCurrent();
    String key = "environments." + env.getName() + '.' + name;
    for (PropertySource propertySource : source) {
        if (propertySource != this) {
            Object value = propertySource.getProperty(key);
            if (value != null)
                return value;
        }
    }
    return null;
}
Also used : Environment(grails.util.Environment) PropertySource(org.springframework.core.env.PropertySource) EnumerablePropertySource(org.springframework.core.env.EnumerablePropertySource)

Example 8 with PropertySource

use of org.springframework.core.env.PropertySource in project spring-boot by spring-projects.

the class EnvironmentEndpoint method getPropertySourcesAsMap.

private Map<String, PropertySource<?>> getPropertySourcesAsMap() {
    Map<String, PropertySource<?>> map = new LinkedHashMap<String, PropertySource<?>>();
    MutablePropertySources sources = getPropertySources();
    for (PropertySource<?> source : sources) {
        extract("", map, source);
    }
    return map;
}
Also used : MutablePropertySources(org.springframework.core.env.MutablePropertySources) LinkedHashMap(java.util.LinkedHashMap) PropertySource(org.springframework.core.env.PropertySource) EnumerablePropertySource(org.springframework.core.env.EnumerablePropertySource) CompositePropertySource(org.springframework.core.env.CompositePropertySource)

Example 9 with PropertySource

use of org.springframework.core.env.PropertySource in project spring-boot by spring-projects.

the class EnvironmentEndpoint method invoke.

@Override
public Map<String, Object> invoke() {
    Map<String, Object> result = new LinkedHashMap<>();
    result.put("profiles", getEnvironment().getActiveProfiles());
    PropertyResolver resolver = getResolver();
    for (Entry<String, PropertySource<?>> entry : getPropertySourcesAsMap().entrySet()) {
        PropertySource<?> source = entry.getValue();
        String sourceName = entry.getKey();
        if (source instanceof EnumerablePropertySource) {
            EnumerablePropertySource<?> enumerable = (EnumerablePropertySource<?>) source;
            Map<String, Object> properties = new LinkedHashMap<>();
            for (String name : enumerable.getPropertyNames()) {
                properties.put(name, sanitize(name, resolver.getProperty(name)));
            }
            properties = postProcessSourceProperties(sourceName, properties);
            if (properties != null) {
                result.put(sourceName, properties);
            }
        }
    }
    return result;
}
Also used : EnumerablePropertySource(org.springframework.core.env.EnumerablePropertySource) PropertyResolver(org.springframework.core.env.PropertyResolver) PropertySourcesPropertyResolver(org.springframework.core.env.PropertySourcesPropertyResolver) LinkedHashMap(java.util.LinkedHashMap) PropertySource(org.springframework.core.env.PropertySource) EnumerablePropertySource(org.springframework.core.env.EnumerablePropertySource) CompositePropertySource(org.springframework.core.env.CompositePropertySource)

Example 10 with PropertySource

use of org.springframework.core.env.PropertySource in project libresonic by Libresonic.

the class LibresonicPropertySourceConfigurer method initialize.

public void initialize(ConfigurableWebApplicationContext ctx) {
    ApacheCommonsConfigurationService configurationService = new ApacheCommonsConfigurationService();
    ImmutableConfiguration snapshot = configurationService.getImmutableSnapshot();
    PropertySource ps = new CommonsConfigurationPropertySource("libresonic-pre-init-configs", snapshot);
    ctx.getEnvironment().getPropertySources().addLast(ps);
    addDataSourceProfile(ctx);
}
Also used : ApacheCommonsConfigurationService(org.libresonic.player.service.ApacheCommonsConfigurationService) ImmutableConfiguration(org.apache.commons.configuration2.ImmutableConfiguration) PropertySource(org.springframework.core.env.PropertySource)

Aggregations

PropertySource (org.springframework.core.env.PropertySource)11 EnumerablePropertySource (org.springframework.core.env.EnumerablePropertySource)5 CompositePropertySource (org.springframework.core.env.CompositePropertySource)4 LinkedHashMap (java.util.LinkedHashMap)3 MutablePropertySources (org.springframework.core.env.MutablePropertySources)3 Environment (grails.util.Environment)2 Test (org.junit.Test)2 PropertiesPropertySource (org.springframework.core.env.PropertiesPropertySource)2 Resource (org.springframework.core.io.Resource)2 MockPropertySource (org.springframework.mock.env.MockPropertySource)2 BitsquareEnvironment (io.bitsquare.app.BitsquareEnvironment)1 JOptCommandLinePropertySource (io.bitsquare.util.spring.JOptCommandLinePropertySource)1 File (java.io.File)1 Reader (java.io.Reader)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1