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));
}
}
}
}
}
}
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;
}
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;
}
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;
}
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);
}
Aggregations