|
|
|
@ -18,13 +18,20 @@ package org.springframework.boot.context.config;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.LinkedHashSet;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.context.config.ConfigDataEnvironmentContributors.BinderOption;
|
|
|
|
|
import org.springframework.boot.context.properties.bind.BindException;
|
|
|
|
|
import org.springframework.boot.context.properties.bind.Bindable;
|
|
|
|
|
import org.springframework.boot.context.properties.bind.Binder;
|
|
|
|
|
import org.springframework.boot.context.properties.bind.PlaceholdersResolver;
|
|
|
|
|
import org.springframework.boot.context.properties.source.ConfigurationPropertyName;
|
|
|
|
|
import org.springframework.boot.context.properties.source.ConfigurationPropertySource;
|
|
|
|
|
import org.springframework.boot.env.BootstrapRegistry;
|
|
|
|
|
import org.springframework.boot.env.DefaultPropertiesPropertySource;
|
|
|
|
|
import org.springframework.boot.logging.DeferredLogFactory;
|
|
|
|
@ -74,6 +81,11 @@ class ConfigDataEnvironment {
|
|
|
|
|
|
|
|
|
|
private static final String[] EMPTY_LOCATIONS = new String[0];
|
|
|
|
|
|
|
|
|
|
private static final ConfigurationPropertyName INCLUDE_PROFILES = ConfigurationPropertyName
|
|
|
|
|
.of(Profiles.INCLUDE_PROFILES_PROPERTY_NAME);
|
|
|
|
|
|
|
|
|
|
private static final Bindable<List<String>> STRING_LIST = Bindable.listOf(String.class);
|
|
|
|
|
|
|
|
|
|
private final DeferredLogFactory logFactory;
|
|
|
|
|
|
|
|
|
|
private final Log logger;
|
|
|
|
@ -212,7 +224,9 @@ class ConfigDataEnvironment {
|
|
|
|
|
this.logger.trace("Deducing profiles from current config data environment contributors");
|
|
|
|
|
Binder binder = contributors.getBinder(activationContext, BinderOption.FAIL_ON_BIND_TO_INACTIVE_SOURCE);
|
|
|
|
|
try {
|
|
|
|
|
Profiles profiles = new Profiles(this.environment, binder, this.additionalProfiles);
|
|
|
|
|
Set<String> additionalProfiles = new LinkedHashSet<>(this.additionalProfiles);
|
|
|
|
|
additionalProfiles.addAll(getIncludedProfiles(contributors, activationContext));
|
|
|
|
|
Profiles profiles = new Profiles(this.environment, binder, additionalProfiles);
|
|
|
|
|
return activationContext.withProfiles(profiles);
|
|
|
|
|
}
|
|
|
|
|
catch (BindException ex) {
|
|
|
|
@ -223,6 +237,27 @@ class ConfigDataEnvironment {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Collection<? extends String> getIncludedProfiles(ConfigDataEnvironmentContributors contributors,
|
|
|
|
|
ConfigDataActivationContext activationContext) {
|
|
|
|
|
PlaceholdersResolver placeholdersResolver = new ConfigDataEnvironmentContributorPlaceholdersResolver(
|
|
|
|
|
contributors, activationContext, true);
|
|
|
|
|
Set<String> result = new LinkedHashSet<>();
|
|
|
|
|
for (ConfigDataEnvironmentContributor contributor : contributors) {
|
|
|
|
|
ConfigurationPropertySource source = contributor.getConfigurationPropertySource();
|
|
|
|
|
if (source == null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
Binder binder = new Binder(Collections.singleton(source), placeholdersResolver);
|
|
|
|
|
binder.bind(INCLUDE_PROFILES, STRING_LIST).ifBound((includes) -> {
|
|
|
|
|
if (!contributor.isActive(activationContext)) {
|
|
|
|
|
InactiveConfigDataAccessException.throwIfPropertyFound(contributor, INCLUDE_PROFILES);
|
|
|
|
|
}
|
|
|
|
|
result.addAll(includes);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ConfigDataEnvironmentContributors processWithProfiles(ConfigDataEnvironmentContributors contributors,
|
|
|
|
|
ConfigDataImporter importer, ConfigDataActivationContext activationContext) {
|
|
|
|
|
this.logger.trace("Processing config data environment contributors with profile activation context");
|
|
|
|
|