Skip to content

Commit 4c1d1a6

Browse files
committed
Merge branch '2.5.x' into 2.6.x
Closes gh-30166
2 parents 7c3c5d3 + cced7ed commit 4c1d1a6

File tree

7 files changed

+154
-25
lines changed

7 files changed

+154
-25
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright 2012-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.build.devtools;
18+
19+
import java.io.FileInputStream;
20+
import java.io.FileNotFoundException;
21+
import java.io.FileWriter;
22+
import java.io.IOException;
23+
import java.io.PrintWriter;
24+
import java.util.HashMap;
25+
import java.util.Map;
26+
import java.util.Properties;
27+
import java.util.TreeMap;
28+
29+
import org.gradle.api.DefaultTask;
30+
import org.gradle.api.artifacts.Configuration;
31+
import org.gradle.api.file.FileCollection;
32+
import org.gradle.api.file.RegularFileProperty;
33+
import org.gradle.api.tasks.InputFiles;
34+
import org.gradle.api.tasks.OutputFile;
35+
import org.gradle.api.tasks.TaskAction;
36+
37+
/**
38+
* Task for documenting Devtools' property defaults.
39+
*
40+
* @author Andy Wilkinson
41+
*/
42+
public class DocumentDevtoolsPropertyDefaults extends DefaultTask {
43+
44+
private Configuration devtools;
45+
46+
private final RegularFileProperty outputFile;
47+
48+
public DocumentDevtoolsPropertyDefaults() {
49+
this.devtools = getProject().getConfigurations().create("devtools");
50+
this.outputFile = getProject().getObjects().fileProperty();
51+
this.outputFile.convention(getProject().getLayout().getBuildDirectory()
52+
.file("docs/generated/using/devtools-property-defaults.adoc"));
53+
Map<String, String> dependency = new HashMap<>();
54+
dependency.put("path", ":spring-boot-project:spring-boot-devtools");
55+
dependency.put("configuration", "propertyDefaults");
56+
this.devtools.getDependencies().add(getProject().getDependencies().project(dependency));
57+
}
58+
59+
@InputFiles
60+
public FileCollection getDevtools() {
61+
return this.devtools;
62+
}
63+
64+
@OutputFile
65+
public RegularFileProperty getOutputFile() {
66+
return this.outputFile;
67+
}
68+
69+
@TaskAction
70+
void documentPropertyDefaults() throws IOException {
71+
Map<String, String> properties = loadProperties();
72+
documentProperties(properties);
73+
}
74+
75+
private Map<String, String> loadProperties() throws IOException, FileNotFoundException {
76+
Properties properties = new Properties();
77+
Map<String, String> sortedProperties = new TreeMap<>();
78+
try (FileInputStream stream = new FileInputStream(this.devtools.getSingleFile())) {
79+
properties.load(stream);
80+
for (String name : properties.stringPropertyNames()) {
81+
sortedProperties.put(name, properties.getProperty(name));
82+
}
83+
}
84+
return sortedProperties;
85+
}
86+
87+
private void documentProperties(Map<String, String> properties) throws IOException {
88+
try (PrintWriter writer = new PrintWriter(new FileWriter(this.outputFile.getAsFile().get()))) {
89+
writer.println("[cols=\"3,1\"]");
90+
writer.println("|===");
91+
writer.println("| Name | Default Value");
92+
properties.forEach((name, value) -> {
93+
writer.println();
94+
writer.printf("| `%s`%n", name);
95+
writer.printf("| `%s`%n", value);
96+
});
97+
writer.println("|===");
98+
}
99+
}
100+
101+
}

spring-boot-project/spring-boot-devtools/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ configurations {
1313
intTestDependencies {
1414
extendsFrom dependencyManagement
1515
}
16+
propertyDefaults
17+
}
18+
19+
artifacts {
20+
propertyDefaults(file("build/resources/main/org/springframework/boot/devtools/env/devtools-property-defaults.properties")) {
21+
builtBy(processResources)
22+
}
1623
}
1724

