use of org.springframework.core.env.EnumerablePropertySource in project jeesuite-libs by vakinge.
the class EnvironmentHelper method getAllProperties.
public static Map<String, Object> getAllProperties(String prefix) {
init();
if (environment == null)
return null;
MutablePropertySources propertySources = ((ConfigurableEnvironment) environment).getPropertySources();
Map<String, Object> properties = new LinkedHashMap<String, Object>();
for (PropertySource<?> source : propertySources) {
if (source.getName().startsWith("servlet") || source.getName().startsWith("system")) {
continue;
}
if (source instanceof EnumerablePropertySource) {
for (String name : ((EnumerablePropertySource<?>) source).getPropertyNames()) {
boolean match = StringUtils.isEmpty(prefix);
if (!match) {
match = name.startsWith(prefix);
}
if (match) {
Object value = source.getProperty(name);
if (value != null) {
properties.put(name, value);
}
}
}
}
}
return Collections.unmodifiableMap(properties);
}
use of org.springframework.core.env.EnumerablePropertySource in project spring-boot by spring-projects.
the class YamlPropertySourceLoaderTests method loadOriginAware.
@Test
void loadOriginAware() throws Exception {
Resource resource = new ClassPathResource("test-yaml.yml", getClass());
List<PropertySource<?>> loaded = this.loader.load("resource", resource);
for (PropertySource<?> source : loaded) {
EnumerablePropertySource<?> enumerableSource = (EnumerablePropertySource<?>) source;
for (String name : enumerableSource.getPropertyNames()) {
System.out.println(name + " = " + enumerableSource.getProperty(name));
}
}
}
use of org.springframework.core.env.EnumerablePropertySource in project spring-boot by spring-projects.
the class EnvironmentEndpoint method getEnvironmentDescriptor.
private EnvironmentDescriptor getEnvironmentDescriptor(Predicate<String> propertyNamePredicate) {
PlaceholdersResolver resolver = getResolver();
List<PropertySourceDescriptor> propertySources = new ArrayList<>();
getPropertySourcesAsMap().forEach((sourceName, source) -> {
if (source instanceof EnumerablePropertySource) {
propertySources.add(describeSource(sourceName, (EnumerablePropertySource<?>) source, resolver, propertyNamePredicate));
}
});
return new EnvironmentDescriptor(Arrays.asList(this.environment.getActiveProfiles()), propertySources);
}
use of org.springframework.core.env.EnumerablePropertySource in project CzechIdMng by bcvsolutions.
the class DefaultConfigurationService method getAllProperties.
private static Map<String, Object> getAllProperties(PropertySource<?> aPropSource) {
Map<String, Object> result = new HashMap<>();
if (aPropSource instanceof CompositePropertySource) {
CompositePropertySource cps = (CompositePropertySource) aPropSource;
cps.getPropertySources().forEach(ps -> addAll(result, getAllProperties(ps)));
return result;
}
if (aPropSource instanceof EnumerablePropertySource<?>) {
EnumerablePropertySource<?> ps = (EnumerablePropertySource<?>) aPropSource;
Arrays.asList(ps.getPropertyNames()).forEach(key -> result.put(key, ps.getProperty(key)));
return result;
}
return result;
}
use of org.springframework.core.env.EnumerablePropertySource in project incubator-dubbo-spring-boot-project by apache.
the class EnvironmentUtils method doExtraProperties.
// /**
// * Gets {@link PropertySource} Map , the {@link PropertySource#getName()} as key
// *
// * @param environment {@link ConfigurableEnvironment}
// * @return Read-only Map
// */
// public static Map<String, PropertySource<?>> getPropertySources(ConfigurableEnvironment environment) {
// return Collections.unmodifiableMap(doGetPropertySources(environment));
// }
private static Map<String, Object> doExtraProperties(ConfigurableEnvironment environment) {
// orderly
Map<String, Object> properties = new LinkedHashMap<>();
Map<String, PropertySource<?>> map = doGetPropertySources(environment);
for (PropertySource<?> source : map.values()) {
if (source instanceof EnumerablePropertySource) {
EnumerablePropertySource propertySource = (EnumerablePropertySource) source;
String[] propertyNames = propertySource.getPropertyNames();
if (ObjectUtils.isEmpty(propertyNames)) {
continue;
}
for (String propertyName : propertyNames) {
if (!properties.containsKey(propertyName)) {
// put If absent
properties.put(propertyName, propertySource.getProperty(propertyName));
}
}
}
}
return properties;
}
Aggregations