Added the inclusion pattern

This commit is contained in:
Marcin Grzejszczak
2019-09-06 13:49:31 +02:00
parent f7f7f81534
commit 39c493473b
3 changed files with 19 additions and 4 deletions

View File

@@ -94,7 +94,9 @@ approach of generating documentation just add these plugins to your `docs` modul
IMPORTANT: The order of plugin declaration is important!
In order for the build to generate the `adoc` file with all your configuration properties, your `docs` module should contain all the dependencies on the classpath, that you would want to scan for configuration properties. The file will be output to `${docsModule}/src/main/asciidoc/configprops.adoc` file.
In order for the build to generate the `adoc` file with all your configuration properties, your `docs` module should contain all the dependencies on the classpath, that you would want to scan for configuration properties. The file will be output to `${docsModule}/src/main/asciidoc/configprops.adoc` file (configurable via the `configprops.path` property).
If you want to modify which of the configuration properties are put in the table, you can tweak the `configprops.inclusionPattern` pattern to include only a subset of the properties (e.g. `<configprops.inclusionPattern>spring.sleuth.*</configprops.inclusionPattern>`).
Spring Cloud Build Docs comes with a set of attributes for asciidoctor that you can reuse.

View File

@@ -1,5 +1,7 @@
package org.springframework.cloud.internal
import java.util.regex.Pattern
import groovy.json.JsonSlurper
import groovy.transform.CompileStatic
@@ -14,10 +16,11 @@ class Main {
@CompileStatic
static void main(String... args) {
String outputFile = args[0]
new Main().generate(outputFile)
String inclusionPattern = args.length > 0 ? args[1] : ".*"
new Main().generate(outputFile, inclusionPattern)
}
void generate(String outputFile) {
void generate(String outputFile, String inclusionPattern) {
println "Parsing all configuration metadata"
Resource[] resources = new PathMatchingResourcePatternResolver()
.getResources("classpath*:/META-INF/spring-configuration-metadata.json")
@@ -25,17 +28,25 @@ class Main {
TreeSet names = new TreeSet()
def descriptions = [:]
int count = 0
int matchingPropertyCount = 0
int propertyCount = 0
Pattern pattern = Pattern.compile(inclusionPattern)
resources.each { Resource resource ->
if (resource.url.toString().contains("cloud")) {
count++
def slurper = new JsonSlurper()
slurper.parseText(resource.inputStream.text).properties.each { val ->
propertyCount++
if (!pattern.matcher(val.name).matches()) {
return
}
matchingPropertyCount++
names.add val.name
descriptions[val.name] = new ConfigValue(val.name, val.description, val.defaultValue)
}
}
}
println "Found [${count}] Cloud projects configuration metadata jsons"
println "Found [${count}] Cloud projects configuration metadata jsons. [${matchingPropertyCount}/${propertyCount}] were matching the pattern [${inclusionPattern}]"
println "Successfully built the description table"
if (names.empty) {
println("Will not update the table, since no configuration properties were found!")

View File

@@ -99,6 +99,7 @@
<antelopetasks.version>3.2.10</antelopetasks.version>
<ant-nodeps.version>1.8.1</ant-nodeps.version>
<configprops.path>${project.basedir}/src/main/asciidoc/_configprops.adoc</configprops.path>
<configprops.inclusionPattern>.*</configprops.inclusionPattern>
</properties>
<dependencyManagement>
<dependencies>
@@ -1024,6 +1025,7 @@
<mainClass>org.springframework.cloud.internal.Main</mainClass>
<arguments>
<argument>${configprops.path}</argument>
<argument>${configprops.inclusionPattern}</argument>
</arguments>
</configuration>
</plugin>