Skip to content

Commit 2a2bfb9

Browse files
committed
Auto-generate the "Common application properties"
Prior to this commit, the application properties listed in the reference documentation would be manually managed and updated. This commit adds a new `spring-boot-configuration-docs` project that extracts that information from the available JSON metadata and writes Asciidoctor tables ready for inclusion in the reference documentation. The `generateConfigurationPropertyTables.groovy` is using this library and configures the sections and how namespaces should be organized. Fixes gh-8237
1 parent add8c6f commit 2a2bfb9

File tree

15 files changed

+892
-1549
lines changed

15 files changed

+892
-1549
lines changed

ci/pipeline.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ jobs:
192192
disable_checksum_uploads: true
193193
exclude:
194194
- "**/spring-boot-test-support/**"
195+
- "**/spring-boot-configuration-docs/**"
195196
- "**/*.effective-pom"
196197
artifact_set:
197198
- include:

spring-boot-project/spring-boot-docs/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
<groupId>org.springframework.boot</groupId>
5656
<artifactId>spring-boot-loader-tools</artifactId>
5757
</dependency>
58+
<dependency>
59+
<groupId>org.springframework.boot</groupId>
60+
<artifactId>spring-boot-configuration-docs</artifactId>
61+
<version>${revision}</version>
62+
</dependency>
5863
<dependency>
5964
<groupId>org.springframework.boot</groupId>
6065
<artifactId>spring-boot-test</artifactId>
@@ -1244,6 +1249,7 @@
12441249
<script>file:///${project.basedir}/src/main/groovy/generateAutoConfigurationClassTables.groovy</script>
12451250
<script>file:///${project.basedir}/src/main/groovy/generateStarterTables.groovy</script>
12461251
<script>file:///${project.basedir}/src/main/groovy/generateTestSlicesTable.groovy</script>
1252+
<script>file:///${project.basedir}/src/main/groovy/generateConfigurationPropertyTables.groovy</script>
12471253
</scripts>
12481254
</configuration>
12491255
<dependencies>

spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix/application-properties.adoc

Lines changed: 30 additions & 1549 deletions
Large diffs are not rendered by default.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import org.springframework.boot.configurationdocs.ConfigurationMetadataDocumentWriter
2+
import org.springframework.boot.configurationdocs.DocumentOptions
3+
import org.springframework.core.io.UrlResource
4+
5+
import java.nio.file.Path
6+
import java.nio.file.Paths
7+
8+
def getConfigMetadataInputStreams() {
9+
def mainMetadata = getClass().getClassLoader().getResources("META-INF/spring-configuration-metadata.json")
10+
def additionalMetadata = getClass().getClassLoader().getResources("META-INF/additional-spring-configuration-metadata.json")
11+
def streams = []
12+
streams += mainMetadata.collect { new UrlResource(it).getInputStream() }
13+
streams += additionalMetadata.collect { new UrlResource(it).getInputStream() }
14+
return streams
15+
}
16+
17+
def generateConfigMetadataDocumentation() {
18+
19+
def streams = getConfigMetadataInputStreams()
20+
try {
21+
Path outputPath = Paths.get(project.build.directory, 'generated-resources', 'config-docs')
22+
def builder = DocumentOptions.builder();
23+
24+
builder
25+
.addSection("core")
26+
.withKeyPrefixes("debug", "trace", "logging", "spring.aop", "spring.application",
27+
"spring.autoconfigure", "spring.banner", "spring.beaninfo", "spring.config",
28+
"spring.info", "spring.jmx", "spring.main", "spring.messages", "spring.pid",
29+
"spring.profiles", "spring.quartz", "spring.reactor", "spring.task",
30+
"spring.mandatory-file-encoding", "info", "spring.output.ansi.enabled")
31+
.addSection("mail")
32+
.withKeyPrefixes("spring.mail", "spring.sendgrid")
33+
.addSection("cache")
34+
.withKeyPrefixes("spring.cache")
35+
.addSection("server")
36+
.withKeyPrefixes("server")
37+
.addSection("web")
38+
.withKeyPrefixes("spring.hateoas",
39+
"spring.http", "spring.servlet", "spring.jersey",
40+
"spring.mvc", "spring.resources", "spring.webflux")
41+
.addSection("json")
42+
.withKeyPrefixes("spring.jackson", "spring.gson")
43+
.addSection("templating")
44+
.withKeyPrefixes("spring.freemarker", "spring.groovy", "spring.mustache", "spring.thymeleaf")
45+
.addOverride("spring.groovy.template.configuration", "See GroovyMarkupConfigurer")
46+
.addSection("security")
47+
.withKeyPrefixes("spring.security", "spring.ldap", "spring.session")
48+
.addSection("data-migration")
49+
.withKeyPrefixes("spring.flyway", "spring.liquibase")
50+
.addSection("data")
51+
.withKeyPrefixes("spring.couchbase", "spring.elasticsearch", "spring.h2",
52+
"spring.influx", "spring.mongodb", "spring.redis",
53+
"spring.dao", "spring.data", "spring.datasource", "spring.jooq",
54+
"spring.jdbc", "spring.jpa")
55+
.addOverride("spring.datasource.dbcp2", "Commons DBCP2 specific settings")
56+
.addOverride("spring.datasource.tomcat", "Tomcat datasource specific settings")
57+
.addOverride("spring.datasource.hikari", "Hikari specific settings")
58+
.addSection("transaction")
59+
.withKeyPrefixes("spring.jta", "spring.transaction")
60+
.addSection("integration")
61+
.withKeyPrefixes("spring.activemq", "spring.artemis", "spring.batch",
62+
"spring.integration", "spring.jms", "spring.kafka", "spring.rabbitmq", "spring.hazelcast",
63+
"spring.webservices")
64+
.addSection("actuator")
65+
.withKeyPrefixes("management")
66+
.addSection("devtools")
67+
.withKeyPrefixes("spring.devtools")
68+
.addSection("testing")
69+
.withKeyPrefixes("spring.test");
70+
71+
ConfigurationMetadataDocumentWriter writer = new ConfigurationMetadataDocumentWriter();
72+
writer.writeDocument(outputPath, builder.build(), streams.toArray(new InputStream[0]));
73+
}
74+
finally {
75+
streams.each { it.close() }
76+
}
77+
}
78+
79+
generateConfigMetadataDocumentation()

