From 7c8bf48ebb3c2284ce63b4f057a56b178e836b0d Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Tue, 7 May 2019 20:26:30 +0900 Subject: [PATCH] Polish DevToolsEnablementDeducer and OnEnabledDevToolsCondition See gh-16732 --- ...Deducer.java => DevToolsEnablementDeducer.java} | 7 ++++--- .../DevToolsDataSourceAutoConfiguration.java | 2 +- ...dition.java => OnEnabledDevToolsCondition.java} | 7 ++++--- .../RemoteDevToolsAutoConfiguration.java | 2 +- .../env/DevToolsHomePropertiesPostProcessor.java | 4 ++-- .../env/DevToolsPropertyDefaultsPostProcessor.java | 4 ++-- .../restart/DefaultRestartInitializer.java | 4 ++-- ...s.java => OnEnabledDevToolsConditionTests.java} | 14 +++++++------- 8 files changed, 23 insertions(+), 21 deletions(-) rename spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/{DevtoolsEnablementDeducer.java => DevToolsEnablementDeducer.java} (91%) rename spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/{OnEnabledDevtoolsCondition.java => OnEnabledDevToolsCondition.java} (89%) rename spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/{OnEnabledDevtoolsConditionTests.java => OnEnabledDevToolsConditionTests.java} (81%) diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/DevtoolsEnablementDeducer.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/DevToolsEnablementDeducer.java similarity index 91% rename from spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/DevtoolsEnablementDeducer.java rename to spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/DevToolsEnablementDeducer.java index 85702fa1c6..e176ad58d3 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/DevtoolsEnablementDeducer.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/DevToolsEnablementDeducer.java @@ -21,11 +21,12 @@ import java.util.LinkedHashSet; import java.util.Set; /** - * Utility to deduce if Devtools should be enabled in the current context. + * Utility to deduce if DevTools should be enabled in the current context. * * @author Madhura Bhave + * @since 2.2.0 */ -public final class DevtoolsEnablementDeducer { +public final class DevToolsEnablementDeducer { private static final Set SKIPPED_STACK_ELEMENTS; @@ -38,7 +39,7 @@ public final class DevtoolsEnablementDeducer { SKIPPED_STACK_ELEMENTS = Collections.unmodifiableSet(skipped); } - private DevtoolsEnablementDeducer() { + private DevToolsEnablementDeducer() { } /** diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.java index e224606eed..97d7280e49 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.java @@ -55,7 +55,7 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; * @since 1.3.3 */ @AutoConfigureAfter(DataSourceAutoConfiguration.class) -@Conditional({ OnEnabledDevtoolsCondition.class, DevToolsDataSourceCondition.class }) +@Conditional({ OnEnabledDevToolsCondition.class, DevToolsDataSourceCondition.class }) @Configuration(proxyBeanMethods = false) public class DevToolsDataSourceAutoConfiguration { diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/OnEnabledDevtoolsCondition.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/OnEnabledDevToolsCondition.java similarity index 89% rename from spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/OnEnabledDevtoolsCondition.java rename to spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/OnEnabledDevToolsCondition.java index 29dba33ff4..9e6f2dadf8 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/OnEnabledDevtoolsCondition.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/OnEnabledDevToolsCondition.java @@ -19,7 +19,7 @@ package org.springframework.boot.devtools.autoconfigure; import org.springframework.boot.autoconfigure.condition.ConditionMessage; import org.springframework.boot.autoconfigure.condition.ConditionOutcome; import org.springframework.boot.autoconfigure.condition.SpringBootCondition; -import org.springframework.boot.devtools.DevtoolsEnablementDeducer; +import org.springframework.boot.devtools.DevToolsEnablementDeducer; import org.springframework.context.annotation.ConditionContext; import org.springframework.core.type.AnnotatedTypeMetadata; @@ -27,14 +27,15 @@ import org.springframework.core.type.AnnotatedTypeMetadata; * A condition that checks if DevTools should be enabled. * * @author Madhura Bhave + * @since 2.2.0 */ -public class OnEnabledDevtoolsCondition extends SpringBootCondition { +public class OnEnabledDevToolsCondition extends SpringBootCondition { @Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConditionMessage.Builder message = ConditionMessage.forCondition("Devtools"); - boolean shouldEnable = DevtoolsEnablementDeducer + boolean shouldEnable = DevToolsEnablementDeducer .shouldEnable(Thread.currentThread()); if (!shouldEnable) { return ConditionOutcome.noMatch( diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfiguration.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfiguration.java index e67fb41312..a0af3469ed 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfiguration.java @@ -56,7 +56,7 @@ import org.springframework.http.server.ServerHttpRequest; * @since 1.3.0 */ @Configuration(proxyBeanMethods = false) -@Conditional(OnEnabledDevtoolsCondition.class) +@Conditional(OnEnabledDevToolsCondition.class) @ConditionalOnProperty(prefix = "spring.devtools.remote", name = "secret") @ConditionalOnClass({ Filter.class, ServerHttpRequest.class }) @EnableConfigurationProperties({ ServerProperties.class, DevToolsProperties.class }) diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsHomePropertiesPostProcessor.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsHomePropertiesPostProcessor.java index aa248beb40..801cabfa25 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsHomePropertiesPostProcessor.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsHomePropertiesPostProcessor.java @@ -21,7 +21,7 @@ import java.io.IOException; import java.util.Properties; import org.springframework.boot.SpringApplication; -import org.springframework.boot.devtools.DevtoolsEnablementDeducer; +import org.springframework.boot.devtools.DevToolsEnablementDeducer; import org.springframework.boot.env.EnvironmentPostProcessor; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.PropertiesPropertySource; @@ -44,7 +44,7 @@ public class DevToolsHomePropertiesPostProcessor implements EnvironmentPostProce @Override public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { - if (DevtoolsEnablementDeducer.shouldEnable(Thread.currentThread())) { + if (DevToolsEnablementDeducer.shouldEnable(Thread.currentThread())) { File home = getHomeFolder(); File propertyFile = (home != null) ? new File(home, FILE_NAME) : null; if (propertyFile != null && propertyFile.exists() && propertyFile.isFile()) { diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java index 253ac6e5c8..3d6d55ccda 100755 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java @@ -23,7 +23,7 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.springframework.boot.SpringApplication; -import org.springframework.boot.devtools.DevtoolsEnablementDeducer; +import org.springframework.boot.devtools.DevToolsEnablementDeducer; import org.springframework.boot.devtools.logger.DevToolsLogFactory; import org.springframework.boot.devtools.restart.Restarter; import org.springframework.boot.env.EnvironmentPostProcessor; @@ -80,7 +80,7 @@ public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostPro @Override public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { - if (DevtoolsEnablementDeducer.shouldEnable(Thread.currentThread()) + if (DevToolsEnablementDeducer.shouldEnable(Thread.currentThread()) && isLocalApplication(environment)) { if (canAddProperties(environment)) { logger.info("Devtools property defaults active! Set '" + ENABLED diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/DefaultRestartInitializer.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/DefaultRestartInitializer.java index 0d241228d2..523b32c1a6 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/DefaultRestartInitializer.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/DefaultRestartInitializer.java @@ -18,7 +18,7 @@ package org.springframework.boot.devtools.restart; import java.net.URL; -import org.springframework.boot.devtools.DevtoolsEnablementDeducer; +import org.springframework.boot.devtools.DevToolsEnablementDeducer; /** * Default {@link RestartInitializer} that only enable initial restart when running a @@ -36,7 +36,7 @@ public class DefaultRestartInitializer implements RestartInitializer { if (!isMain(thread)) { return null; } - if (!DevtoolsEnablementDeducer.shouldEnable(thread)) { + if (!DevToolsEnablementDeducer.shouldEnable(thread)) { return null; } return getUrls(thread); diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/OnEnabledDevtoolsConditionTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/OnEnabledDevToolsConditionTests.java similarity index 81% rename from spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/OnEnabledDevtoolsConditionTests.java rename to spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/OnEnabledDevToolsConditionTests.java index 1b4055a6d4..2d7a2b5ba3 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/OnEnabledDevtoolsConditionTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/OnEnabledDevToolsConditionTests.java @@ -27,11 +27,11 @@ import org.springframework.context.annotation.Configuration; import static org.assertj.core.api.Assertions.assertThat; /** - * Tests for {@link OnEnabledDevtoolsCondition}. + * Tests for {@link OnEnabledDevToolsCondition}. * * @author Madhura Bhave */ -public class OnEnabledDevtoolsConditionTests { +public class OnEnabledDevToolsConditionTests { private AnnotationConfigApplicationContext context; @@ -44,8 +44,8 @@ public class OnEnabledDevtoolsConditionTests { @Test public void outcomeWhenDevtoolsShouldBeEnabledIsTrueShouldMatch() throws Exception { Thread thread = new Thread(() -> { - OnEnabledDevtoolsConditionTests.this.context.refresh(); - assertThat(OnEnabledDevtoolsConditionTests.this.context.containsBean("test")) + OnEnabledDevToolsConditionTests.this.context.refresh(); + assertThat(OnEnabledDevToolsConditionTests.this.context.containsBean("test")) .isTrue(); }); thread.start(); @@ -54,8 +54,8 @@ public class OnEnabledDevtoolsConditionTests { @Test public void outcomeWhenDevtoolsShouldBeEnabledIsFalseShouldNotMatch() { - OnEnabledDevtoolsConditionTests.this.context.refresh(); - assertThat(OnEnabledDevtoolsConditionTests.this.context.containsBean("test")) + OnEnabledDevToolsConditionTests.this.context.refresh(); + assertThat(OnEnabledDevToolsConditionTests.this.context.containsBean("test")) .isFalse(); } @@ -63,7 +63,7 @@ public class OnEnabledDevtoolsConditionTests { static class TestConfiguration { @Bean - @Conditional(OnEnabledDevtoolsCondition.class) + @Conditional(OnEnabledDevToolsCondition.class) public String test() { return "hello"; }