Skip to content

Commit

Permalink
Migrate to Antora
Browse files Browse the repository at this point in the history
Closes gh-33766
  • Loading branch information
philwebb committed Mar 20, 2024
2 parents 4aa4e14 + 8dd89c1 commit 66dc3ed
Show file tree
Hide file tree
Showing 468 changed files with 9,827 additions and 8,251 deletions.
9 changes: 6 additions & 3 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def versions = [:]
new File(projectDir.parentFile, "gradle.properties").withInputStream {
def properties = new Properties()
properties.load(it)
["assertj", "commonsCodec", "hamcrest", "junitJupiter", "kotlin", "maven"].each {
["assertj", "commonsCodec", "hamcrest", "junitJupiter", "kotlin", "maven", "snakeYaml"].each {
versions[it] = properties[it + "Version"]
}
}
Expand All @@ -42,20 +42,23 @@ dependencies {
implementation(platform("org.springframework:spring-framework-bom:${versions.springFramework}"))
implementation("com.diffplug.gradle:goomph:3.37.2")
implementation("com.fasterxml.jackson.core:jackson-databind:${versions.jackson}")
implementation("com.github.node-gradle:gradle-node-plugin:3.5.1")
implementation("com.gradle:gradle-enterprise-gradle-plugin:3.12.1")
implementation("com.tngtech.archunit:archunit:1.0.0")
implementation("commons-codec:commons-codec:${versions.commonsCodec}")
implementation("de.undercouch.download:de.undercouch.download.gradle.plugin:5.5.0")
implementation("io.spring.gradle.antora:spring-antora-plugin:0.0.1")
implementation("io.spring.javaformat:spring-javaformat-gradle-plugin:${javaFormatVersion}")
implementation("io.spring.nohttp:nohttp-gradle:0.0.11")
implementation("org.apache.httpcomponents.client5:httpclient5:5.3.1")
implementation("org.apache.maven:maven-embedder:${versions.maven}")
implementation("org.asciidoctor:asciidoctor-gradle-jvm:3.3.2")
implementation("org.antora:gradle-antora-plugin:1.0.0")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}")
implementation("org.jetbrains.kotlin:kotlin-compiler-embeddable:${versions.kotlin}")
implementation("org.springframework:spring-context")
implementation("org.springframework:spring-core")
implementation("org.springframework:spring-web")
implementation("io.spring.nohttp:nohttp-gradle:0.0.11")
implementation("org.yaml:snakeyaml:${versions.snakeYaml}")

testImplementation("org.assertj:assertj-core:${versions.assertj}")
testImplementation("org.hamcrest:hamcrest:${versions.hamcrest}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.boot.build;

import java.io.File;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.github.gradle.node.NodeExtension;
import io.spring.gradle.antora.GenerateAntoraYmlPlugin;
import io.spring.gradle.antora.GenerateAntoraYmlTask;
import org.antora.gradle.AntoraExtension;
import org.antora.gradle.AntoraPlugin;
import org.antora.gradle.AntoraTask;
import org.gradle.api.Project;
import org.gradle.api.file.RegularFile;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.logging.LogLevel;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.TaskContainer;

import org.springframework.boot.build.antora.AntoraAsciidocAttributes;
import org.springframework.boot.build.antora.Extensions;
import org.springframework.boot.build.antora.GenerateAntoraPlaybook;
import org.springframework.boot.build.bom.BomExtension;
import org.springframework.boot.build.constraints.ExtractVersionConstraints;
import org.springframework.util.Assert;

/**
* Conventions that are applied in the presence of the {@link AntoraPlugin} and
* {@link GenerateAntoraYmlPlugin}.
*
* @author Phillip Webb
*/
public class AntoraConventions {

private static final String DEPENDENCIES_PATH = ":spring-boot-project:spring-boot-dependencies";

private static final String ANTORA_VERSION = "3.2.0-alpha.4";

private static final String ANTORA_SOURCE_DIR = "src/docs/antora";

private static final List<String> NAV_FILES = List.of("nav.adoc", "local-nav.adoc");

void apply(Project project) {
project.getPlugins().withType(AntoraPlugin.class, (antoraPlugin) -> apply(project, antoraPlugin));
}

private void apply(Project project, AntoraPlugin antoraPlugin) {
ExtractVersionConstraints dependencyVersionsTask = addDependencyVersionsTask(project);
project.getPlugins().apply(GenerateAntoraYmlPlugin.class);
TaskContainer tasks = project.getTasks();
GenerateAntoraPlaybook generateAntoraPlaybookTask = tasks.create("generateAntoraPlaybook",
GenerateAntoraPlaybook.class);
tasks.withType(GenerateAntoraYmlTask.class, (generateAntoraYmlTask) -> configureGenerateAntoraYmlTask(project,
generateAntoraYmlTask, dependencyVersionsTask));
tasks.withType(AntoraTask.class,
(antoraTask) -> configureAntoraTask(project, antoraTask, generateAntoraPlaybookTask));
project.getExtensions().configure(AntoraExtension.class, (antoraExtension) -> {
RegularFileProperty outputFile = generateAntoraPlaybookTask.getOutputFile();
configureAntoraExtension(project, antoraExtension, outputFile);
});
project.getExtensions()
.configure(NodeExtension.class, (nodeExtension) -> configureNodeExtension(project, nodeExtension));
}

private ExtractVersionConstraints addDependencyVersionsTask(Project project) {
return project.getTasks()
.create("dependencyVersions", ExtractVersionConstraints.class,
(task) -> task.enforcedPlatform(DEPENDENCIES_PATH));
}

private void configureGenerateAntoraYmlTask(Project project, GenerateAntoraYmlTask generateAntoraYmlTask,
ExtractVersionConstraints dependencyVersionsTask) {
generateAntoraYmlTask.getOutputs().doNotCacheIf("getAsciidocAttributes() changes output", (task) -> true);
generateAntoraYmlTask.dependsOn(dependencyVersionsTask);
generateAntoraYmlTask.setProperty("componentName", "spring-boot");
generateAntoraYmlTask.setProperty("outputFile",
new File(project.getBuildDir(), "generated/docs/antora-yml/antora.yml"));
generateAntoraYmlTask.setProperty("yml", getDefaultYml(project));
generateAntoraYmlTask.doFirst((task) -> generateAntoraYmlTask.getAsciidocAttributes()
.putAll(project.provider(() -> getAsciidocAttributes(project, dependencyVersionsTask))));
}

private Map<String, ?> getDefaultYml(Project project) {
String navFile = null;
for (String candidate : NAV_FILES) {
if (project.file(ANTORA_SOURCE_DIR + "/" + candidate).exists()) {
Assert.state(navFile == null, "Multiple nav files found");
navFile = candidate;
}
}
Map<String, Object> defaultYml = new LinkedHashMap<>();
defaultYml.put("title", "Spring Boot");
if (navFile != null) {
defaultYml.put("nav", List.of(navFile));
}
return defaultYml;
}

private Map<String, String> getAsciidocAttributes(Project project,
ExtractVersionConstraints dependencyVersionsTask) {
BomExtension bom = (BomExtension) project.project(DEPENDENCIES_PATH).getExtensions().getByName("bom");
Map<String, String> dependencyVersions = dependencyVersionsTask.getVersionConstraints();
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes(project, bom, dependencyVersions);
return attributes.get();
}

private void configureAntoraTask(Project project, AntoraTask antoraTask,
GenerateAntoraPlaybook generateAntoraPlaybookTask) {
antoraTask.setGroup("Documentation");
antoraTask.getDependsOn().add(generateAntoraPlaybookTask);
project.getPlugins()
.withType(JavaBasePlugin.class,
(javaBasePlugin) -> project.getTasks()
.getByName(JavaBasePlugin.CHECK_TASK_NAME)
.dependsOn(antoraTask));
}

private void configureAntoraExtension(Project project, AntoraExtension antoraExtension,
Provider<RegularFile> playbook) {
antoraExtension.getVersion().convention(ANTORA_VERSION);
antoraExtension.getPackages().convention(Extensions.packages());
antoraExtension.getPlaybook().convention(playbook.map(RegularFile::getAsFile));
if (project.getGradle().getStartParameter().getLogLevel() != LogLevel.DEBUG) {
antoraExtension.getOptions().add("--quiet");
}
else {
antoraExtension.getOptions().addAll("--log-level", "all");
}
}

private void configureNodeExtension(Project project, NodeExtension nodeExtension) {
File buildDir = project.getBuildDir();
nodeExtension.getWorkDir().set(buildDir.toPath().resolve(".gradle/nodejs").toFile());
nodeExtension.getNpmWorkDir().set(buildDir.toPath().resolve(".gradle/npm").toFile());
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.springframework.boot.build;

import org.asciidoctor.gradle.jvm.AsciidoctorJPlugin;
import org.antora.gradle.AntoraPlugin;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaBasePlugin;
Expand All @@ -32,8 +32,8 @@
* When the {@link MavenPublishPlugin} is applied, the conventions in
* {@link MavenPublishingConventions} are applied.
*
* When the {@link AsciidoctorJPlugin} is applied, the conventions in
* {@link AsciidoctorConventions} are applied.
* When the {@link AntoraPlugin} is applied, the conventions in {@link AntoraConventions}
* are applied.
*
* @author Andy Wilkinson
* @author Christoph Dreis
Expand All @@ -46,7 +46,7 @@ public void apply(Project project) {
new NoHttpConventions().apply(project);
new JavaConventions().apply(project);
new MavenPublishingConventions().apply(project);
new AsciidoctorConventions().apply(project);
new AntoraConventions().apply(project);
new KotlinConventions().apply(project);
new WarConventions().apply(project);
new EclipseConventions().apply(project);
Expand Down

0 comments on commit 66dc3ed

Please sign in to comment.