From 9ab1b669d0171ba5d3d91f2adead75a862477d66 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 16 Feb 2022 17:56:07 -0800 Subject: [PATCH 1/2] Polish --- .../features/developing-web-applications.adoc | 3 +- .../platform/docker/LogUpdateEvent.java | 30 ++++++++----------- .../platform/docker/LogUpdateEventTests.java | 3 +- .../plugin/ApplicationPluginAction.java | 16 +++++++--- .../boot/gradle/plugin/JavaPluginAction.java | 17 ++++++----- 5 files changed, 36 insertions(+), 33 deletions(-) diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/developing-web-applications.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/developing-web-applications.adoc index c7d03a8353..c9acd27279 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/developing-web-applications.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/developing-web-applications.adoc @@ -40,9 +40,10 @@ There are also several guides that cover Spring MVC available at https://spring. TIP: You can define as many `RouterFunction` beans as you like to modularize the definition of the router. Beans can be ordered if you need to apply a precedence. + + [[features.developing-web-applications.spring-mvc.auto-configuration]] ==== Spring MVC Auto-configuration - Spring Boot provides auto-configuration for Spring MVC that works well with most applications. The auto-configuration adds the following features on top of Spring's defaults: diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/LogUpdateEvent.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/LogUpdateEvent.java index 9ed0483139..740b159a77 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/LogUpdateEvent.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/LogUpdateEvent.java @@ -22,6 +22,7 @@ import java.nio.charset.StandardCharsets; import java.util.function.Consumer; import java.util.regex.Pattern; +import org.springframework.util.Assert; import org.springframework.util.StreamUtils; /** @@ -83,13 +84,8 @@ public class LogUpdateEvent extends UpdateEvent { } } catch (IllegalStateException ex) { - // Parsing has failed, abort further parsing - LogUpdateEvent abortedEvent = new LogUpdateEvent(StreamType.STD_ERR, - ex.getMessage().getBytes(StandardCharsets.UTF_8)); - consumer.accept(abortedEvent); - - // At this point, the inputStream is burned, consume it fully to prevent - // further processing + byte[] message = ex.getMessage().getBytes(StandardCharsets.UTF_8); + consumer.accept(new LogUpdateEvent(StreamType.STD_ERR, message)); StreamUtils.drain(inputStream); } finally { @@ -102,21 +98,12 @@ public class LogUpdateEvent extends UpdateEvent { if (header == null) { return null; } - - // First byte denotes stream type. 0 = stdin, 1 = stdout, 2 = stderr - byte streamTypeId = header[0]; - if (streamTypeId < 0 || streamTypeId >= StreamType.values().length) { - throw new IllegalStateException("Stream type is out of bounds. Must be >= 0 and < " - + StreamType.values().length + ", but was " + streamTypeId + ". Will abort parsing."); - } - + StreamType streamType = StreamType.forId(header[0]); long size = 0; for (int i = 0; i < 4; i++) { size = (size << 8) + (header[i + 4] & 0xff); } byte[] payload = read(inputStream, size); - - StreamType streamType = StreamType.values()[streamTypeId]; return new LogUpdateEvent(streamType, payload); } @@ -152,7 +139,14 @@ public class LogUpdateEvent extends UpdateEvent { /** * Output to {@code stderr}. */ - STD_ERR + STD_ERR; + + static StreamType forId(byte id) { + int upperBound = values().length; + Assert.state(id > 0 && id < upperBound, + () -> "Stream type is out of bounds. Must be >= 0 and < " + upperBound + ", but was " + id); + return values()[id]; + } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/LogUpdateEventTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/LogUpdateEventTests.java index 577eb012dc..e8a6fc4297 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/LogUpdateEventTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/LogUpdateEventTests.java @@ -57,8 +57,7 @@ class LogUpdateEventTests { void readSucceedsWhenStreamTypeIsInvalid() throws IOException { List events = readAll("log-update-event-invalid-stream-type.stream"); assertThat(events).hasSize(1); - assertThat(events.get(0).toString()) - .isEqualTo("Stream type is out of bounds. Must be >= 0 and < 3, but was 3. Will abort parsing."); + assertThat(events.get(0).toString()).isEqualTo("Stream type is out of bounds. Must be >= 0 and < 3, but was 3"); } private List readAll(String name) throws IOException { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ApplicationPluginAction.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ApplicationPluginAction.java index 0c373d5b57..dd5017a68a 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ApplicationPluginAction.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ApplicationPluginAction.java @@ -25,6 +25,7 @@ import java.util.concurrent.Callable; import org.gradle.api.GradleException; import org.gradle.api.Plugin; import org.gradle.api.Project; +import org.gradle.api.artifacts.Configuration; import org.gradle.api.distribution.Distribution; import org.gradle.api.distribution.DistributionContainer; import org.gradle.api.file.CopySpec; @@ -68,10 +69,7 @@ final class ApplicationPluginAction implements PluginApplicationAction { .setTemplate(project.getResources().getText().fromString(loadResource("/windowsStartScript.txt"))); project.getConfigurations().all((configuration) -> { if ("bootArchives".equals(configuration.getName())) { - CopySpec libCopySpec = project.copySpec().into("lib") - .from((Callable) () -> configuration.getArtifacts().getFiles()); - libCopySpec.setFileMode(0644); - distribution.getContents().with(libCopySpec); + distribution.getContents().with(artifactFilesToLibCopySpec(project, configuration)); createStartScripts.setClasspath(configuration.getArtifacts().getFiles()); } }); @@ -82,6 +80,16 @@ final class ApplicationPluginAction implements PluginApplicationAction { applicationConvention::getApplicationDefaultJvmArgs); } + private CopySpec artifactFilesToLibCopySpec(Project project, Configuration configuration) { + CopySpec copySpec = project.copySpec().into("lib").from(artifactFiles(configuration)); + copySpec.setFileMode(0644); + return copySpec; + } + + private Callable artifactFiles(Configuration configuration) { + return () -> configuration.getArtifacts().getFiles(); + } + @Override public Class> getPluginClass() { return ApplicationPlugin.class; diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java index a9ea3fd4c9..8bfc275fe3 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java @@ -83,7 +83,7 @@ final class JavaPluginAction implements PluginApplicationAction { configureBootBuildImageTask(project, bootJar); configureArtifactPublication(bootJar); configureBootRunTask(project); - configureUtf8Encoding(project); + project.afterEvaluate(this::configureUtf8Encoding); configureParametersCompilerArg(project); configureAdditionalMetadataLocations(project); } @@ -166,13 +166,14 @@ final class JavaPluginAction implements PluginApplicationAction { return project.getConvention().getPlugin(JavaPluginConvention.class); } - private void configureUtf8Encoding(Project project) { - project.afterEvaluate( - (evaluated) -> evaluated.getTasks().withType(JavaCompile.class).configureEach((compile) -> { - if (compile.getOptions().getEncoding() == null) { - compile.getOptions().setEncoding("UTF-8"); - } - })); + private void configureUtf8Encoding(Project evaluatedProject) { + evaluatedProject.getTasks().withType(JavaCompile.class).configureEach(this::configureUtf8Encoding); + } + + private void configureUtf8Encoding(JavaCompile compile) { + if (compile.getOptions().getEncoding() == null) { + compile.getOptions().setEncoding("UTF-8"); + } } private void configureParametersCompilerArg(Project project) { From c86b1330cf5c2d7ff0d9303b6d132fb1e79baeac Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 16 Feb 2022 17:56:19 -0800 Subject: [PATCH 2/2] Update copyright year of changed files --- .../org/springframework/boot/build/AsciidoctorConventions.java | 2 +- .../springframework/boot/build/context/properties/Snippets.java | 2 +- .../springwebflux/MyRoutingConfiguration.java | 2 +- .../boot/gradle/junit/GradleCompatibilityExtension.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/AsciidoctorConventions.java b/buildSrc/src/main/java/org/springframework/boot/build/AsciidoctorConventions.java index 8c665f17e8..e041ae7703 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/AsciidoctorConventions.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/AsciidoctorConventions.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/buildSrc/src/main/java/org/springframework/boot/build/context/properties/Snippets.java b/buildSrc/src/main/java/org/springframework/boot/build/context/properties/Snippets.java index 35a310e3f7..0930b2f7fe 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/context/properties/Snippets.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/context/properties/Snippets.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/developingwebapplications/springwebflux/MyRoutingConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/developingwebapplications/springwebflux/MyRoutingConfiguration.java index 8250b430f5..c2e3fc745f 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/developingwebapplications/springwebflux/MyRoutingConfiguration.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/developingwebapplications/springwebflux/MyRoutingConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleCompatibilityExtension.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleCompatibilityExtension.java index 44ffcb74a0..1d8be4daf8 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleCompatibilityExtension.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleCompatibilityExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.