From 4d0da4b700c08bead46084da33d77131587ab60f Mon Sep 17 00:00:00 2001 From: Yuyan <845058547@qq.com> Date: Thu, 26 Sep 2019 19:09:28 -0700 Subject: [PATCH 1/2] Simplify code See gh-18342 --- .../boot/gradle/tasks/bundling/BootArchiveSupport.java | 4 ++-- .../tomcat/TomcatServletWebServerFactoryTests.java | 9 +-------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchiveSupport.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchiveSupport.java index 48b42b10a6..bf6a818d34 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchiveSupport.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchiveSupport.java @@ -143,8 +143,8 @@ class BootArchiveSupport { } private boolean isZip(InputStream inputStream) throws IOException { - for (int i = 0; i < ZIP_FILE_HEADER.length; i++) { - if (inputStream.read() != ZIP_FILE_HEADER[i]) { + for (byte b : ZIP_FILE_HEADER) { + if (inputStream.read() != b) { return false; } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java index 941120ff5f..2c138b96de 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java @@ -544,14 +544,7 @@ class TomcatServletWebServerFactoryTests extends AbstractServletWebServerFactory @Test void registerJspServletWithDefaultLoadOnStartup() { TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(0); - factory.addInitializers(new ServletContextInitializer() { - - @Override - public void onStartup(ServletContext servletContext) throws ServletException { - servletContext.addServlet("manually-registered-jsp-servlet", JspServlet.class); - } - - }); + factory.addInitializers(servletContext -> servletContext.addServlet("manually-registered-jsp-servlet", JspServlet.class)); this.webServer = factory.getWebServer(); this.webServer.start(); } From a13666d69619332ca8c4806f3777794183e7aeae Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 26 Sep 2019 19:12:18 -0700 Subject: [PATCH 2/2] Polish "Simplify code" See gh-18342 --- .../boot/gradle/tasks/bundling/BootArchiveSupport.java | 4 ++-- .../embedded/tomcat/TomcatServletWebServerFactoryTests.java | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchiveSupport.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchiveSupport.java index bf6a818d34..330b314398 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchiveSupport.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchiveSupport.java @@ -143,8 +143,8 @@ class BootArchiveSupport { } private boolean isZip(InputStream inputStream) throws IOException { - for (byte b : ZIP_FILE_HEADER) { - if (inputStream.read() != b) { + for (byte headerByte : ZIP_FILE_HEADER) { + if (inputStream.read() != headerByte) { return false; } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java index 2c138b96de..b8758a395a 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java @@ -68,7 +68,6 @@ import org.mockito.InOrder; import org.springframework.boot.testsupport.system.CapturedOutput; import org.springframework.boot.web.server.PortInUseException; import org.springframework.boot.web.server.WebServerException; -import org.springframework.boot.web.servlet.ServletContextInitializer; import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory; import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactoryTests; import org.springframework.core.io.ByteArrayResource; @@ -544,7 +543,7 @@ class TomcatServletWebServerFactoryTests extends AbstractServletWebServerFactory @Test void registerJspServletWithDefaultLoadOnStartup() { TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(0); - factory.addInitializers(servletContext -> servletContext.addServlet("manually-registered-jsp-servlet", JspServlet.class)); + factory.addInitializers((context) -> context.addServlet("manually-registered-jsp-servlet", JspServlet.class)); this.webServer = factory.getWebServer(); this.webServer.start(); }