|
|
|
@ -92,6 +92,8 @@ public class ConfigFileApplicationListener implements |
|
|
|
|
|
|
|
|
|
|
|
private static final String ACTIVE_PROFILES_PROPERTY = "spring.profiles.active"; |
|
|
|
private static final String ACTIVE_PROFILES_PROPERTY = "spring.profiles.active"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String INCLUDE_PROFILES_PROPERTY = "spring.profiles.include"; |
|
|
|
|
|
|
|
|
|
|
|
private static final String CONFIG_NAME_PROPERTY = "spring.config.name"; |
|
|
|
private static final String CONFIG_NAME_PROPERTY = "spring.config.name"; |
|
|
|
|
|
|
|
|
|
|
|
private static final String CONFIG_LOCATION_PROPERTY = "spring.config.location"; |
|
|
|
private static final String CONFIG_LOCATION_PROPERTY = "spring.config.location"; |
|
|
|
@ -274,9 +276,9 @@ public class ConfigFileApplicationListener implements |
|
|
|
|
|
|
|
|
|
|
|
if (this.environment.containsProperty(ACTIVE_PROFILES_PROPERTY)) { |
|
|
|
if (this.environment.containsProperty(ACTIVE_PROFILES_PROPERTY)) { |
|
|
|
// Any pre-existing active profiles set via property sources (e.g. System
|
|
|
|
// Any pre-existing active profiles set via property sources (e.g. System
|
|
|
|
// properties) take precedence over those added in config files (unless
|
|
|
|
// properties) take precedence over those added in config files.
|
|
|
|
// latter are prefixed with "+").
|
|
|
|
maybeActivateProfiles(this.environment |
|
|
|
addActiveProfiles(this.environment.getProperty(ACTIVE_PROFILES_PROPERTY)); |
|
|
|
.getProperty(ACTIVE_PROFILES_PROPERTY)); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
// Pre-existing active profiles set via Environment.setActiveProfiles()
|
|
|
|
// Pre-existing active profiles set via Environment.setActiveProfiles()
|
|
|
|
@ -330,36 +332,46 @@ public class ConfigFileApplicationListener implements |
|
|
|
PropertySource<?> propertySource = this.propertiesLoader.load(resource, |
|
|
|
PropertySource<?> propertySource = this.propertiesLoader.load(resource, |
|
|
|
name, profile); |
|
|
|
name, profile); |
|
|
|
if (propertySource != null) { |
|
|
|
if (propertySource != null) { |
|
|
|
addActiveProfiles(propertySource |
|
|
|
maybeActivateProfiles(propertySource |
|
|
|
.getProperty(ACTIVE_PROFILES_PROPERTY)); |
|
|
|
.getProperty(ACTIVE_PROFILES_PROPERTY)); |
|
|
|
|
|
|
|
addIncludeProfiles(propertySource |
|
|
|
|
|
|
|
.getProperty(INCLUDE_PROFILES_PROPERTY)); |
|
|
|
} |
|
|
|
} |
|
|
|
return propertySource; |
|
|
|
return propertySource; |
|
|
|
} |
|
|
|
} |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void addActiveProfiles(Object property) { |
|
|
|
private void maybeActivateProfiles(Object value) { |
|
|
|
String profiles = (property == null ? null : property.toString()); |
|
|
|
if (!this.activatedProfiles == true) { |
|
|
|
boolean profilesNotActivatedWhenCalled = !this.activatedProfiles; |
|
|
|
Set<String> profiles = getProfilesForValue(value); |
|
|
|
for (String profile : asResolvedSet(profiles, null)) { |
|
|
|
activateProfiles(profiles); |
|
|
|
// A profile name prefixed with "+" is always added even if it is
|
|
|
|
if (profiles.size() > 0) { |
|
|
|
// activated in a config file (without the "+" it can be disabled
|
|
|
|
|
|
|
|
// by an explicit Environment property set before the file was
|
|
|
|
|
|
|
|
// processed).
|
|
|
|
|
|
|
|
boolean addition = profile.startsWith("+"); |
|
|
|
|
|
|
|
profile = (addition ? profile.substring(1) : profile); |
|
|
|
|
|
|
|
if (profilesNotActivatedWhenCalled || addition) { |
|
|
|
|
|
|
|
this.profiles.add(profile); |
|
|
|
|
|
|
|
if (!this.environment.acceptsProfiles(profile)) { |
|
|
|
|
|
|
|
// If it's already accepted we assume the order was set
|
|
|
|
|
|
|
|
// intentionally
|
|
|
|
|
|
|
|
prependProfile(this.environment, profile); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.activatedProfiles = true; |
|
|
|
this.activatedProfiles = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void addIncludeProfiles(Object value) { |
|
|
|
|
|
|
|
Set<String> profiles = getProfilesForValue(value); |
|
|
|
|
|
|
|
activateProfiles(profiles); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Set<String> getProfilesForValue(Object property) { |
|
|
|
|
|
|
|
return asResolvedSet((property == null ? null : property.toString()), null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void activateProfiles(Set<String> profiles) { |
|
|
|
|
|
|
|
for (String profile : profiles) { |
|
|
|
|
|
|
|
this.profiles.add(profile); |
|
|
|
|
|
|
|
if (!this.environment.acceptsProfiles(profile)) { |
|
|
|
|
|
|
|
// If it's already accepted we assume the order was set
|
|
|
|
|
|
|
|
// intentionally
|
|
|
|
|
|
|
|
prependProfile(this.environment, profile); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void prependProfile(ConfigurableEnvironment environment, String profile) { |
|
|
|
private void prependProfile(ConfigurableEnvironment environment, String profile) { |
|
|
|
Set<String> profiles = new LinkedHashSet<String>(); |
|
|
|
Set<String> profiles = new LinkedHashSet<String>(); |
|
|
|
environment.getActiveProfiles(); // ensure they are initialized
|
|
|
|
environment.getActiveProfiles(); // ensure they are initialized
|
|
|
|
|