1825
dependencies {

spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616

1717
package org.springframework.boot.devtools.env;
1818

19-
import java.util.Collections;
19+
import java.io.IOException;
20+
import java.io.InputStream;
2021
import java.util.HashMap;
2122
import java.util.Map;
23+
import java.util.Properties;
2224

2325
import org.apache.commons.logging.Log;
2426

@@ -60,23 +62,19 @@ public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostPro
6062
private static final Map<String, Object> PROPERTIES;
6163

6264
static {
63-
Map<String, Object> properties = new HashMap<>();
64-
properties.put("spring.thymeleaf.cache", "false");
65-
properties.put("spring.freemarker.cache", "false");
66-
properties.put("spring.groovy.template.cache", "false");
67-
properties.put("spring.mustache.cache", "false");
68-
properties.put("server.servlet.session.persistent", "true");
69-
properties.put("spring.h2.console.enabled", "true");
70-
properties.put("spring.web.resources.cache.period", "0");
71-
properties.put("spring.web.resources.chain.cache", "false");
72-
properties.put("spring.template.provider.cache", "false");
73-
properties.put("spring.mvc.log-resolved-exception", "true");
74-
properties.put("server.error.include-binding-errors", "ALWAYS");
75-
properties.put("server.error.include-message", "ALWAYS");
76-
properties.put("server.error.include-stacktrace", "ALWAYS");
77-
properties.put("server.servlet.jsp.init-parameters.development", "true");
78-
properties.put("spring.reactor.debug", "true");
79-
PROPERTIES = Collections.unmodifiableMap(properties);
65+
Properties properties = new Properties();
66+
try (InputStream stream = DevToolsPropertyDefaultsPostProcessor.class
67+
.getResourceAsStream("devtools-property-defaults.properties")) {
68+
properties.load(stream);
69+
}
70+
catch (IOException ex) {
71+
throw new RuntimeException("Failed to load devtools-property-defaults.properties", ex);
72+
}
73+
Map<String, Object> map = new HashMap<>();
74+
for (String name : properties.stringPropertyNames()) {
75+
map.put(name, properties.getProperty(name));
76+
}
77+
PROPERTIES = map;
8078
}
8179

8280
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
server.error.include-binding-errors=always
2+
server.error.include-message=always
3+
server.error.include-stacktrace=always
4+
server.servlet.jsp.init-parameters.development=true
5+
server.servlet.session.persistent=true
6+
spring.freemarker.cache=false
7+
spring.groovy.template.cache=false
8+
spring.h2.console.enabled=true
9+
spring.mustache.cache=false
10+
spring.mvc.log-resolved-exception=true
11+
spring.reactor.debug=true
12+
spring.template.provider.cache=false
13+
spring.thymeleaf.cache=false
14+
spring.web.resources.cache.period=0
15+
spring.web.resources.chain.cache=false

spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/env/DevToolPropertiesIntegrationTests.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import java.net.URL;
2020
import java.util.Collections;
21+
import java.util.Locale;
2122
import java.util.concurrent.atomic.AtomicReference;
2223
import java.util.function.Supplier;
2324

@@ -107,9 +108,11 @@ void postProcessEnablesIncludeStackTraceProperty() throws Exception {
107108
this.context = getContext(application::run);
108109
ConfigurableEnvironment environment = this.context.getEnvironment();
109110
String includeStackTrace = environment.getProperty("server.error.include-stacktrace");
110-
assertThat(includeStackTrace).isEqualTo(ErrorProperties.IncludeAttribute.ALWAYS.toString());
111+
assertThat(includeStackTrace)
112+
.isEqualTo(ErrorProperties.IncludeAttribute.ALWAYS.toString().toLowerCase(Locale.ENGLISH));
111113
String includeMessage = environment.getProperty("server.error.include-message");
112-
assertThat(includeMessage).isEqualTo(ErrorProperties.IncludeAttribute.ALWAYS.toString());
114+
assertThat(includeMessage)
115+
.isEqualTo(ErrorProperties.IncludeAttribute.ALWAYS.toString().toLowerCase(Locale.ENGLISH));
113116
}
114117

115118
protected ConfigurableApplicationContext getContext(Supplier<ConfigurableApplicationContext> supplier)

spring-boot-project/spring-boot-docs/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ task documentConfigurationProperties(type: org.springframework.boot.build.contex
249249
outputDir = file("${buildDir}/docs/generated/")
250250
}
251251

252+
task documentDevtoolsPropertyDefaults(type: org.springframework.boot.build.devtools.DocumentDevtoolsPropertyDefaults) {}
253+
252254
tasks.withType(org.asciidoctor.gradle.jvm.AbstractAsciidoctorTask) {
253255
dependsOn dependencyVersions
254256
asciidoctorj {
@@ -309,6 +311,7 @@ syncDocumentationSourceForAsciidoctor {
309311
dependsOn documentDependencyVersions
310312
dependsOn documentVersionProperties
311313
dependsOn documentConfigurationProperties
314+
dependsOn documentDevtoolsPropertyDefaults
312315
from("${buildDir}/docs/generated") {
313316
into "asciidoc"
314317
}

spring-boot-project/spring-boot-docs/src/docs/asciidoc/using/devtools.adoc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ Cache options are usually configured by settings in your `application.properties
6767
For example, Thymeleaf offers the configprop:spring.thymeleaf.cache[] property.
6868
Rather than needing to set these properties manually, the `spring-boot-devtools` module automatically applies sensible development-time configuration.
6969

70-
Because you need more information about web requests while developing Spring MVC and Spring WebFlux applications, developer tools suggests you to enable `DEBUG` logging for the `web` logging group.
71-
This will give you information about the incoming request, which handler is processing it, the response outcome, and other details.
72-
If you wish to log all request details (including potentially sensitive information), you can turn on the configprop:spring.mvc.log-request-details[] or configprop:spring.codec.log-request-details[] configuration properties.
70+
The following table lists all the properties that are applied:
71+
72+
include::devtools-property-defaults.adoc[]
7373

7474
NOTE: If you do not want property defaults to be applied you can set configprop:spring.devtools.add-properties[] to `false` in your `application.properties`.
7575

76-
TIP: For a complete list of the properties that are applied by the devtools, see {spring-boot-devtools-module-code}/env/DevToolsPropertyDefaultsPostProcessor.java[DevToolsPropertyDefaultsPostProcessor].
76+
Because you need more information about web requests while developing Spring MVC and Spring WebFlux applications, developer tools suggests you to enable `DEBUG` logging for the `web` logging group.
77+
This will give you information about the incoming request, which handler is processing it, the response outcome, and other details.
78+
If you wish to log all request details (including potentially sensitive information), you can turn on the configprop:spring.mvc.log-request-details[] or configprop:spring.codec.log-request-details[] configuration properties.
7779

7880

7981

0 commit comments

Comments
 (0)