Prepare buildSrc for migration to Antora

Replace `AsciidoctorConventions` with `AntoraConventions` in
preparation for the migration to Antora.

See gh-33766
This commit is contained in:
Phillip Webb
2024-03-19 22:29:48 -07:00
parent d18f60e9af
commit 8d64e99714
22 changed files with 1187 additions and 228 deletions

View File

@@ -0,0 +1,171 @@
/*
* Copyright 2012-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.antora;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import org.junit.jupiter.api.Test;
import org.springframework.boot.build.bom.Library;
import org.springframework.boot.build.bom.Library.Group;
import org.springframework.boot.build.bom.Library.LibraryVersion;
import org.springframework.boot.build.bom.Library.ProhibitedVersion;
import org.springframework.boot.build.bom.Library.VersionAlignment;
import org.springframework.boot.build.bom.bomr.version.DependencyVersion;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link AntoraAsciidocAttributes}.
*
* @author Phillip Webb
*/
class AntoraAsciidocAttributesTests {
@Test
void githubRefWhenReleasedVersionIsTag() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, null,
mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("github-ref", "v1.2.3");
}
@Test
void githubRefWhenLatestSnapshotVersionIsMainBranch() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", true, null,
mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("github-ref", "main");
}
@Test
void githubRefWhenOlderSnapshotVersionIsBranch() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", false, null,
mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("github-ref", "1.2.x");
}
@Test
void githubRefWhenOlderSnapshotHotFixVersionIsBranch() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3.1-SNAPSHOT", false, null,
mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("github-ref", "1.2.3.x");
}
@Test
void versionReferenceFromLibrary() {
Library library = mockLibrary(Collections.emptyMap());
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3.1-SNAPSHOT", false, List.of(library),
mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("version-spring-framework", "1.2.3");
}
@Test
void versionReferenceFromSpringDataDependencyVersion() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, null,
mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("version-spring-data-mongodb", "1.2.3");
}
@Test
void versionNativeBuildTools() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, null,
mockDependencyVersions(), Map.of("nativeBuildToolsVersion", "3.4.5"));
assertThat(attributes.get()).containsEntry("version-native-build-tools", "3.4.5");
}
@Test
void urlArtifactReposiroryWhenRelease() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, null,
mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("url-artifact-repository", "https://repo.maven.apache.org/maven2");
}
@Test
void urlArtifactReposiroryWhenMilestone() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-M1", true, null,
mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("url-artifact-repository", "https://repo.spring.io/milestone");
}
@Test
void urlArtifactReposiroryWhenSnapshot() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", true, null,
mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("url-artifact-repository", "https://repo.spring.io/snapshot");
}
@Test
void urlLinksFromLibrary() {
Map<String, Function<LibraryVersion, String>> links = new LinkedHashMap<>();
links.put("site", (version) -> "https://example.com/site/" + version);
links.put("docs", (version) -> "https://example.com/docs/" + version);
Library library = mockLibrary(links);
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3.1-SNAPSHOT", false, List.of(library),
mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("url-spring-framework-site", "https://example.com/site/1.2.3")
.containsEntry("url-spring-framework-docs", "https://example.com/docs/1.2.3");
}
@Test
void linksFromProperties() {
Map<String, String> attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", true, null,
mockDependencyVersions(), null)
.get();
assertThat(attributes).containsEntry("include-java", "ROOT:example$java/org/springframework/boot/docs");
assertThat(attributes).containsEntry("url-spring-data-cassandra-site",
"https://spring.io/projects/spring-data-cassandra");
List<String> keys = new ArrayList<>(attributes.keySet());
assertThat(keys.indexOf("include-java")).isLessThan(keys.indexOf("code-spring-boot-latest"));
}
private Library mockLibrary(Map<String, Function<LibraryVersion, String>> links) {
String name = "Spring Framework";
String calendarName = null;
LibraryVersion version = new LibraryVersion(DependencyVersion.parse("1.2.3"));
List<Group> groups = Collections.emptyList();
List<ProhibitedVersion> prohibitedVersion = Collections.emptyList();
boolean considerSnapshots = false;
VersionAlignment versionAlignment = null;
String linkRootName = null;
Library library = new Library(name, calendarName, version, groups, prohibitedVersion, considerSnapshots,
versionAlignment, linkRootName, links);
return library;
}
private Map<String, String> mockDependencyVersions() {
Map<String, String> versions = new LinkedHashMap<>();
addMockSpringDataVersion(versions, "spring-data-commons");
addMockSpringDataVersion(versions, "spring-data-couchbase");
addMockSpringDataVersion(versions, "spring-data-elasticsearch");
addMockSpringDataVersion(versions, "spring-data-jdbc");
addMockSpringDataVersion(versions, "spring-data-jpa");
addMockSpringDataVersion(versions, "spring-data-mongodb");
addMockSpringDataVersion(versions, "spring-data-neo4j");
addMockSpringDataVersion(versions, "spring-data-r2dbc");
addMockSpringDataVersion(versions, "spring-data-rest-core");
return versions;
}
private void addMockSpringDataVersion(Map<String, String> versions, String artifactId) {
versions.put("org.springframework.data:" + artifactId, "1.2.3");
}
}

