Skip to content

Commit 9ab1b66

Browse files
committed
Polish
1 parent fa6a146 commit 9ab1b66

File tree

5 files changed

+36
-33
lines changed

5 files changed

+36
-33
lines changed

spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/developing-web-applications.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ There are also several guides that cover Spring MVC available at https://spring.
4040
TIP: You can define as many `RouterFunction` beans as you like to modularize the definition of the router.
4141
Beans can be ordered if you need to apply a precedence.
4242

43+
44+
4345
[[features.developing-web-applications.spring-mvc.auto-configuration]]
4446
==== Spring MVC Auto-configuration
45-
4647
Spring Boot provides auto-configuration for Spring MVC that works well with most applications.
4748

4849
The auto-configuration adds the following features on top of Spring's defaults:

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/LogUpdateEvent.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.function.Consumer;
2323
import java.util.regex.Pattern;
2424

25+
import org.springframework.util.Assert;
2526
import org.springframework.util.StreamUtils;
2627

2728
/**
@@ -83,13 +84,8 @@ static void readAll(InputStream inputStream, Consumer<LogUpdateEvent> consumer)
8384
}
8485
}
8586
catch (IllegalStateException ex) {
86-
// Parsing has failed, abort further parsing
87-
LogUpdateEvent abortedEvent = new LogUpdateEvent(StreamType.STD_ERR,
88-
ex.getMessage().getBytes(StandardCharsets.UTF_8));
89-
consumer.accept(abortedEvent);
90-
91-
// At this point, the inputStream is burned, consume it fully to prevent
92-
// further processing
87+
byte[] message = ex.getMessage().getBytes(StandardCharsets.UTF_8);
88+
consumer.accept(new LogUpdateEvent(StreamType.STD_ERR, message));
9389
StreamUtils.drain(inputStream);
9490
}
9591
finally {
@@ -102,21 +98,12 @@ private static LogUpdateEvent read(InputStream inputStream) throws IOException {
10298
if (header == null) {
10399
return null;
104100
}
105-
106-
// First byte denotes stream type. 0 = stdin, 1 = stdout, 2 = stderr
107-
byte streamTypeId = header[0];
108-
if (streamTypeId < 0 || streamTypeId >= StreamType.values().length) {
109-
throw new IllegalStateException("Stream type is out of bounds. Must be >= 0 and < "
110-
+ StreamType.values().length + ", but was " + streamTypeId + ". Will abort parsing.");
111-
}
112-
101+
StreamType streamType = StreamType.forId(header[0]);
113102
long size = 0;
114103
for (int i = 0; i < 4; i++) {
115104
size = (size << 8) + (header[i + 4] & 0xff);
116105
}
117106
byte[] payload = read(inputStream, size);
118-
119-
StreamType streamType = StreamType.values()[streamTypeId];
120107
return new LogUpdateEvent(streamType, payload);
121108
}
122109

@@ -152,7 +139,14 @@ public enum StreamType {
152139
/**
153140
* Output to {@code stderr}.
154141
*/
155-
STD_ERR
142+
STD_ERR;
143+
144+
static StreamType forId(byte id) {
145+
int upperBound = values().length;
146+
Assert.state(id > 0 && id < upperBound,
147+
() -> "Stream type is out of bounds. Must be >= 0 and < " + upperBound + ", but was " + id);
148+
return values()[id];
149+
}
156150

157151
}
158152

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/LogUpdateEventTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ void readAllWhenAnsiStreamReturnsEvents() throws Exception {
5757
void readSucceedsWhenStreamTypeIsInvalid() throws IOException {
5858
List<LogUpdateEvent> events = readAll("log-update-event-invalid-stream-type.stream");
5959
assertThat(events).hasSize(1);
60-
assertThat(events.get(0).toString())
61-
.isEqualTo("Stream type is out of bounds. Must be >= 0 and < 3, but was 3. Will abort parsing.");
60+
assertThat(events.get(0).toString()).isEqualTo("Stream type is out of bounds. Must be >= 0 and < 3, but was 3");
6261
}
6362

6463
private List<LogUpdateEvent> readAll(String name) throws IOException {

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ApplicationPluginAction.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.gradle.api.GradleException;
2626
import org.gradle.api.Plugin;
2727
import org.gradle.api.Project;
28+
import org.gradle.api.artifacts.Configuration;
2829
import org.gradle.api.distribution.Distribution;
2930
import org.gradle.api.distribution.DistributionContainer;
3031
import org.gradle.api.file.CopySpec;
@@ -68,10 +69,7 @@ private void configureCreateStartScripts(Project project, ApplicationPluginConve
6869
.setTemplate(project.getResources().getText().fromString(loadResource("/windowsStartScript.txt")));
6970
project.getConfigurations().all((configuration) -> {
7071
if ("bootArchives".equals(configuration.getName())) {
71-
CopySpec libCopySpec = project.copySpec().into("lib")
72-
.from((Callable<FileCollection>) () -> configuration.getArtifacts().getFiles());
73-
libCopySpec.setFileMode(0644);
74-
distribution.getContents().with(libCopySpec);
72+
distribution.getContents().with(artifactFilesToLibCopySpec(project, configuration));
7573
createStartScripts.setClasspath(configuration.getArtifacts().getFiles());
7674
}
7775
});
@@ -82,6 +80,16 @@ private void configureCreateStartScripts(Project project, ApplicationPluginConve
8280
applicationConvention::getApplicationDefaultJvmArgs);
8381
}
8482

83+
private CopySpec artifactFilesToLibCopySpec(Project project, Configuration configuration) {
84+
CopySpec copySpec = project.copySpec().into("lib").from(artifactFiles(configuration));
85+
copySpec.setFileMode(0644);
86+
return copySpec;
87+
}
88+
89+
private Callable<FileCollection> artifactFiles(Configuration configuration) {
90+
return () -> configuration.getArtifacts().getFiles();
91+
}
92+
8593
@Override
8694
public Class<? extends Plugin<Project>> getPluginClass() {
8795
return ApplicationPlugin.class;

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void execute(Project project) {
8383
configureBootBuildImageTask(project, bootJar);
8484
configureArtifactPublication(bootJar);
8585
configureBootRunTask(project);
86-
configureUtf8Encoding(project);
86+
project.afterEvaluate(this::configureUtf8Encoding);
8787
configureParametersCompilerArg(project);
8888
configureAdditionalMetadataLocations(project);
8989
}
@@ -166,13 +166,14 @@ private JavaPluginConvention javaPluginConvention(Project project) {
166166
return project.getConvention().getPlugin(JavaPluginConvention.class);
167167
}
168168

169-
private void configureUtf8Encoding(Project project) {
170-
project.afterEvaluate(
171-
(evaluated) -> evaluated.getTasks().withType(JavaCompile.class).configureEach((compile) -> {
172-
if (compile.getOptions().getEncoding() == null) {
173-
compile.getOptions().setEncoding("UTF-8");
174-
}
175-
}));
169+
private void configureUtf8Encoding(Project evaluatedProject) {
170+
evaluatedProject.getTasks().withType(JavaCompile.class).configureEach(this::configureUtf8Encoding);
171+
}
172+
173+
private void configureUtf8Encoding(JavaCompile compile) {
174+
if (compile.getOptions().getEncoding() == null) {
175+
compile.getOptions().setEncoding("UTF-8");
176+
}
176177
}
177178

178179
private void configureParametersCompilerArg(Project project) {

0 commit comments

Comments
 (0)