Auto-generate tables describing the first-party starters

Previously, the documentation included hand-written tables for the
application, production, and technical starters.

This commit replaces the hand-written tables with tables that are
generated automatically from all of the starter poms, thereby ensuring
that the documentation is automatically kept up-to-date as starters
are added and removed. An extra column provided a link to each
starter's pom on GitHub has also been added to the table. This makes
it easier for users to see exactly what each starter contains.

Closes gh-5267
This commit is contained in:
Andy Wilkinson
2016-03-29 17:19:29 +01:00
parent 2b649542e0
commit fec53970f7
55 changed files with 280 additions and 205 deletions

View File

@@ -0,0 +1,83 @@
import groovy.util.XmlSlurper
def getStarters(File dir) {
def starters = []
new File(project.build.directory, 'external-resources/starter-poms').eachDir { starterDir ->
def pom = new XmlSlurper().parse(new File(starterDir, 'pom.xml'))
def dependencies = getDependencies(pom)
if (isStarter(dependencies)) {
def name = pom.artifactId.text()
starters << [
'name': name,
'description': postProcessDescription(pom.description.text()),
'dependencies': dependencies,
'pomUrl': "{github-code}/spring-boot-starters/$name/pom.xml"
]
}
}
return starters
}
boolean isApplicationStarter(def starter) {
!isTechnicalStarter(starter) && !isProductionStarter(starter)
}
boolean isTechnicalStarter(def starter) {
starter.name != 'spring-boot-starter-test' && !isProductionStarter(starter) &&
starter.dependencies.find {
it.startsWith('org.springframework.boot:spring-boot-starter') } == null
}
boolean isProductionStarter(def starter) {
starter.name in ['spring-boot-starter-actuator', 'spring-boot-starter-remote-shell']
}
boolean isStarter(def dependencies) {
!dependencies.empty
}
def postProcessDescription(String description) {
addStarterCrossLinks(removeExtraWhitespace(description))
}
def removeExtraWhitespace(String input) {
input.replaceAll('\\s+', ' ')
}
def addStarterCrossLinks(String input) {
input.replaceAll('(spring-boot-starter[A-Za-z-]*)', '<<$1,`$1`>>')
}
def addBackTicksIfNecessary(String input) {
if (!input.contains('`')) {
return "`${input}`"
}
input
}
def getDependencies(def pom) {
dependencies = []
pom.dependencies.dependency.each { dependency ->
dependencies << "${dependency.groupId.text()}:${dependency.artifactId.text()}"
}
dependencies
}
def writeTable(String name, def starters) {
new File(project.build.directory, "generated-resources/${name}.adoc").withPrintWriter { writer ->
writer.println '|==='
writer.println '| Name | Description | Pom'
starters.each { starter ->
writer.println ''
writer.println "| [[${starter.name}]]`${starter.name}`"
writer.println "| ${starter.description}"
writer.println "| ${starter.pomUrl}[Pom]"
}
writer.println '|==='
}
}
def starters = getStarters(new File(project.build.directory, 'external-resources/starter-poms'))
writeTable('application-starters', starters.findAll { isApplicationStarter(it) })
writeTable('production-starters', starters.findAll { isProductionStarter(it) })
writeTable('technical-starters', starters.findAll { isTechnicalStarter(it) })