View File

@@ -0,0 +1,68 @@
/*
* Copyright 2012-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.antora;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import org.gradle.api.Project;
import org.gradle.testfixtures.ProjectBuilder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.springframework.util.function.ThrowingConsumer;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link GenerateAntoraPlaybook}.
*
* @author Phillip Webb
*/
class GenerateAntoraPlaybookTests {
@TempDir
File temp;
@Test
void writePlaybookGeneratesExpectedContent() throws Exception {
writePlaybookYml((task) -> {
task.getXrefStubs().addAll("appendix:.*", "api:.*", "reference:.*");
task.getAlwaysInclude().set(Map.of("name", "test", "classifier", "local-aggregate-content"));
});
Path actual = this.temp.toPath()
.resolve("rootproject/project/build/generated/docs/antora-playbook/antora-playbook.yml");
System.out.println(Files.readString(actual));
assertThat(actual).hasSameTextualContentAs(
Path.of("src/test/resources/org/springframework/boot/build/antora/expected-playbook.yml"));
}
private void writePlaybookYml(ThrowingConsumer<GenerateAntoraPlaybook> customizer) throws Exception {
File rootProjectDir = new File(this.temp, "rootproject").getCanonicalFile();
rootProjectDir.mkdirs();
Project rootProject = ProjectBuilder.builder().withProjectDir(rootProjectDir).build();
File projectDir = new File(rootProjectDir, "project");
projectDir.mkdirs();
Project project = ProjectBuilder.builder().withProjectDir(projectDir).withParent(rootProject).build();
GenerateAntoraPlaybook task = project.getTasks().create("generateAntoraPlaybook", GenerateAntoraPlaybook.class);
customizer.accept(task);
task.writePlaybookYml();
}
}

View File

@@ -153,7 +153,6 @@ class ArchitectureCheckTests {
Resource root = resolver.getResource("classpath:org/springframework/boot/build/architecture/" + name);
FileSystemUtils.copyRecursively(root.getFile(),
new File(projectDir, "classes/org/springframework/boot/build/architecture/" + name));
}
private interface Callback<T> {

View File

@@ -0,0 +1,50 @@
antora:
extensions:
- require: '@springio/antora-extensions/static-page-extension'
- require: '@springio/antora-xref-extension'
stub:
- appendix:.*
- api:.*
- reference:.*
- require: '@springio/antora-zip-contents-collector-extension'
always_include:
- classifier: local-aggregate-content
name: test
locations:
- project/build/generated/docs/antora-content/test-${version}-${name}-${classifier}.zip
- project/build/generated/docs/antora-dependencies-content/test-${version}-${name}-${classifier}.zip
version_file: gradle.properties
- require: '@springio/antora-extensions/root-component-extension'
root_component_name: spring-boot
site:
title: Spring Boot
content:
sources:
- url: ./../../../../..
branches: HEAD
version: unspecified
start_paths:
- project/src/docs/antora
asciidoc:
sourcemap: true
attributes:
chomp: all
hide-uri-scheme: '@'
page-pagination: ''
page-stackoverflow-url: https://stackoverflow.com/tags/spring-boot
tabs-sync-option: '@'
extensions:
- '@asciidoctor/tabs'
- '@springio/asciidoctor-extensions'
- '@springio/asciidoctor-extensions/configuration-properties-extension'
- '@springio/asciidoctor-extensions/section-ids-extension'
urls:
latest_version_segment: ''
runtime:
log:
failure_level: warn
ui:
bundle:
url: https://github.com/spring-io/antora-ui-spring/releases/download/v0.4.11/ui-bundle.zip
output:
dir: ./../../../site