|
|
|
@ -31,9 +31,6 @@ import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
import static java.lang.String.*; |
|
|
|
|
|
|
|
import static org.springframework.util.StringUtils.*; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Abstract base class for {@link Environment} implementations. Supports the notion of |
|
|
|
* Abstract base class for {@link Environment} implementations. Supports the notion of |
|
|
|
* reserved default profile names and enables specifying active and default profiles |
|
|
|
* reserved default profile names and enables specifying active and default profiles |
|
|
|
@ -124,7 +121,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { |
|
|
|
public AbstractEnvironment() { |
|
|
|
public AbstractEnvironment() { |
|
|
|
customizePropertySources(this.propertySources); |
|
|
|
customizePropertySources(this.propertySources); |
|
|
|
if (this.logger.isDebugEnabled()) { |
|
|
|
if (this.logger.isDebugEnabled()) { |
|
|
|
this.logger.debug(format( |
|
|
|
this.logger.debug(String.format( |
|
|
|
"Initialized %s with PropertySources %s", getClass().getSimpleName(), this.propertySources)); |
|
|
|
"Initialized %s with PropertySources %s", getClass().getSimpleName(), this.propertySources)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -242,7 +239,8 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { |
|
|
|
if (this.activeProfiles.isEmpty()) { |
|
|
|
if (this.activeProfiles.isEmpty()) { |
|
|
|
String profiles = getProperty(ACTIVE_PROFILES_PROPERTY_NAME); |
|
|
|
String profiles = getProperty(ACTIVE_PROFILES_PROPERTY_NAME); |
|
|
|
if (StringUtils.hasText(profiles)) { |
|
|
|
if (StringUtils.hasText(profiles)) { |
|
|
|
setActiveProfiles(commaDelimitedListToStringArray(trimAllWhitespace(profiles))); |
|
|
|
setActiveProfiles(StringUtils.commaDelimitedListToStringArray( |
|
|
|
|
|
|
|
StringUtils.trimAllWhitespace(profiles))); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return this.activeProfiles; |
|
|
|
return this.activeProfiles; |
|
|
|
@ -264,7 +262,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void addActiveProfile(String profile) { |
|
|
|
public void addActiveProfile(String profile) { |
|
|
|
if (this.logger.isDebugEnabled()) { |
|
|
|
if (this.logger.isDebugEnabled()) { |
|
|
|
this.logger.debug(format("Activating profile '%s'", profile)); |
|
|
|
this.logger.debug(String.format("Activating profile '%s'", profile)); |
|
|
|
} |
|
|
|
} |
|
|
|
validateProfile(profile); |
|
|
|
validateProfile(profile); |
|
|
|
doGetActiveProfiles(); |
|
|
|
doGetActiveProfiles(); |
|
|
|
@ -296,7 +294,8 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { |
|
|
|
if (this.defaultProfiles.equals(getReservedDefaultProfiles())) { |
|
|
|
if (this.defaultProfiles.equals(getReservedDefaultProfiles())) { |
|
|
|
String profiles = getProperty(DEFAULT_PROFILES_PROPERTY_NAME); |
|
|
|
String profiles = getProperty(DEFAULT_PROFILES_PROPERTY_NAME); |
|
|
|
if (StringUtils.hasText(profiles)) { |
|
|
|
if (StringUtils.hasText(profiles)) { |
|
|
|
setDefaultProfiles(commaDelimitedListToStringArray(trimAllWhitespace(profiles))); |
|
|
|
setDefaultProfiles(StringUtils.commaDelimitedListToStringArray( |
|
|
|
|
|
|
|
StringUtils.trimAllWhitespace(profiles))); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return this.defaultProfiles; |
|
|
|
return this.defaultProfiles; |
|
|
|
@ -393,7 +392,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { |
|
|
|
} |
|
|
|
} |
|
|
|
catch (AccessControlException ex) { |
|
|
|
catch (AccessControlException ex) { |
|
|
|
if (logger.isInfoEnabled()) { |
|
|
|
if (logger.isInfoEnabled()) { |
|
|
|
logger.info(format("Caught AccessControlException when accessing system " + |
|
|
|
logger.info(String.format("Caught AccessControlException when accessing system " + |
|
|
|
"environment variable [%s]; its value will be returned [null]. Reason: %s", |
|
|
|
"environment variable [%s]; its value will be returned [null]. Reason: %s", |
|
|
|
attributeName, ex.getMessage())); |
|
|
|
attributeName, ex.getMessage())); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -434,7 +433,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { |
|
|
|
} |
|
|
|
} |
|
|
|
catch (AccessControlException ex) { |
|
|
|
catch (AccessControlException ex) { |
|
|
|
if (logger.isInfoEnabled()) { |
|
|
|
if (logger.isInfoEnabled()) { |
|
|
|
logger.info(format("Caught AccessControlException when accessing system " + |
|
|
|
logger.info(String.format("Caught AccessControlException when accessing system " + |
|
|
|
"property [%s]; its value will be returned [null]. Reason: %s", |
|
|
|
"property [%s]; its value will be returned [null]. Reason: %s", |
|
|
|
attributeName, ex.getMessage())); |
|
|
|
attributeName, ex.getMessage())); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -569,7 +568,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String toString() { |
|
|
|
public String toString() { |
|
|
|
return format("%s {activeProfiles=%s, defaultProfiles=%s, propertySources=%s}", |
|
|
|
return String.format("%s {activeProfiles=%s, defaultProfiles=%s, propertySources=%s}", |
|
|
|
getClass().getSimpleName(), this.activeProfiles, this.defaultProfiles, |
|
|
|
getClass().getSimpleName(), this.activeProfiles, this.defaultProfiles, |
|
|
|
this.propertySources); |
|
|
|
this.propertySources); |
|
|
|
} |
|
|
|
} |
|
|
|
|