spring-boot-project/spring-boot-tools/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<modules>
1818
<module>spring-boot-antlib</module>
1919
<module>spring-boot-autoconfigure-processor</module>
20+
<module>spring-boot-configuration-docs</module>
2021
<module>spring-boot-configuration-metadata</module>
2122
<module>spring-boot-configuration-processor</module>
2223
<module>spring-boot-gradle-plugin</module>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>org.springframework.boot</groupId>
6+
<artifactId>spring-boot-tools</artifactId>
7+
<version>${revision}</version>
8+
</parent>
9+
<artifactId>spring-boot-configuration-docs</artifactId>
10+
<name>Spring Boot Configuration Docs</name>
11+
<description>Spring Boot Configuration Docs</description>
12+
<properties>
13+
<main.basedir>${basedir}/../../..</main.basedir>
14+
</properties>
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.springframework.boot</groupId>
18+
<artifactId>spring-boot-configuration-metadata</artifactId>
19+
</dependency>
20+
<dependency>
21+
<groupId>org.springframework.boot</groupId>
22+
<artifactId>spring-boot-test-support</artifactId>
23+
<scope>test</scope>
24+
</dependency>
25+
</dependencies>
26+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2012-2019 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+
* http://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.configurationdocs;
18+
19+
import java.util.Objects;
20+
21+
/**
22+
* Abstract class for entries in {@link ConfigurationTable}.
23+
*
24+
* @author Brian Clozel
25+
*/
26+
abstract class AbstractConfigurationEntry
27+
implements Comparable<AbstractConfigurationEntry> {
28+
29+
protected static final String NEWLINE = System.lineSeparator();
30+
31+
protected String key;
32+
33+
public String getKey() {
34+
return this.key;
35+
}
36+
37+
public abstract void writeAsciidoc(StringBuilder builder);
38+
39+
@Override
40+
public boolean equals(Object o) {
41+
if (this == o) {
42+
return true;
43+
}
44+
if (o == null || getClass() != o.getClass()) {
45+
return false;
46+
}
47+
AbstractConfigurationEntry that = (AbstractConfigurationEntry) o;
48+
return this.key.equals(that.key);
49+
}
50+
51+
@Override
52+
public int hashCode() {
53+
return Objects.hash(this.key);
54+
}
55+
56+
@Override
57+
public int compareTo(AbstractConfigurationEntry other) {
58+
return this.key.compareTo(other.getKey());
59+
}
60+
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2012-2019 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+
* http://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.configurationdocs;
18+
19+
import java.util.Set;
20+
import java.util.TreeSet;
21+
import java.util.stream.Stream;
22+
23+
import org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty;
24+
25+
/**
26+
* Table entry regrouping a list of configuration properties sharing the same description.
27+
*
28+
* @author Brian Clozel
29+
*/
30+
class CompoundKeyEntry extends AbstractConfigurationEntry {
31+
32+
private Set<String> configurationKeys;
33+
34+
private String description;
35+
36+
CompoundKeyEntry(String key, String description) {
37+
this.key = key;
38+
this.description = description;
39+
this.configurationKeys = new TreeSet<>();
40+
}
41+
42+
void addConfigurationKeys(ConfigurationMetadataProperty... properties) {
43+
Stream.of(properties)
44+
.forEach((property) -> this.configurationKeys.add(property.getId()));
45+
}
46+
47+
@Override
48+
public void writeAsciidoc(StringBuilder builder) {
49+
builder.append("|`+++");
50+
this.configurationKeys.forEach((key) -> builder.append(key).append(NEWLINE));
51+
builder.append("+++`").append(NEWLINE).append("|").append(NEWLINE).append("|+++")
52+
.append(this.description).append("+++").append(NEWLINE);
53+
}
54+
55+
}

0 commit comments

Comments
 (0)