From 01c7623f5d4f7dfa491815affa8e121c097a2afb Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 2 Apr 2020 22:08:30 -0700 Subject: [PATCH] Polish --- .../boot/cloud/CloudPlatform.java | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudPlatform.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudPlatform.java index 43f77db4279..00b5fb811f2 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudPlatform.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudPlatform.java @@ -26,12 +26,6 @@ import org.springframework.core.env.StandardEnvironment; * Simple detection for well known cloud platforms. Detection can be forced using the * {@code "spring.main.cloud-platform"} configuration property. * - *

- * For more advanced cloud platform integration, consider using a platform-specific - * library such as Java CFEnv or - * Spring Cloud - * Kubernetes. - * * @author Phillip Webb * @author Brian Clozel * @since 1.3.0 @@ -44,7 +38,7 @@ public enum CloudPlatform { NONE { @Override - public boolean isAutoDetected(Environment environment) { + public boolean isDetected(Environment environment) { return false; } @@ -56,7 +50,7 @@ public enum CloudPlatform { CLOUD_FOUNDRY { @Override - public boolean isAutoDetected(Environment environment) { + public boolean isDetected(Environment environment) { return environment.containsProperty("VCAP_APPLICATION") || environment.containsProperty("VCAP_SERVICES"); } @@ -68,7 +62,7 @@ public enum CloudPlatform { HEROKU { @Override - public boolean isAutoDetected(Environment environment) { + public boolean isDetected(Environment environment) { return environment.containsProperty("DYNO"); } @@ -80,7 +74,7 @@ public enum CloudPlatform { SAP { @Override - public boolean isAutoDetected(Environment environment) { + public boolean isDetected(Environment environment) { return environment.containsProperty("HC_LANDSCAPE"); } @@ -100,7 +94,7 @@ public enum CloudPlatform { private static final String SERVICE_PORT_SUFFIX = "_SERVICE_PORT"; @Override - public boolean isAutoDetected(Environment environment) { + public boolean isDetected(Environment environment) { if (environment instanceof ConfigurableEnvironment) { return isAutoDetected((ConfigurableEnvironment) environment); } @@ -143,30 +137,29 @@ public enum CloudPlatform { * @return if the platform is active. */ 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. * @param environment the environment * @return if the platform is enforced + * @since 2.3.0 */ public boolean isEnforced(Environment environment) { String platform = environment.getProperty("spring.main.cloud-platform"); - if (platform != null) { - return this.name().equalsIgnoreCase(platform); - } - return false; + return (platform != null) ? this.name().equalsIgnoreCase(platform) : false; } /** - * Determines if the platform is auto-detected by looking for platform-specific - * environment variables. + * Determines if the platform is detected by looking for platform-specific environment + * variables. * @param environment the environment * @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