Browse Source

Removes RelaxedPropertyResolver

pull/227/head
Spencer Gibb 8 years ago
parent
commit
c6c391158f
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 3
      spring-cloud-commons/src/main/java/org/springframework/cloud/client/circuitbreaker/EnableCircuitBreakerImportSelector.java
  2. 3
      spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/EnableDiscoveryClientImportSelector.java
  3. 12
      spring-cloud-commons/src/main/java/org/springframework/cloud/commons/util/IdUtils.java
  4. 2
      spring-cloud-commons/src/test/java/org/springframework/cloud/client/serviceregistry/AbstractAutoServiceRegistrationTests.java
  5. 6
      spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/PropertySourceBootstrapConfiguration.java
  6. 12
      spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/encrypt/EncryptionBootstrapConfiguration.java
  7. 44
      spring-cloud-context/src/main/java/org/springframework/cloud/env/EnvironmentUtils.java
  8. 6
      spring-cloud-context/src/main/java/org/springframework/cloud/logging/LoggingRebinder.java

3
spring-cloud-commons/src/main/java/org/springframework/cloud/client/circuitbreaker/EnableCircuitBreakerImportSelector.java

@ -16,7 +16,6 @@ @@ -16,7 +16,6 @@
package org.springframework.cloud.client.circuitbreaker;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.cloud.commons.util.SpringFactoryImportSelector;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
@ -31,7 +30,7 @@ public class EnableCircuitBreakerImportSelector extends @@ -31,7 +30,7 @@ public class EnableCircuitBreakerImportSelector extends
@Override
protected boolean isEnabled() {
return new RelaxedPropertyResolver(getEnvironment()).getProperty(
return getEnvironment().getProperty(
"spring.cloud.circuit.breaker.enabled", Boolean.class, Boolean.TRUE);
}

3
spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/EnableDiscoveryClientImportSelector.java

@ -16,7 +16,6 @@ @@ -16,7 +16,6 @@
package org.springframework.cloud.client.discovery;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.cloud.commons.util.SpringFactoryImportSelector;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.AnnotationAttributes;
@ -54,7 +53,7 @@ public class EnableDiscoveryClientImportSelector @@ -54,7 +53,7 @@ public class EnableDiscoveryClientImportSelector
@Override
protected boolean isEnabled() {
return new RelaxedPropertyResolver(getEnvironment()).getProperty(
return getEnvironment().getProperty(
"spring.cloud.discovery.enabled", Boolean.class, Boolean.TRUE);
}

12
spring-cloud-commons/src/main/java/org/springframework/cloud/commons/util/IdUtils.java

@ -1,6 +1,5 @@ @@ -1,6 +1,5 @@
package org.springframework.cloud.commons.util;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.core.env.PropertyResolver;
import org.springframework.util.StringUtils;
@ -12,19 +11,18 @@ public class IdUtils { @@ -12,19 +11,18 @@ public class IdUtils {
private static final String SEPARATOR = ":";
public static String getDefaultInstanceId(PropertyResolver resolver) {
RelaxedPropertyResolver relaxed = new RelaxedPropertyResolver(resolver);
String vcapInstanceId = relaxed.getProperty("vcap.application.instance_id");
String vcapInstanceId = resolver.getProperty("vcap.application.instance_id");
if (StringUtils.hasText(vcapInstanceId)) {
return vcapInstanceId;
}
String hostname = relaxed.getProperty("spring.cloud.client.hostname");
String appName = relaxed.getProperty("spring.application.name");
String hostname = resolver.getProperty("spring.cloud.client.hostname");
String appName = resolver.getProperty("spring.application.name");
String namePart = combineParts(hostname, SEPARATOR, appName);
String indexPart = relaxed.getProperty("spring.application.instance_id",
relaxed.getProperty("server.port"));
String indexPart = resolver.getProperty("spring.application.instance_id",
resolver.getProperty("server.port"));
return combineParts(namePart, SEPARATOR, indexPart);
}

2
spring-cloud-commons/src/test/java/org/springframework/cloud/client/serviceregistry/AbstractAutoServiceRegistrationTests.java

@ -7,8 +7,8 @@ import org.junit.runner.RunWith; @@ -7,8 +7,8 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.LocalManagementPort;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;

6
spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/PropertySourceBootstrapConfiguration.java

@ -29,7 +29,6 @@ import org.apache.commons.logging.LogFactory; @@ -29,7 +29,6 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.bind.PropertySourcesPropertyValues;
import org.springframework.boot.bind.RelaxedDataBinder;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.boot.context.config.ConfigFileApplicationListener;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.logging.LogFile;
@ -51,6 +50,8 @@ import org.springframework.core.env.StandardEnvironment; @@ -51,6 +50,8 @@ import org.springframework.core.env.StandardEnvironment;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
import static org.springframework.cloud.env.EnvironmentUtils.getSubProperties;
/**
* @author Dave Syer
*
@ -114,8 +115,7 @@ public class PropertySourceBootstrapConfiguration implements @@ -114,8 +115,7 @@ public class PropertySourceBootstrapConfiguration implements
private void reinitializeLoggingSystem(ConfigurableEnvironment environment,
String oldLogConfig, LogFile oldLogFile) {
Map<String, Object> props = new RelaxedPropertyResolver(environment)
.getSubProperties("logging.");
Map<String, Object> props = getSubProperties(environment, "logging.");
if (!props.isEmpty()) {
String logConfig = environment.resolvePlaceholders("${logging.config:}");
LogFile logFile = LogFile.get(environment);

12
spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/encrypt/EncryptionBootstrapConfiguration.java

@ -21,7 +21,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -21,7 +21,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.bootstrap.encrypt.KeyProperties.KeyStore;
import org.springframework.cloud.context.encrypt.EncryptorFactory;
@ -110,22 +109,21 @@ public class EncryptionBootstrapConfiguration { @@ -110,22 +109,21 @@ public class EncryptionBootstrapConfiguration {
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
Environment environment = context.getEnvironment();
RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver(environment);
if (hasProperty(propertyResolver, environment, "encrypt.keyStore.location")) {
if (hasProperty(propertyResolver, environment, "encrypt.keyStore.password")) {
if (hasProperty(environment, "encrypt.keyStore.location")) {
if (hasProperty(environment, "encrypt.keyStore.password")) {
return ConditionOutcome.match("Keystore found in Environment");
}
return ConditionOutcome
.noMatch("Keystore found but no password in Environment");
}
else if (hasProperty(propertyResolver, environment, "encrypt.key")) {
else if (hasProperty(environment, "encrypt.key")) {
return ConditionOutcome.match("Key found in Environment");
}
return ConditionOutcome.noMatch("Keystore nor key found in Environment");
}
private boolean hasProperty(RelaxedPropertyResolver propertyResolver, Environment environment, String key) {
String value = propertyResolver.getProperty(key);
private boolean hasProperty(Environment environment, String key) {
String value = environment.getProperty(key);
if (value == null) {
return false;
}

44
spring-cloud-context/src/main/java/org/springframework/cloud/env/EnvironmentUtils.java vendored

@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
package org.springframework.cloud.env;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.EnumerablePropertySource;
import org.springframework.core.env.Environment;
import org.springframework.core.env.PropertySource;
import org.springframework.core.env.PropertySources;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @author Spencer Gibb
*/
public class EnvironmentUtils {
public static Map<String, Object> getSubProperties(Environment environment, String keyPrefix) {
if (environment instanceof ConfigurableEnvironment) {
ConfigurableEnvironment env = (ConfigurableEnvironment) environment;
Map<String, Object> subProperties = new LinkedHashMap<>();
PropertySources propertySources = env.getPropertySources();
for (PropertySource<?> source : propertySources) {
if (source instanceof EnumerablePropertySource) {
for (String name : ((EnumerablePropertySource<?>) source)
.getPropertyNames()) {
String key = getSubKey(name, keyPrefix);
if (key != null && !subProperties.containsKey(key)) {
subProperties.put(key, source.getProperty(name));
}
}
}
}
return Collections.unmodifiableMap(subProperties);
}
return Collections.emptyMap();
}
private static String getSubKey(String name, String keyPrefix) {
if (name.startsWith(keyPrefix)) {
return name.substring(keyPrefix.length());
}
return null;
}
}

6
spring-cloud-context/src/main/java/org/springframework/cloud/logging/LoggingRebinder.java

@ -20,7 +20,6 @@ import java.util.Map.Entry; @@ -20,7 +20,6 @@ import java.util.Map.Entry;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.boot.logging.LogLevel;
import org.springframework.boot.logging.LoggingSystem;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
@ -28,6 +27,8 @@ import org.springframework.context.ApplicationListener; @@ -28,6 +27,8 @@ import org.springframework.context.ApplicationListener;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import static org.springframework.cloud.env.EnvironmentUtils.getSubProperties;
/**
* Listener that looks for {@link EnvironmentChangeEvent} and rebinds logger levels if any
* changed.
@ -57,8 +58,7 @@ public class LoggingRebinder @@ -57,8 +58,7 @@ public class LoggingRebinder
}
protected void setLogLevels(LoggingSystem system, Environment environment) {
Map<String, Object> levels = new RelaxedPropertyResolver(environment)
.getSubProperties("logging.level.");
Map<String, Object> levels = getSubProperties(environment, "logging.level.");
for (Entry<String, Object> entry : levels.entrySet()) {
setLogLevel(system, environment, entry.getKey(), entry.getValue().toString());
}

Loading…
Cancel
Save