Commit 01c7623f authored by Phillip Webb's avatar Phillip Webb

Polish

parent 577bc1ce
...@@ -26,12 +26,6 @@ import org.springframework.core.env.StandardEnvironment; ...@@ -26,12 +26,6 @@ import org.springframework.core.env.StandardEnvironment;
* Simple detection for well known cloud platforms. Detection can be forced using the * Simple detection for well known cloud platforms. Detection can be forced using the
* {@code "spring.main.cloud-platform"} configuration property. * {@code "spring.main.cloud-platform"} configuration property.
* *
* <p>
* For more advanced cloud platform integration, consider using a platform-specific
* library such as <a href="https://github.com/pivotal-cf/java-cfenv">Java CFEnv</a> or
* <a href="https://spring.io/projects/spring-cloud-kubernetes">Spring Cloud
* Kubernetes</a>.
*
* @author Phillip Webb * @author Phillip Webb
* @author Brian Clozel * @author Brian Clozel
* @since 1.3.0 * @since 1.3.0
...@@ -44,7 +38,7 @@ public enum CloudPlatform { ...@@ -44,7 +38,7 @@ public enum CloudPlatform {
NONE { NONE {
@Override @Override
public boolean isAutoDetected(Environment environment) { public boolean isDetected(Environment environment) {
return false; return false;
} }
...@@ -56,7 +50,7 @@ public enum CloudPlatform { ...@@ -56,7 +50,7 @@ public enum CloudPlatform {
CLOUD_FOUNDRY { CLOUD_FOUNDRY {
@Override @Override
public boolean isAutoDetected(Environment environment) { public boolean isDetected(Environment environment) {
return environment.containsProperty("VCAP_APPLICATION") || environment.containsProperty("VCAP_SERVICES"); return environment.containsProperty("VCAP_APPLICATION") || environment.containsProperty("VCAP_SERVICES");
} }
...@@ -68,7 +62,7 @@ public enum CloudPlatform { ...@@ -68,7 +62,7 @@ public enum CloudPlatform {
HEROKU { HEROKU {
@Override @Override
public boolean isAutoDetected(Environment environment) { public boolean isDetected(Environment environment) {
return environment.containsProperty("DYNO"); return environment.containsProperty("DYNO");
} }
...@@ -80,7 +74,7 @@ public enum CloudPlatform { ...@@ -80,7 +74,7 @@ public enum CloudPlatform {
SAP { SAP {
@Override @Override
public boolean isAutoDetected(Environment environment) { public boolean isDetected(Environment environment) {
return environment.containsProperty("HC_LANDSCAPE"); return environment.containsProperty("HC_LANDSCAPE");
} }
...@@ -100,7 +94,7 @@ public enum CloudPlatform { ...@@ -100,7 +94,7 @@ public enum CloudPlatform {
private static final String SERVICE_PORT_SUFFIX = "_SERVICE_PORT"; private static final String SERVICE_PORT_SUFFIX = "_SERVICE_PORT";
@Override @Override
public boolean isAutoDetected(Environment environment) { public boolean isDetected(Environment environment) {
if (environment instanceof ConfigurableEnvironment) { if (environment instanceof ConfigurableEnvironment) {
return isAutoDetected((ConfigurableEnvironment) environment); return isAutoDetected((ConfigurableEnvironment) environment);
} }
...@@ -143,30 +137,29 @@ public enum CloudPlatform { ...@@ -143,30 +137,29 @@ public enum CloudPlatform {
* @return if the platform is active. * @return if the platform is active.
*/ */
public boolean isActive(Environment environment) { public boolean isActive(Environment environment) {
return isEnforced(environment) || isAutoDetected(environment); return isEnforced(environment) || isDetected(environment);
} }
/** /**
* Detemines if the platform is enforced by looking at the * Determines if the platform is enforced by looking at the
* {@code "spring.main.cloud-platform"} configuration property. * {@code "spring.main.cloud-platform"} configuration property.
* @param environment the environment * @param environment the environment
* @return if the platform is enforced * @return if the platform is enforced
* @since 2.3.0
*/ */
public boolean isEnforced(Environment environment) { public boolean isEnforced(Environment environment) {
String platform = environment.getProperty("spring.main.cloud-platform"); String platform = environment.getProperty("spring.main.cloud-platform");
if (platform != null) { return (platform != null) ? this.name().equalsIgnoreCase(platform) : false;
return this.name().equalsIgnoreCase(platform);
}
return false;
} }
/** /**
* Determines if the platform is auto-detected by looking for platform-specific * Determines if the platform is detected by looking for platform-specific environment
* environment variables. * variables.
* @param environment the environment * @param environment the environment
* @return if the platform is auto-detected. * @return if the platform is auto-detected.
* @since 2.3.0
*/ */
public abstract boolean isAutoDetected(Environment environment); public abstract boolean isDetected(Environment environment);
/** /**
* Returns if the platform is behind a load balancer and uses * Returns if the platform is behind a load balancer and uses
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment