Skip to content

Commit 66dc3ed

Browse files
committed
Migrate to Antora
Closes gh-33766
2 parents 4aa4e14 + 8dd89c1 commit 66dc3ed

File tree

468 files changed

+9827
-8251
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

468 files changed

+9827
-8251
lines changed

buildSrc/build.gradle

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def versions = [:]
1717
new File(projectDir.parentFile, "gradle.properties").withInputStream {
1818
def properties = new Properties()
1919
properties.load(it)
20-
["assertj", "commonsCodec", "hamcrest", "junitJupiter", "kotlin", "maven"].each {
20+
["assertj", "commonsCodec", "hamcrest", "junitJupiter", "kotlin", "maven", "snakeYaml"].each {
2121
versions[it] = properties[it + "Version"]
2222
}
2323
}
@@ -42,20 +42,23 @@ dependencies {
4242
implementation(platform("org.springframework:spring-framework-bom:${versions.springFramework}"))
4343
implementation("com.diffplug.gradle:goomph:3.37.2")
4444
implementation("com.fasterxml.jackson.core:jackson-databind:${versions.jackson}")
45+
implementation("com.github.node-gradle:gradle-node-plugin:3.5.1")
4546
implementation("com.gradle:gradle-enterprise-gradle-plugin:3.12.1")
4647
implementation("com.tngtech.archunit:archunit:1.0.0")
4748
implementation("commons-codec:commons-codec:${versions.commonsCodec}")
4849
implementation("de.undercouch.download:de.undercouch.download.gradle.plugin:5.5.0")
50+
implementation("io.spring.gradle.antora:spring-antora-plugin:0.0.1")
4951
implementation("io.spring.javaformat:spring-javaformat-gradle-plugin:${javaFormatVersion}")
52+
implementation("io.spring.nohttp:nohttp-gradle:0.0.11")
5053
implementation("org.apache.httpcomponents.client5:httpclient5:5.3.1")
5154
implementation("org.apache.maven:maven-embedder:${versions.maven}")
52-
implementation("org.asciidoctor:asciidoctor-gradle-jvm:3.3.2")
55+
implementation("org.antora:gradle-antora-plugin:1.0.0")
5356
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}")
5457
implementation("org.jetbrains.kotlin:kotlin-compiler-embeddable:${versions.kotlin}")
5558
implementation("org.springframework:spring-context")
5659
implementation("org.springframework:spring-core")
5760
implementation("org.springframework:spring-web")
58-
implementation("io.spring.nohttp:nohttp-gradle:0.0.11")
61+
implementation("org.yaml:snakeyaml:${versions.snakeYaml}")
5962

6063
testImplementation("org.assertj:assertj-core:${versions.assertj}")
6164
testImplementation("org.hamcrest:hamcrest:${versions.hamcrest}")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
* Copyright 2023-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.build;
18+
19+
import java.io.File;
20+
import java.util.LinkedHashMap;
21+
import java.util.List;
22+
import java.util.Map;
23+
24+
import com.github.gradle.node.NodeExtension;
25+
import io.spring.gradle.antora.GenerateAntoraYmlPlugin;
26+
import io.spring.gradle.antora.GenerateAntoraYmlTask;
27+
import org.antora.gradle.AntoraExtension;
28+
import org.antora.gradle.AntoraPlugin;
29+
import org.antora.gradle.AntoraTask;
30+
import org.gradle.api.Project;
31+
import org.gradle.api.file.RegularFile;
32+
import org.gradle.api.file.RegularFileProperty;
33+
import org.gradle.api.logging.LogLevel;
34+
import org.gradle.api.plugins.JavaBasePlugin;
35+
import org.gradle.api.provider.Provider;
36+
import org.gradle.api.tasks.TaskContainer;
37+
38+
import org.springframework.boot.build.antora.AntoraAsciidocAttributes;
39+
import org.springframework.boot.build.antora.Extensions;
40+
import org.springframework.boot.build.antora.GenerateAntoraPlaybook;
41+
import org.springframework.boot.build.bom.BomExtension;
42+
import org.springframework.boot.build.constraints.ExtractVersionConstraints;
43+
import org.springframework.util.Assert;
44+
45+
/**
46+
* Conventions that are applied in the presence of the {@link AntoraPlugin} and
47+
* {@link GenerateAntoraYmlPlugin}.
48+
*
49+
* @author Phillip Webb
50+
*/
51+
public class AntoraConventions {
52+
53+
private static final String DEPENDENCIES_PATH = ":spring-boot-project:spring-boot-dependencies";
54+
55+
private static final String ANTORA_VERSION = "3.2.0-alpha.4";
56+
57+
private static final String ANTORA_SOURCE_DIR = "src/docs/antora";
58+
59+
private static final List<String> NAV_FILES = List.of("nav.adoc", "local-nav.adoc");
60+
61+
void apply(Project project) {
62+
project.getPlugins().withType(AntoraPlugin.class, (antoraPlugin) -> apply(project, antoraPlugin));
63+
}
64+
65+
private void apply(Project project, AntoraPlugin antoraPlugin) {
66+
ExtractVersionConstraints dependencyVersionsTask = addDependencyVersionsTask(project);
67+
project.getPlugins().apply(GenerateAntoraYmlPlugin.class);
68+
TaskContainer tasks = project.getTasks();
69+
GenerateAntoraPlaybook generateAntoraPlaybookTask = tasks.create("generateAntoraPlaybook",
70+
GenerateAntoraPlaybook.class);
71+
tasks.withType(GenerateAntoraYmlTask.class, (generateAntoraYmlTask) -> configureGenerateAntoraYmlTask(project,
72+
generateAntoraYmlTask, dependencyVersionsTask));
73+
tasks.withType(AntoraTask.class,
74+
(antoraTask) -> configureAntoraTask(project, antoraTask, generateAntoraPlaybookTask));
75+
project.getExtensions().configure(AntoraExtension.class, (antoraExtension) -> {
76+
RegularFileProperty outputFile = generateAntoraPlaybookTask.getOutputFile();
77+
configureAntoraExtension(project, antoraExtension, outputFile);
78+
});
79+
project.getExtensions()
80+
.configure(NodeExtension.class, (nodeExtension) -> configureNodeExtension(project, nodeExtension));
81+
}
82+
83+
private ExtractVersionConstraints addDependencyVersionsTask(Project project) {
84+
return project.getTasks()
85+
.create("dependencyVersions", ExtractVersionConstraints.class,
86+
(task) -> task.enforcedPlatform(DEPENDENCIES_PATH));
87+
}
88+
89+
private void configureGenerateAntoraYmlTask(Project project, GenerateAntoraYmlTask generateAntoraYmlTask,
90+
ExtractVersionConstraints dependencyVersionsTask) {
91+
generateAntoraYmlTask.getOutputs().doNotCacheIf("getAsciidocAttributes() changes output", (task) -> true);
92+
generateAntoraYmlTask.dependsOn(dependencyVersionsTask);
93+
generateAntoraYmlTask.setProperty("componentName", "spring-boot");
94+
generateAntoraYmlTask.setProperty("outputFile",
95+
new File(project.getBuildDir(), "generated/docs/antora-yml/antora.yml"));
96+
generateAntoraYmlTask.setProperty("yml", getDefaultYml(project));
97+
generateAntoraYmlTask.doFirst((task) -> generateAntoraYmlTask.getAsciidocAttributes()
98+
.putAll(project.provider(() -> getAsciidocAttributes(project, dependencyVersionsTask))));
99+
}
100+
101+
private Map<String, ?> getDefaultYml(Project project) {
102+
String navFile = null;
103+
for (String candidate : NAV_FILES) {
104+
if (project.file(ANTORA_SOURCE_DIR + "/" + candidate).exists()) {
105+
Assert.state(navFile == null, "Multiple nav files found");
106+
navFile = candidate;
107+
}
108+
}
109+
Map<String, Object> defaultYml = new LinkedHashMap<>();
110+
defaultYml.put("title", "Spring Boot");
111+
if (navFile != null) {
112+
defaultYml.put("nav", List.of(navFile));
113+
}
114+
return defaultYml;
115+
}
116+
117+
private Map<String, String> getAsciidocAttributes(Project project,
118+
ExtractVersionConstraints dependencyVersionsTask) {
119+
BomExtension bom = (BomExtension) project.project(DEPENDENCIES_PATH).getExtensions().getByName("bom");
120+
Map<String, String> dependencyVersions = dependencyVersionsTask.getVersionConstraints();
121+
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes(project, bom, dependencyVersions);
122+
return attributes.get();
123+
}
124+
125+
private void configureAntoraTask(Project project, AntoraTask antoraTask,
126+
GenerateAntoraPlaybook generateAntoraPlaybookTask) {
127+
antoraTask.setGroup("Documentation");
128+
antoraTask.getDependsOn().add(generateAntoraPlaybookTask);
129+
project.getPlugins()
130+
.withType(JavaBasePlugin.class,
131+
(javaBasePlugin) -> project.getTasks()
132+
.getByName(JavaBasePlugin.CHECK_TASK_NAME)
133+
.dependsOn(antoraTask));
134+
}
135+
136+
private void configureAntoraExtension(Project project, AntoraExtension antoraExtension,
137+
Provider<RegularFile> playbook) {
138+
antoraExtension.getVersion().convention(ANTORA_VERSION);
139+
antoraExtension.getPackages().convention(Extensions.packages());
140+
antoraExtension.getPlaybook().convention(playbook.map(RegularFile::getAsFile));
141+
if (project.getGradle().getStartParameter().getLogLevel() != LogLevel.DEBUG) {
142+
antoraExtension.getOptions().add("--quiet");
143+
}
144+
else {
145+
antoraExtension.getOptions().addAll("--log-level", "all");
146+
}
147+
}
148+
149+
private void configureNodeExtension(Project project, NodeExtension nodeExtension) {
150+
File buildDir = project.getBuildDir();
151+
nodeExtension.getWorkDir().set(buildDir.toPath().resolve(".gradle/nodejs").toFile());
152+
nodeExtension.getNpmWorkDir().set(buildDir.toPath().resolve(".gradle/npm").toFile());
153+
}
154+
155+
}

buildSrc/src/main/java/org/springframework/boot/build/AsciidoctorConventions.java

-159
This file was deleted.

buildSrc/src/main/java/org/springframework/boot/build/ConventionsPlugin.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.boot.build;
1818

19-
import org.asciidoctor.gradle.jvm.AsciidoctorJPlugin;
19+
import org.antora.gradle.AntoraPlugin;
2020
import org.gradle.api.Plugin;
2121
import org.gradle.api.Project;
2222
import org.gradle.api.plugins.JavaBasePlugin;
@@ -32,8 +32,8 @@
3232
* When the {@link MavenPublishPlugin} is applied, the conventions in
3333
* {@link MavenPublishingConventions} are applied.
3434
*
35-
* When the {@link AsciidoctorJPlugin} is applied, the conventions in
36-
* {@link AsciidoctorConventions} are applied.
35+
* When the {@link AntoraPlugin} is applied, the conventions in {@link AntoraConventions}
36+
* are applied.
3737
*
3838
* @author Andy Wilkinson
3939
* @author Christoph Dreis
@@ -46,7 +46,7 @@ public void apply(Project project) {
4646
new NoHttpConventions().apply(project);
4747
new JavaConventions().apply(project);
4848
new MavenPublishingConventions().apply(project);
49-
new AsciidoctorConventions().apply(project);
49+
new AntoraConventions().apply(project);
5050
new KotlinConventions().apply(project);
5151
new WarConventions().apply(project);
5252
new EclipseConventions().apply(project);

0 commit comments

Comments
 (0)