Added automated configprops table generation; fixes gh-144
This commit is contained in:
@@ -68,13 +68,17 @@ approach of generating documentation just add these plugins to your `docs` modul
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId> <3>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId> <4>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.asciidoctor</groupId>
|
||||
<artifactId>asciidoctor-maven-plugin</artifactId> <4>
|
||||
<artifactId>asciidoctor-maven-plugin</artifactId> <5>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId> <5>
|
||||
<artifactId>maven-antrun-plugin</artifactId> <6>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
@@ -84,11 +88,14 @@ approach of generating documentation just add these plugins to your `docs` modul
|
||||
<2> This plugin downloads sets up all the git information of the project
|
||||
<2> This plugin downloads the resources of the `spring-cloud-build-docs` module
|
||||
<3> This plugin unpacks the resources of the `spring-cloud-build-docs` module
|
||||
<4> This plugin is required to parse the Asciidoctor documentation
|
||||
<5> This plugin is required to copy resources into proper final destinations and to generate main README.adoc and to assert that no files use unresolved links
|
||||
<4> This plugin generates an `adoc` file with all the configuration properties from the classpath
|
||||
<5> This plugin is required to parse the Asciidoctor documentation
|
||||
<6> This plugin is required to copy resources into proper final destinations and to generate main README.adoc and to assert that no files use unresolved links
|
||||
|
||||
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.
|
||||
|
||||
Spring Cloud Build Docs comes with a set of attributes for asciidoctor that you can reuse.
|
||||
|
||||
[source,xml]
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package org.springframework.cloud.internal
|
||||
|
||||
import groovy.json.JsonSlurper
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
import org.springframework.core.io.Resource
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
class Main {
|
||||
|
||||
@CompileStatic
|
||||
static void main(String... args) {
|
||||
String outputFile = args[0]
|
||||
new Main().generate(outputFile)
|
||||
}
|
||||
|
||||
void generate(String outputFile) {
|
||||
println "Parsing all configuration metadata"
|
||||
Resource[] resources = new PathMatchingResourcePatternResolver()
|
||||
.getResources("classpath*:/META-INF/spring-configuration-metadata.json")
|
||||
println "Found [${resources.length}] configuration metadata jsons"
|
||||
TreeSet names = new TreeSet()
|
||||
def descriptions = [:]
|
||||
int count = 0
|
||||
resources.each { Resource resource ->
|
||||
if (resource.url.toString().contains("cloud")) {
|
||||
count++
|
||||
def slurper = new JsonSlurper()
|
||||
slurper.parseText(resource.inputStream.text).properties.each { val ->
|
||||
names.add val.name
|
||||
descriptions[val.name] = new ConfigValue(val.name, val.description, val.defaultValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
println "Found [${count}] Cloud projects configuration metadata jsons"
|
||||
println "Successfully built the description table"
|
||||
if (names.empty) {
|
||||
println("Will not update the table, since no configuration properties were found!")
|
||||
return
|
||||
}
|
||||
new File(outputFile).text = """\
|
||||
|===
|
||||
|Name | Default | Description
|
||||
${names.collect { it -> return descriptions[it] }.join("\n")}
|
||||
|
||||
|
||||
|
||||
|===
|
||||
"""
|
||||
println "Successfully stored the output file"
|
||||
}
|
||||
|
||||
@CompileStatic
|
||||
static class ConfigValue {
|
||||
String name
|
||||
String description
|
||||
Object defaultValue
|
||||
|
||||
ConfigValue() {}
|
||||
|
||||
ConfigValue(String name, String description, Object defaultValue) {
|
||||
this.name = name
|
||||
this.description = escapedValue(description)
|
||||
this.defaultValue = escapedValue(defaultValue)
|
||||
}
|
||||
|
||||
private String escapedValue(Object value) {
|
||||
return value != null ?
|
||||
value.toString().replaceAll('\\|', '\\\\|') : ''
|
||||
}
|
||||
|
||||
String toString() {
|
||||
"|${name} | ${defaultValue} | ${description}"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user