From 6b0ce464918d7f2515e9409706878a976d6e5a88 Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Fri, 1 Jun 2018 16:11:08 +0900 Subject: [PATCH] Polish Closes gh-13320 --- README.adoc | 2 +- .../jest/JestAutoConfiguration.java | 2 +- .../boot/devtools/restart/Restarter.java | 19 ++++++---- .../appendix-application-properties.adoc | 2 +- .../src/main/asciidoc/getting-started.adoc | 2 +- .../main/asciidoc/spring-boot-features.adoc | 6 ++-- .../boot/loader/jar/StringSequence.java | 6 ++-- .../config/ConfigFileApplicationListener.java | 15 ++++---- .../SampleTomcatDeployApplicationIT.java | 35 ++++++------------- 9 files changed, 42 insertions(+), 47 deletions(-) diff --git a/README.adoc b/README.adoc index 5c824aad0a..37836f50f0 100755 --- a/README.adoc +++ b/README.adoc @@ -223,7 +223,7 @@ This module contains core items and annotations that can be helpful when testing === spring-boot-test-autoconfigure -Like other Spring Boot Auto-Configuration modules, spring-boot-test-autoconfigure, provides auto-configuration +Like other Spring Boot auto-configuration modules, spring-boot-test-autoconfigure, provides auto-configuration for tests based on the classpath. It includes a number of annotations that can be used to automatically configure a slice of your application that needs to be tested. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/jest/JestAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/jest/JestAutoConfiguration.java index 1996ca5445..3c1a23ebd4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/jest/JestAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/jest/JestAutoConfiguration.java @@ -39,7 +39,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.util.Assert; /** - * {@link EnableAutoConfiguration Auto-Configuration} for Jest. + * {@link EnableAutoConfiguration Auto-configuration} for Jest. * * @author Stephane Nicoll * @since 1.4.0 diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java index 26f0a0a1a7..66e4582b6a 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java @@ -134,7 +134,9 @@ public class Restarter { Assert.notNull(thread, "Thread must not be null"); Assert.notNull(args, "Args must not be null"); Assert.notNull(initializer, "Initializer must not be null"); - this.logger.debug("Creating new Restarter for thread " + thread); + if (this.logger.isDebugEnabled()) { + this.logger.debug("Creating new Restarter for thread " + thread); + } SilentExitExceptionHandler.setup(thread); this.forceReferenceCleanup = forceReferenceCleanup; this.initialUrls = initializer.getInitialUrls(thread); @@ -360,7 +362,10 @@ public class Restarter { clear(Class.forName(className), fieldName); } catch (Exception ex) { - this.logger.debug("Unable to clear field " + className + " " + fieldName, ex); + if (this.logger.isDebugEnabled()) { + this.logger.debug("Unable to clear field " + className + " " + fieldName, + ex); + } } } @@ -377,15 +382,15 @@ public class Restarter { } } catch (Exception ex) { - this.logger.debug("Unable to clear field " + type + " " + fieldName, ex); + if (this.logger.isDebugEnabled()) { + this.logger.debug("Unable to clear field " + type + " " + fieldName, ex); + } } } private boolean isFromRestartClassLoader(Object object) { - if (object instanceof Class) { - return ((Class) object).getClassLoader() instanceof RestartClassLoader; - } - return false; + return (object instanceof Class + && ((Class) object).getClassLoader() instanceof RestartClassLoader); } /** diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 0ed694b6fd..702fd07aae 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -3,7 +3,7 @@ [[common-application-properties]] == Common application properties Various properties can be specified inside your `application.properties` file, inside -your `application.yml` file, or as command line switches. This appendix provides a list +your `application.yml` file, or as command line switches. This appendix provides a list of common Spring Boot properties and references to the underlying classes that consume them. diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc index 3921769e32..62bffbcab9 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc @@ -662,7 +662,7 @@ that you have added. Since `spring-boot-starter-web` added Tomcat and Spring MVC auto-configuration assumes that you are developing a web application and sets up Spring accordingly. -.Starters and Auto-Configuration +.Starters and Auto-configuration **** Auto-configuration is designed to work well with "`Starters`", but the two concepts are not directly tied. You are free to pick and choose jar dependencies outside of the diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index a95f2822ea..1682129759 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -2064,7 +2064,7 @@ directory locations). The root Servlet context path, `"/"`, is automatically add location as well. In addition to the "`standard`" static resource locations mentioned earlier, a special -case is made for http://www.webjars.org/[Webjars content]. Any resources with a path in +case is made for https://www.webjars.org/[Webjars content]. Any resources with a path in `+/webjars/**+` are served from jar files if they are packaged in the Webjars format. TIP: Do not use the `src/main/webapp` directory if your application is packaged as a jar. @@ -2625,7 +2625,7 @@ custom locations. So, if there is an `index.html` in any of your locations on st is the home page of the application. In addition to the "`standard`" static resource locations listed earlier, a special case -is made for http://www.webjars.org/[Webjars content]. Any resources with a path in +is made for https://www.webjars.org/[Webjars content]. Any resources with a path in `+/webjars/**+` are served from jar files if they are packaged in the Webjars format. TIP: Spring WebFlux applications do not strictly depend on the Servlet API, so they @@ -7227,7 +7227,7 @@ which auto-configures one for you. -[[boot-features-environment-test-utilities]] +[[boot-features-test-property-values]] ==== TestPropertyValues `TestPropertyValues` lets you quickly add properties to a `ConfigurableEnvironment` or `ConfigurableApplicationContext`. You can call it with diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/StringSequence.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/StringSequence.java index c298cf6886..85cf87bbe1 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/StringSequence.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/StringSequence.java @@ -99,11 +99,11 @@ final class StringSequence implements CharSequence { return startsWith(prefix, 0); } - public boolean startsWith(CharSequence prefix, int toffset) { - if (length() - prefix.length() - toffset < 0) { + public boolean startsWith(CharSequence prefix, int offset) { + if (length() - prefix.length() - offset < 0) { return false; } - return subSequence(toffset, toffset + prefix.length()).equals(prefix); + return subSequence(offset, offset + prefix.length()).equals(prefix); } @Override diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java index 44c01cbd55..b651e08b1f 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Deque; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedHashSet; @@ -301,7 +302,7 @@ public class ConfigFileApplicationListener private final List propertySourceLoaders; - private LinkedList profiles; + private Deque profiles; private List processedProfiles; @@ -345,9 +346,9 @@ public class ConfigFileApplicationListener // The default profile for these purposes is represented as null. We add it // first so that it is processed first and has lowest priority. this.profiles.add(null); - Set activatedViaProperty = getProfilesActivatedViaActiveProfileProperty(); + Set activatedViaProperty = getProfilesActivatedViaProperty(); processOtherActiveProfiles(activatedViaProperty); - // Any pre-existing active activeProfiles set via property sources (e.g. + // Any pre-existing active profiles set via property sources (e.g. // System // properties) take precedence over those added in config files. addActiveProfiles(activatedViaProperty); @@ -360,7 +361,7 @@ public class ConfigFileApplicationListener } } - private Set getProfilesActivatedViaActiveProfileProperty() { + private Set getProfilesActivatedViaProperty() { if (!this.environment.containsProperty(ACTIVE_PROFILES_PROPERTY) && !this.environment.containsProperty(INCLUDE_PROFILES_PROPERTY)) { return Collections.emptySet(); @@ -385,8 +386,10 @@ public class ConfigFileApplicationListener return; } addProfiles(profiles); - this.logger.debug("Activated activeProfiles " - + StringUtils.collectionToCommaDelimitedString(profiles)); + if (this.logger.isDebugEnabled()) { + this.logger.debug("Activated activeProfiles " + + StringUtils.collectionToCommaDelimitedString(profiles)); + } this.activatedProfiles = true; removeUnprocessedDefaultProfiles(); } diff --git a/spring-boot-tests/spring-boot-deployment-tests/spring-boot-deployment-test-tomcat/src/test/java/sample/SampleTomcatDeployApplicationIT.java b/spring-boot-tests/spring-boot-deployment-tests/spring-boot-deployment-test-tomcat/src/test/java/sample/SampleTomcatDeployApplicationIT.java index a4a0246075..db0d81ed3b 100644 --- a/spring-boot-tests/spring-boot-deployment-tests/spring-boot-deployment-test-tomcat/src/test/java/sample/SampleTomcatDeployApplicationIT.java +++ b/spring-boot-tests/spring-boot-deployment-tests/spring-boot-deployment-test-tomcat/src/test/java/sample/SampleTomcatDeployApplicationIT.java @@ -58,62 +58,49 @@ public class SampleTomcatDeployApplicationIT { @Test public void errorFromExceptionForRequestAcceptingAnythingProducesAJsonResponse() throws Exception { - assertThatErrorFromExceptionProducesExpectedResponse(MediaType.ALL, + assertThatPathProducesExpectedResponse("/bootapp/exception", MediaType.ALL, MediaType.APPLICATION_JSON); } @Test public void errorFromExceptionForRequestAcceptingJsonProducesAJsonResponse() throws Exception { - assertThatErrorFromExceptionProducesExpectedResponse(MediaType.APPLICATION_JSON, - MediaType.APPLICATION_JSON); + assertThatPathProducesExpectedResponse("/bootapp/exception", + MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON); } @Test public void errorFromExceptionForRequestAcceptingHtmlProducesAnHtmlResponse() throws Exception { - assertThatErrorFromExceptionProducesExpectedResponse(MediaType.TEXT_HTML, + assertThatPathProducesExpectedResponse("/bootapp/exception", MediaType.TEXT_HTML, MediaType.TEXT_HTML); } @Test public void sendErrorForRequestAcceptingAnythingProducesAJsonResponse() throws Exception { - assertThatSendErrorProducesExpectedResponse(MediaType.ALL, + assertThatPathProducesExpectedResponse("/bootapp/send-error", MediaType.ALL, MediaType.APPLICATION_JSON); } @Test public void sendErrorForRequestAcceptingJsonProducesAJsonResponse() throws Exception { - assertThatSendErrorProducesExpectedResponse(MediaType.APPLICATION_JSON, - MediaType.APPLICATION_JSON); + assertThatPathProducesExpectedResponse("/bootapp/send-error", + MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON); } @Test public void sendErrorForRequestAcceptingHtmlProducesAnHtmlResponse() throws Exception { - assertThatSendErrorProducesExpectedResponse(MediaType.TEXT_HTML, + assertThatPathProducesExpectedResponse("/bootapp/send-error", MediaType.TEXT_HTML, MediaType.TEXT_HTML); } - private void assertThatSendErrorProducesExpectedResponse(MediaType accept, - MediaType contentType) { - RequestEntity request = RequestEntity - .get(URI.create("http://localhost:" + this.port + "/bootapp/send-error")) - .accept(accept).build(); - ResponseEntity response = this.rest.exchange(request, String.class); - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); - assertThat(contentType.isCompatibleWith(response.getHeaders().getContentType())) - .as("%s is compatible with %s", contentType, - response.getHeaders().getContentType()) - .isTrue(); - } - - private void assertThatErrorFromExceptionProducesExpectedResponse(MediaType accept, + private void assertThatPathProducesExpectedResponse(String path, MediaType accept, MediaType contentType) { RequestEntity request = RequestEntity - .get(URI.create("http://localhost:" + this.port + "/bootapp/exception")) - .accept(accept).build(); + .get(URI.create("http://localhost:" + this.port + path)).accept(accept) + .build(); ResponseEntity response = this.rest.exchange(request, String.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); assertThat(contentType.isCompatibleWith(response.getHeaders().getContentType()))