17
17
package org .springframework .boot .build .context .properties ;
18
18
19
19
import java .io .IOException ;
20
+ import java .util .List ;
21
+ import java .util .Map ;
20
22
21
23
import org .gradle .api .DefaultTask ;
22
24
import org .gradle .api .Task ;
23
25
import org .gradle .api .file .DirectoryProperty ;
24
26
import org .gradle .api .file .FileCollection ;
27
+ import org .gradle .api .provider .ListProperty ;
28
+ import org .gradle .api .tasks .Input ;
25
29
import org .gradle .api .tasks .InputFiles ;
26
30
import org .gradle .api .tasks .OutputDirectory ;
27
31
import org .gradle .api .tasks .PathSensitive ;
28
32
import org .gradle .api .tasks .PathSensitivity ;
29
33
import org .gradle .api .tasks .TaskAction ;
30
34
31
- import org .springframework .boot .build .context .properties .Snippet .Config ;
32
-
33
35
/**
34
- * {@link Task} used to document auto- configuration classes .
36
+ * {@link Task} used to document configuration properties .
35
37
*
36
38
* @author Andy Wilkinson
37
39
* @author Phillip Webb
40
+ * @author Kim Tae Eun
38
41
*/
39
42
public abstract class DocumentConfigurationProperties extends DefaultTask {
40
43
@@ -53,176 +56,131 @@ public void setConfigurationPropertyMetadata(FileCollection configurationPropert
53
56
@ OutputDirectory
54
57
public abstract DirectoryProperty getOutputDir ();
55
58
59
+ @ Input
60
+ public abstract ListProperty <PropertySectionDefinition > getPropertySections ();
61
+
56
62
@ TaskAction
57
63
void documentConfigurationProperties () throws IOException {
58
64
Snippets snippets = new Snippets (this .configurationPropertyMetadata );
59
- snippets .add ("application-properties.core" , "Core Properties" , this ::corePrefixes );
60
- snippets .add ("application-properties.cache" , "Cache Properties" , this ::cachePrefixes );
61
- snippets .add ("application-properties.mail" , "Mail Properties" , this ::mailPrefixes );
62
- snippets .add ("application-properties.json" , "JSON Properties" , this ::jsonPrefixes );
63
- snippets .add ("application-properties.data" , "Data Properties" , this ::dataPrefixes );
64
- snippets .add ("application-properties.transaction" , "Transaction Properties" , this ::transactionPrefixes );
65
- snippets .add ("application-properties.data-migration" , "Data Migration Properties" , this ::dataMigrationPrefixes );
66
- snippets .add ("application-properties.integration" , "Integration Properties" , this ::integrationPrefixes );
67
- snippets .add ("application-properties.web" , "Web Properties" , this ::webPrefixes );
68
- snippets .add ("application-properties.templating" , "Templating Properties" , this ::templatePrefixes );
69
- snippets .add ("application-properties.server" , "Server Properties" , this ::serverPrefixes );
70
- snippets .add ("application-properties.security" , "Security Properties" , this ::securityPrefixes );
71
- snippets .add ("application-properties.rsocket" , "RSocket Properties" , this ::rsocketPrefixes );
72
- snippets .add ("application-properties.actuator" , "Actuator Properties" , this ::actuatorPrefixes );
73
- snippets .add ("application-properties.devtools" , "Devtools Properties" , this ::devtoolsPrefixes );
74
- snippets .add ("application-properties.docker-compose" , "Docker Compose Properties" , this ::dockerComposePrefixes );
75
- snippets .add ("application-properties.testcontainers" , "Testcontainers Properties" ,
76
- this ::testcontainersPrefixes );
77
- snippets .add ("application-properties.testing" , "Testing Properties" , this ::testingPrefixes );
78
- snippets .writeTo (getOutputDir ().getAsFile ().get ().toPath ());
79
- }
80
-
81
- private void corePrefixes (Config config ) {
82
- config .accept ("debug" );
83
- config .accept ("trace" );
84
- config .accept ("logging" );
85
- config .accept ("spring.aop" );
86
- config .accept ("spring.application" );
87
- config .accept ("spring.autoconfigure" );
88
- config .accept ("spring.banner" );
89
- config .accept ("spring.beaninfo" );
90
- config .accept ("spring.config" );
91
- config .accept ("spring.info" );
92
- config .accept ("spring.jmx" );
93
- config .accept ("spring.lifecycle" );
94
- config .accept ("spring.main" );
95
- config .accept ("spring.messages" );
96
- config .accept ("spring.pid" );
97
- config .accept ("spring.profiles" );
98
- config .accept ("spring.quartz" );
99
- config .accept ("spring.reactor" );
100
- config .accept ("spring.ssl" );
101
- config .accept ("spring.task" );
102
- config .accept ("spring.threads" );
103
- config .accept ("spring.validation" );
104
- config .accept ("spring.mandatory-file-encoding" );
105
- config .accept ("info" );
106
- config .accept ("spring.output.ansi.enabled" );
107
- }
108
-
109
- private void cachePrefixes (Config config ) {
110
- config .accept ("spring.cache" );
111
- }
112
-
113
- private void mailPrefixes (Config config ) {
114
- config .accept ("spring.mail" );
115
- config .accept ("spring.sendgrid" );
116
- }
117
-
118
- private void jsonPrefixes (Config config ) {
119
- config .accept ("spring.jackson" );
120
- config .accept ("spring.gson" );
121
- }
122
-
123
- private void dataPrefixes (Config config ) {
124
- config .accept ("spring.couchbase" );
125
- config .accept ("spring.cassandra" );
126
- config .accept ("spring.elasticsearch" );
127
- config .accept ("spring.h2" );
128
- config .accept ("spring.influx" );
129
- config .accept ("spring.ldap" );
130
- config .accept ("spring.mongodb" );
131
- config .accept ("spring.neo4j" );
132
- config .accept ("spring.dao" );
133
- config .accept ("spring.data" );
134
- config .accept ("spring.datasource" );
135
- config .accept ("spring.jooq" );
136
- config .accept ("spring.jdbc" );
137
- config .accept ("spring.jpa" );
138
- config .accept ("spring.r2dbc" );
139
- config .accept ("spring.datasource.oracleucp" ,
140
- "Oracle UCP specific settings bound to an instance of Oracle UCP's PoolDataSource" );
141
- config .accept ("spring.datasource.dbcp2" ,
142
- "Commons DBCP2 specific settings bound to an instance of DBCP2's BasicDataSource" );
143
- config .accept ("spring.datasource.tomcat" ,
144
- "Tomcat datasource specific settings bound to an instance of Tomcat JDBC's DataSource" );
145
- config .accept ("spring.datasource.hikari" ,
146
- "Hikari specific settings bound to an instance of Hikari's HikariDataSource" );
147
-
148
- }
149
-
150
- private void transactionPrefixes (Config prefix ) {
151
- prefix .accept ("spring.jta" );
152
- prefix .accept ("spring.transaction" );
153
- }
154
-
155
- private void dataMigrationPrefixes (Config prefix ) {
156
- prefix .accept ("spring.flyway" );
157
- prefix .accept ("spring.liquibase" );
158
- prefix .accept ("spring.sql.init" );
159
- }
160
-
161
- private void integrationPrefixes (Config prefix ) {
162
- prefix .accept ("spring.activemq" );
163
- prefix .accept ("spring.artemis" );
164
- prefix .accept ("spring.batch" );
165
- prefix .accept ("spring.integration" );
166
- prefix .accept ("spring.jms" );
167
- prefix .accept ("spring.kafka" );
168
- prefix .accept ("spring.pulsar" );
169
- prefix .accept ("spring.rabbitmq" );
170
- prefix .accept ("spring.hazelcast" );
171
- prefix .accept ("spring.webservices" );
172
- }
173
-
174
- private void webPrefixes (Config prefix ) {
175
- prefix .accept ("spring.graphql" );
176
- prefix .accept ("spring.hateoas" );
177
- prefix .accept ("spring.http" );
178
- prefix .accept ("spring.jersey" );
179
- prefix .accept ("spring.mvc" );
180
- prefix .accept ("spring.netty" );
181
- prefix .accept ("spring.resources" );
182
- prefix .accept ("spring.servlet" );
183
- prefix .accept ("spring.session" );
184
- prefix .accept ("spring.web" );
185
- prefix .accept ("spring.webflux" );
186
- }
187
-
188
- private void templatePrefixes (Config prefix ) {
189
- prefix .accept ("spring.freemarker" );
190
- prefix .accept ("spring.groovy" );
191
- prefix .accept ("spring.mustache" );
192
- prefix .accept ("spring.thymeleaf" );
193
- }
194
-
195
- private void serverPrefixes (Config prefix ) {
196
- prefix .accept ("server" );
197
- }
198
65
199
- private void securityPrefixes (Config prefix ) {
200
- prefix .accept ("spring.security" );
201
- }
202
-
203
- private void rsocketPrefixes (Config prefix ) {
204
- prefix .accept ("spring.rsocket" );
205
- }
206
-
207
- private void actuatorPrefixes (Config prefix ) {
208
- prefix .accept ("management" );
209
- prefix .accept ("micrometer" );
210
- }
66
+ List <PropertySectionDefinition > sections = getPropertySections ().getOrElse (getDefaultPropertySections ());
67
+ for (PropertySectionDefinition section : sections ) {
68
+ snippets .add (section .getFileName (), section .getTitle (), (config ) -> {
69
+ for (String prefix : section .getPrefixes ()) {
70
+ if (section .getDescriptions ().containsKey (prefix )) {
71
+ config .accept (prefix , section .getDescriptions ().get (prefix ));
72
+ }
73
+ else {
74
+ config .accept (prefix );
75
+ }
76
+ }
77
+ });
78
+ }
211
79
212
- private void dockerComposePrefixes (Config prefix ) {
213
- prefix .accept ("spring.docker.compose" );
214
- }
215
-
216
- private void devtoolsPrefixes (Config prefix ) {
217
- prefix .accept ("spring.devtools" );
80
+ snippets .writeTo (getOutputDir ().getAsFile ().get ().toPath ());
218
81
}
219
82
220
- private void testingPrefixes (Config prefix ) {
221
- prefix .accept ("spring.test." );
222
- }
83
+ private List <PropertySectionDefinition > getDefaultPropertySections () {
84
+ return List .of (
85
+ new PropertySectionDefinition ("application-properties.core" , "Core Properties" ,
86
+ List .of ("debug" , "trace" , "logging" , "spring.aop" , "spring.application" , "spring.autoconfigure" ,
87
+ "spring.banner" , "spring.beaninfo" , "spring.config" , "spring.info" , "spring.jmx" ,
88
+ "spring.lifecycle" , "spring.main" , "spring.messages" , "spring.pid" , "spring.profiles" ,
89
+ "spring.quartz" , "spring.reactor" , "spring.ssl" , "spring.task" , "spring.threads" ,
90
+ "spring.validation" , "spring.mandatory-file-encoding" , "info" ,
91
+ "spring.output.ansi.enabled" ),
92
+ Map .of ()),
93
+ new PropertySectionDefinition ("application-properties.cache" , "Cache Properties" ,
94
+ List .of ("spring.cache" ), Map .of ()),
95
+ new PropertySectionDefinition ("application-properties.mail" , "Mail Properties" ,
96
+ List .of ("spring.mail" , "spring.sendgrid" ), Map .of ()),
97
+ new PropertySectionDefinition ("application-properties.json" , "JSON Properties" ,
98
+ List .of ("spring.jackson" , "spring.gson" ), Map .of ()),
99
+ new PropertySectionDefinition ("application-properties.data" , "Data Properties" ,
100
+ List .of ("spring.couchbase" , "spring.cassandra" , "spring.elasticsearch" , "spring.h2" ,
101
+ "spring.influx" , "spring.ldap" , "spring.mongodb" , "spring.neo4j" , "spring.dao" ,
102
+ "spring.data" , "spring.datasource" , "spring.jooq" , "spring.jdbc" , "spring.jpa" ,
103
+ "spring.r2dbc" , "spring.datasource.oracleucp" , "spring.datasource.dbcp2" ,
104
+ "spring.datasource.tomcat" , "spring.datasource.hikari" ),
105
+ Map .of ("spring.datasource.oracleucp" ,
106
+ "Oracle UCP specific settings bound to an instance of Oracle UCP's PoolDataSource" ,
107
+ "spring.datasource.dbcp2" ,
108
+ "Commons DBCP2 specific settings bound to an instance of DBCP2's BasicDataSource" ,
109
+ "spring.datasource.tomcat" ,
110
+ "Tomcat datasource specific settings bound to an instance of Tomcat JDBC's DataSource" ,
111
+ "spring.datasource.hikari" ,
112
+ "Hikari specific settings bound to an instance of Hikari's HikariDataSource" )),
113
+ new PropertySectionDefinition ("application-properties.transaction" , "Transaction Properties" ,
114
+ List .of ("spring.jta" , "spring.transaction" ), Map .of ()),
115
+ new PropertySectionDefinition ("application-properties.data-migration" , "Data Migration Properties" ,
116
+ List .of ("spring.flyway" , "spring.liquibase" , "spring.sql.init" ), Map .of ()),
117
+ new PropertySectionDefinition ("application-properties.integration" , "Integration Properties" ,
118
+ List .of ("spring.activemq" , "spring.artemis" , "spring.batch" , "spring.integration" , "spring.jms" ,
119
+ "spring.kafka" , "spring.pulsar" , "spring.rabbitmq" , "spring.hazelcast" ,
120
+ "spring.webservices" ),
121
+ Map .of ()),
122
+ new PropertySectionDefinition ("application-properties.web" , "Web Properties" ,
123
+ List .of ("spring.graphql" , "spring.hateoas" , "spring.http" , "spring.jersey" , "spring.mvc" ,
124
+ "spring.netty" , "spring.resources" , "spring.servlet" , "spring.session" , "spring.web" ,
125
+ "spring.webflux" ),
126
+ Map .of ()),
127
+ new PropertySectionDefinition ("application-properties.templating" , "Templating Properties" ,
128
+ List .of ("spring.freemarker" , "spring.groovy" , "spring.mustache" , "spring.thymeleaf" ), Map .of ()),
129
+ new PropertySectionDefinition ("application-properties.server" , "Server Properties" , List .of ("server" ),
130
+ Map .of ()),
131
+ new PropertySectionDefinition ("application-properties.security" , "Security Properties" ,
132
+ List .of ("spring.security" ), Map .of ()),
133
+ new PropertySectionDefinition ("application-properties.rsocket" , "RSocket Properties" ,
134
+ List .of ("spring.rsocket" ), Map .of ()),
135
+ new PropertySectionDefinition ("application-properties.actuator" , "Actuator Properties" ,
136
+ List .of ("management" , "micrometer" ), Map .of ()),
137
+ new PropertySectionDefinition ("application-properties.devtools" , "Devtools Properties" ,
138
+ List .of ("spring.devtools" ), Map .of ()),
139
+ new PropertySectionDefinition ("application-properties.docker-compose" , "Docker Compose Properties" ,
140
+ List .of ("spring.docker.compose" ), Map .of ()),
141
+ new PropertySectionDefinition ("application-properties.testcontainers" , "Testcontainers Properties" ,
142
+ List .of ("spring.testcontainers." ), Map .of ()),
143
+ new PropertySectionDefinition ("application-properties.testing" , "Testing Properties" ,
144
+ List .of ("spring.test." ), Map .of ()));
145
+ }
146
+
147
+ /**
148
+ * Configuration for a property section.
149
+ */
150
+ public static class PropertySectionDefinition {
151
+
152
+ private final String fileName ;
153
+
154
+ private final String title ;
155
+
156
+ private final List <String > prefixes ;
157
+
158
+ private final Map <String , String > descriptions ;
159
+
160
+ public PropertySectionDefinition (String fileName , String title , List <String > prefixes ,
161
+ Map <String , String > descriptions ) {
162
+ this .fileName = fileName ;
163
+ this .title = title ;
164
+ this .prefixes = prefixes ;
165
+ this .descriptions = descriptions ;
166
+ }
167
+
168
+ public String getFileName () {
169
+ return this .fileName ;
170
+ }
171
+
172
+ public String getTitle () {
173
+ return this .title ;
174
+ }
175
+
176
+ public List <String > getPrefixes () {
177
+ return this .prefixes ;
178
+ }
179
+
180
+ public Map <String , String > getDescriptions () {
181
+ return this .descriptions ;
182
+ }
223
183
224
- private void testcontainersPrefixes (Config prefix ) {
225
- prefix .accept ("spring.testcontainers." );
226
184
}
227
185
228
186
}
0 commit comments