Search in sources :

Example 1 with PlaceholdersResolver

use of org.springframework.boot.context.properties.bind.PlaceholdersResolver in project spring-boot by spring-projects.

the class EnvironmentEndpoint method getPropertySourceDescriptors.

private Map<String, PropertyValueDescriptor> getPropertySourceDescriptors(String propertyName) {
    Map<String, PropertyValueDescriptor> propertySources = new LinkedHashMap<>();
    PlaceholdersResolver resolver = getResolver();
    getPropertySourcesAsMap().forEach((sourceName, source) -> propertySources.put(sourceName, source.containsProperty(propertyName) ? describeValueOf(propertyName, source, resolver) : null));
    return propertySources;
}
Also used : PlaceholdersResolver(org.springframework.boot.context.properties.bind.PlaceholdersResolver) PropertySourcesPlaceholdersResolver(org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with PlaceholdersResolver

use of org.springframework.boot.context.properties.bind.PlaceholdersResolver in project spring-boot by spring-projects.

the class ConfigDataEnvironment method getIncludedProfiles.

private Collection<? extends String> getIncludedProfiles(ConfigDataEnvironmentContributors contributors, ConfigDataActivationContext activationContext) {
    PlaceholdersResolver placeholdersResolver = new ConfigDataEnvironmentContributorPlaceholdersResolver(contributors, activationContext, null, true);
    Set<String> result = new LinkedHashSet<>();
    for (ConfigDataEnvironmentContributor contributor : contributors) {
        ConfigurationPropertySource source = contributor.getConfigurationPropertySource();
        if (source != null && !contributor.hasConfigDataOption(ConfigData.Option.IGNORE_PROFILES)) {
            Binder binder = new Binder(Collections.singleton(source), placeholdersResolver);
            binder.bind(Profiles.INCLUDE_PROFILES, STRING_LIST).ifBound((includes) -> {
                if (!contributor.isActive(activationContext)) {
                    InactiveConfigDataAccessException.throwIfPropertyFound(contributor, Profiles.INCLUDE_PROFILES);
                    InactiveConfigDataAccessException.throwIfPropertyFound(contributor, Profiles.INCLUDE_PROFILES.append("[0]"));
                }
                result.addAll(includes);
            });
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Binder(org.springframework.boot.context.properties.bind.Binder) PlaceholdersResolver(org.springframework.boot.context.properties.bind.PlaceholdersResolver) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource)

Example 3 with PlaceholdersResolver

use of org.springframework.boot.context.properties.bind.PlaceholdersResolver in project spring-boot by spring-projects.

the class ConfigDataEnvironmentContributor method withBoundProperties.

/**
 * Create a new {@link ConfigDataEnvironmentContributor} with bound
 * {@link ConfigDataProperties}.
 * @param contributors the contributors used for binding
 * @param activationContext the activation context
 * @return a new contributor instance
 */
ConfigDataEnvironmentContributor withBoundProperties(Iterable<ConfigDataEnvironmentContributor> contributors, ConfigDataActivationContext activationContext) {
    Iterable<ConfigurationPropertySource> sources = Collections.singleton(getConfigurationPropertySource());
    PlaceholdersResolver placeholdersResolver = new ConfigDataEnvironmentContributorPlaceholdersResolver(contributors, activationContext, this, true);
    Binder binder = new Binder(sources, placeholdersResolver, null, null, null);
    ConfigDataProperties properties = ConfigDataProperties.get(binder);
    if (properties != null && this.configDataOptions.contains(ConfigData.Option.IGNORE_IMPORTS)) {
        properties = properties.withoutImports();
    }
    return new ConfigDataEnvironmentContributor(Kind.BOUND_IMPORT, this.location, this.resource, this.fromProfileSpecificImport, this.propertySource, this.configurationPropertySource, properties, this.configDataOptions, null);
}
Also used : Binder(org.springframework.boot.context.properties.bind.Binder) PlaceholdersResolver(org.springframework.boot.context.properties.bind.PlaceholdersResolver) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource)

Example 4 with PlaceholdersResolver

use of org.springframework.boot.context.properties.bind.PlaceholdersResolver in project spring-boot by spring-projects.

the class ConfigDataEnvironmentContributors method getBinder.

private Binder getBinder(ConfigDataActivationContext activationContext, Predicate<ConfigDataEnvironmentContributor> filter, Set<BinderOption> options) {
    boolean failOnInactiveSource = options.contains(BinderOption.FAIL_ON_BIND_TO_INACTIVE_SOURCE);
    Iterable<ConfigurationPropertySource> sources = () -> getBinderSources(filter.and((contributor) -> failOnInactiveSource || contributor.isActive(activationContext)));
    PlaceholdersResolver placeholdersResolver = new ConfigDataEnvironmentContributorPlaceholdersResolver(this.root, activationContext, null, failOnInactiveSource);
    BindHandler bindHandler = !failOnInactiveSource ? null : new InactiveSourceChecker(activationContext);
    return new Binder(sources, placeholdersResolver, null, null, bindHandler);
}
Also used : Kind(org.springframework.boot.context.config.ConfigDataEnvironmentContributor.Kind) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) BindContext(org.springframework.boot.context.properties.bind.BindContext) Bindable(org.springframework.boot.context.properties.bind.Bindable) Arrays(java.util.Arrays) Iterator(java.util.Iterator) Predicate(java.util.function.Predicate) ConfigurableBootstrapContext(org.springframework.boot.ConfigurableBootstrapContext) ObjectUtils(org.springframework.util.ObjectUtils) Set(java.util.Set) Collectors(java.util.stream.Collectors) ImportPhase(org.springframework.boot.context.config.ConfigDataEnvironmentContributor.ImportPhase) ArrayList(java.util.ArrayList) LogMessage(org.springframework.core.log.LogMessage) List(java.util.List) PlaceholdersResolver(org.springframework.boot.context.properties.bind.PlaceholdersResolver) ConfigurationPropertyName(org.springframework.boot.context.properties.source.ConfigurationPropertyName) Map(java.util.Map) Log(org.apache.commons.logging.Log) Binder(org.springframework.boot.context.properties.bind.Binder) DeferredLogFactory(org.springframework.boot.logging.DeferredLogFactory) Collections(java.util.Collections) EnumSet(java.util.EnumSet) BindHandler(org.springframework.boot.context.properties.bind.BindHandler) Binder(org.springframework.boot.context.properties.bind.Binder) PlaceholdersResolver(org.springframework.boot.context.properties.bind.PlaceholdersResolver) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) BindHandler(org.springframework.boot.context.properties.bind.BindHandler)

Example 5 with PlaceholdersResolver

use of org.springframework.boot.context.properties.bind.PlaceholdersResolver 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);
}
Also used : EnumerablePropertySource(org.springframework.core.env.EnumerablePropertySource) PlaceholdersResolver(org.springframework.boot.context.properties.bind.PlaceholdersResolver) PropertySourcesPlaceholdersResolver(org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver) ArrayList(java.util.ArrayList)

Aggregations

PlaceholdersResolver (org.springframework.boot.context.properties.bind.PlaceholdersResolver)5 Binder (org.springframework.boot.context.properties.bind.Binder)3 ConfigurationPropertySource (org.springframework.boot.context.properties.source.ConfigurationPropertySource)3 ArrayList (java.util.ArrayList)2 PropertySourcesPlaceholdersResolver (org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 EnumSet (java.util.EnumSet)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Log (org.apache.commons.logging.Log)1 ConfigurableBootstrapContext (org.springframework.boot.ConfigurableBootstrapContext)1 ImportPhase (org.springframework.boot.context.config.ConfigDataEnvironmentContributor.ImportPhase)1 Kind (org.springframework.boot.context.config.ConfigDataEnvironmentContributor.Kind)1