Skip to content

Commit 7db357d

Browse files
committed
Use io.spring.antora.generate-antora-yml
1 parent f5bc6ce commit 7db357d

File tree

2 files changed

+36
-59
lines changed

2 files changed

+36
-59
lines changed

docs/antora.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ nav:
66
ext:
77
collector:
88
run:
9-
command: gradlew -q -PbuildSrc.skipTests=true "-Dorg.gradle.jvmargs=-Xmx3g -XX:+HeapDumpOnOutOfMemoryError" :spring-security-docs:generateAntora
9+
command: gradlew -q -PbuildSrc.skipTests=true "-Dorg.gradle.jvmargs=-Xmx3g -XX:+HeapDumpOnOutOfMemoryError" :spring-security-docs:generateAntoraYml
1010
local: true
1111
scan:
12-
dir: ./build/generateAntora
12+
dir: ./build/generated-antora-resources
13+
asciidoc:
14+
attributes:
15+
icondir: icons
16+
gh-old-samples-url: 'https://github.com/spring-projects/spring-security/tree/5.4.x/samples'
17+
gh-samples-url: "https://github.com/spring-projects/spring-security-samples/tree/{gh-tag}"
18+
gh-url: "https://github.com/spring-projects/spring-security/tree/{gh-tag}"

docs/spring-security-docs.gradle

Lines changed: 28 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
id 'org.antora' version '1.0.0-alpha.7'
3+
id 'io.spring.antora.generate-antora-yml' version '0.0.1'
34
}
45

56
apply plugin: 'io.spring.convention.docs'
@@ -16,60 +17,9 @@ antora {
1617
options = [clean: true, fetch: !project.gradle.startParameter.offline, stacktrace: true]
1718
}
1819

19-
tasks.register('generateAntora') {
20-
group = 'Documentation'
21-
description = 'Generates the antora.yml for dynamic properties'
22-
doLast {
23-
def docsTag = snapshotBuild ? 'current' : project.version
24-
def ghTag = snapshotBuild ? 'main' : project.version
25-
def ghUrl = "https://github.com/spring-projects/spring-security/tree/$ghTag"
26-
def ghOldSamplesUrl = 'https://github.com/spring-projects/spring-security/tree/5.4.x/samples'
27-
def ghSamplesUrl = "https://github.com/spring-projects/spring-security-samples/tree/$samplesBranch"
28-
def securityDocsUrl = "https://docs.spring.io/spring-security/site/docs/$docsTag"
29-
def securityApiUrl = "$securityDocsUrl/api/"
30-
def securityReferenceUrl = "$securityDocsUrl/reference/html5/"
31-
def springFrameworkApiUrl = "https://docs.spring.io/spring-framework/docs/$springFrameworkVersion/javadoc-api/"
32-
def springFrameworkReferenceUrl = "https://docs.spring.io/spring-framework/docs/$springFrameworkVersion/reference/html/"
33-
def ymlVersions = resolvedVersions(project.configurations.testRuntimeClasspath).call()
34-
.collect(v -> " ${v.getKey()}: ${v.getValue()}")
35-
.join('\n')
36-
def outputFile = layout.buildDirectory.file('generateAntora/antora.yml').get().asFile
37-
mkdir(outputFile.getParentFile())
38-
def mainVersion = project.version
39-
def prerelease = null
40-
def versionComponents = mainVersion.split(/(?=-)/)
41-
if (versionComponents.length > 1) {
42-
if (versionComponents[1] == '-SNAPSHOT') {
43-
mainVersion = versionComponents[0]
44-
prerelease = "'-SNAPSHOT'"
45-
} else {
46-
prerelease = 'true'
47-
}
48-
}
49-
def antoraYmlText = file('antora.yml').text
50-
layout.buildDirectory.file('.antora.yml').get().asFile.text = antoraYmlText
51-
antoraYmlText = antoraYmlText.lines().collect { l ->
52-
if (l.startsWith('version: ')) {
53-
return prerelease == null ? "version: '${mainVersion}'" : "version: '${mainVersion}'\nprerelease: ${prerelease}"
54-
}
55-
if (l.startsWith('title: ')) return "title: ${project.parent.description}"
56-
return l == 'ext:' || l.getAt(0) == ' ' ? null : l
57-
}.findAll(Objects::nonNull).join('\n')
58-
outputFile.text = """$antoraYmlText
59-
asciidoc:
60-
attributes:
61-
icondir: icons
62-
gh-old-samples-url: $ghOldSamplesUrl
63-
gh-samples-url: $ghSamplesUrl
64-
gh-url: $ghUrl
65-
security-api-url: $securityApiUrl
66-
security-reference-url: $securityReferenceUrl
67-
spring-framework-api-url: $springFrameworkApiUrl
68-
spring-framework-reference-url: $springFrameworkReferenceUrl
69-
spring-security-version: ${project.version}
70-
${ymlVersions}
71-
"""
72-
}
20+
tasks.named("generateAntoraYml") {
21+
asciidocAttributes = project.provider( { generateAttributes() } )
22+
asciidocAttributes.putAll(providers.provider( { resolvedVersions(project.configurations.testRuntimeClasspath) }))
7323
}
7424

7525
dependencies {
@@ -79,12 +29,33 @@ dependencies {
7929
testImplementation 'org.springframework:spring-core'
8030
}
8131

32+
def generateAttributes() {
33+
def docsTag = snapshotBuild ? 'current' : project.version
34+
def ghTag = snapshotBuild ? 'main' : project.version
35+
def ghUrl = "https://github.com/spring-projects/spring-security/tree/$ghTag"
36+
def ghOldSamplesUrl = 'https://github.com/spring-projects/spring-security/tree/5.4.x/samples'
37+
def ghSamplesUrl = "https://github.com/spring-projects/spring-security-samples/tree/$samplesBranch"
38+
def securityDocsUrl = "https://docs.spring.io/spring-security/site/docs/$docsTag"
39+
def securityApiUrl = "$securityDocsUrl/api/"
40+
def securityReferenceUrl = "$securityDocsUrl/reference/html5/"
41+
def springFrameworkApiUrl = "https://docs.spring.io/spring-framework/docs/$springFrameworkVersion/javadoc-api/"
42+
def springFrameworkReferenceUrl = "https://docs.spring.io/spring-framework/docs/$springFrameworkVersion/reference/html/"
43+
44+
return ['gh-old-samples-url': ghOldSamplesUrl.toString(),
45+
'gh-samples-url': ghSamplesUrl.toString(),
46+
'gh-url': ghUrl.toString(),
47+
'security-api-url': securityApiUrl.toString(),
48+
'security-reference-url': securityReferenceUrl.toString(),
49+
'spring-framework-api-url': springFrameworkApiUrl.toString(),
50+
'spring-framework-reference-url': springFrameworkReferenceUrl.toString(),
51+
'spring-security-version': project.version]
52+
+ resolvedVersions(project.configurations.testRuntimeClasspath)
53+
}
54+
8255
def resolvedVersions(Configuration configuration) {
83-
return {
84-
configuration.resolvedConfiguration
56+
return configuration.resolvedConfiguration
8557
.resolvedArtifacts
8658
.collectEntries { [(it.name + '-version'): it.moduleVersion.id.version] }
87-
}
8859
}
8960

9061
repositories {

0 commit comments

Comments
 (0)