Skip to content

Commit 6e5c510

Browse files
committed
Migrate to asciidoctor-spring-backends
Migrate to the snapshot version of asciidoctor-spring-backends. See gh-25553
1 parent 3bb9b23 commit 6e5c510

File tree

8 files changed

+52
-130
lines changed

8 files changed

+52
-130
lines changed

buildSrc/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ dependencies {
1818
implementation("com.fasterxml.jackson.core:jackson-databind:2.11.4")
1919
implementation("commons-codec:commons-codec:1.13")
2020
implementation("org.apache.maven:maven-embedder:3.6.2")
21-
implementation("org.asciidoctor:asciidoctor-gradle-jvm:3.0.0")
22-
implementation("org.asciidoctor:asciidoctor-gradle-jvm-pdf:3.0.0")
21+
implementation("org.asciidoctor:asciidoctor-gradle-jvm:3.1.0")
22+
implementation("org.asciidoctor:asciidoctor-gradle-jvm-pdf:3.1.0")
2323
implementation("org.gradle:test-retry-gradle-plugin:1.1.9")
2424
implementation("org.springframework:spring-core:5.2.2.RELEASE")
2525
implementation("org.springframework:spring-web:5.2.2.RELEASE")
Lines changed: 46 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2020 the original author or authors.
2+
* Copyright 2019-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,16 +26,10 @@
2626
import org.asciidoctor.gradle.jvm.AsciidoctorJExtension;
2727
import org.asciidoctor.gradle.jvm.AsciidoctorJPlugin;
2828
import org.asciidoctor.gradle.jvm.AsciidoctorTask;
29-
import org.gradle.api.Action;
30-
import org.gradle.api.DefaultTask;
3129
import org.gradle.api.Project;
32-
import org.gradle.api.Task;
3330
import org.gradle.api.artifacts.Configuration;
34-
import org.gradle.api.file.FileCollection;
35-
import org.gradle.api.tasks.InputFiles;
36-
import org.gradle.api.tasks.OutputDirectory;
31+
import org.gradle.api.artifacts.ConfigurationContainer;
3732
import org.gradle.api.tasks.Sync;
38-
import org.gradle.api.tasks.TaskAction;
3933

4034
import org.springframework.boot.build.artifactory.ArtifactoryRepository;
4135
import org.springframework.util.StringUtils;
@@ -46,15 +40,13 @@
4640
*
4741
* <ul>
4842
* <li>All warnings are made fatal.
49-
* <li>The version of AsciidoctorJ is upgraded to 2.4.1.
50-
* <li>A task is created to resolve and unzip our documentation resources (CSS and
51-
* Javascript).
43+
* <li>The version of AsciidoctorJ is upgraded to 2.4.3.
44+
* <li>A {@code asciidoctorExtensions} configuration is created.
5245
* <li>For each {@link AsciidoctorTask} (HTML only):
5346
* <ul>
5447
* <li>A task is created to sync the documentation resources to its output directory.
5548
* <li>{@code doctype} {@link AsciidoctorTask#options(Map) option} is configured.
56-
* <li>{@link AsciidoctorTask#attributes(Map) Attributes} are configured for syntax
57-
* highlighting, CSS styling, docinfo, etc.
49+
* <li>The {@code backend} is configured.
5850
* </ul>
5951
* <li>For each {@link AbstractAsciidoctorTask} (HTML and PDF):
6052
* <ul>
@@ -70,43 +62,25 @@
7062
*/
7163
class AsciidoctorConventions {
7264

73-
private static final String ASCIIDOCTORJ_VERSION = "2.4.1";
65+
private static final String EXTENSIONS_CONFIGURATION = "asciidoctorExtensions";
66+
67+
private static final String ASCIIDOCTORJ_VERSION = "2.4.3";
7468

7569
void apply(Project project) {
7670
project.getPlugins().withType(AsciidoctorJPlugin.class, (asciidoctorPlugin) -> {
7771
configureDocResourcesRepository(project);
7872
makeAllWarningsFatal(project);
7973
upgradeAsciidoctorJVersion(project);
80-
UnzipDocumentationResources unzipResources = createUnzipDocumentationResourcesTask(project);
81-
project.getTasks().withType(AbstractAsciidoctorTask.class, (asciidoctorTask) -> {
82-
configureCommonAttributes(project, asciidoctorTask);
83-
configureOptions(asciidoctorTask);
84-
asciidoctorTask.baseDirFollowsSourceDir();
85-
Sync syncSource = createSyncDocumentationSourceTask(project, asciidoctorTask);
86-
if (asciidoctorTask instanceof AsciidoctorTask) {
87-
configureHtmlOnlyAttributes(asciidoctorTask);
88-
syncSource.from(unzipResources, (resources) -> resources.into("asciidoc"));
89-
asciidoctorTask.doFirst(new Action<Task>() {
90-
91-
@Override
92-
public void execute(Task task) {
93-
project.copy((spec) -> {
94-
spec.from(asciidoctorTask.getSourceDir());
95-
spec.into(asciidoctorTask.getOutputDir());
96-
spec.include("css/**", "js/**");
97-
});
98-
}
99-
100-
});
101-
}
102-
});
74+
createAsciidoctorExtensionsConfiguration(project);
75+
project.getTasks().withType(AbstractAsciidoctorTask.class,
76+
(asciidoctorTask) -> configureAsciidoctorTask(project, asciidoctorTask));
10377
});
10478
}
10579

10680
private void configureDocResourcesRepository(Project project) {
10781
project.getRepositories().maven((mavenRepo) -> {
108-
mavenRepo.setUrl(URI.create("https://repo.spring.io/release"));
109-
mavenRepo.mavenContent((mavenContent) -> mavenContent.includeGroup("io.spring.docresources"));
82+
mavenRepo.setUrl(URI.create("https://repo.spring.io/snapshot"));
83+
mavenRepo.mavenContent((mavenContent) -> mavenContent.includeGroup("io.spring.asciidoctor.backends"));
11084
});
11185
}
11286

@@ -118,41 +92,26 @@ private void upgradeAsciidoctorJVersion(Project project) {
11892
project.getExtensions().getByType(AsciidoctorJExtension.class).setVersion(ASCIIDOCTORJ_VERSION);
11993
}
12094

121-
private UnzipDocumentationResources createUnzipDocumentationResourcesTask(Project project) {
122-
Configuration documentationResources = project.getConfigurations().maybeCreate("documentationResources");
123-
documentationResources.getDependencies()
124-
.add(project.getDependencies().create("io.spring.docresources:spring-doc-resources:0.2.5"));
125-
UnzipDocumentationResources unzipResources = project.getTasks().create("unzipDocumentationResources",
126-
UnzipDocumentationResources.class);
127-
unzipResources.setResources(documentationResources);
128-
unzipResources.setOutputDir(new File(project.getBuildDir(), "docs/resources"));
129-
return unzipResources;
130-
}
131-
132-
private Sync createSyncDocumentationSourceTask(Project project, AbstractAsciidoctorTask asciidoctorTask) {
133-
Sync syncDocumentationSource = project.getTasks()
134-
.create("syncDocumentationSourceFor" + StringUtils.capitalize(asciidoctorTask.getName()), Sync.class);
135-
File syncedSource = new File(project.getBuildDir(), "docs/src/" + asciidoctorTask.getName());
136-
syncDocumentationSource.setDestinationDir(syncedSource);
137-
syncDocumentationSource.from("src/docs/");
138-
asciidoctorTask.dependsOn(syncDocumentationSource);
139-
asciidoctorTask.setSourceDir(project.relativePath(new File(syncedSource, "asciidoc/")));
140-
return syncDocumentationSource;
141-
}
142-
143-
private void configureOptions(AbstractAsciidoctorTask asciidoctorTask) {
144-
asciidoctorTask.options(Collections.singletonMap("doctype", "book"));
95+
private void createAsciidoctorExtensionsConfiguration(Project project) {
96+
ConfigurationContainer configurations = project.getConfigurations();
97+
Configuration asciidoctorExtensions = configurations.maybeCreate(EXTENSIONS_CONFIGURATION);
98+
asciidoctorExtensions.getDependencies().add(project.getDependencies()
99+
.create("io.spring.asciidoctor.backends:asciidoctor-spring-backends:0.0.1-SNAPSHOT"));
100+
Configuration dependencyManagement = configurations.findByName("dependencyManagement");
101+
if (dependencyManagement != null) {
102+
asciidoctorExtensions.extendsFrom(dependencyManagement);
103+
}
145104
}
146105

147-
private void configureHtmlOnlyAttributes(AbstractAsciidoctorTask asciidoctorTask) {
148-
Map<String, Object> attributes = new HashMap<>();
149-
attributes.put("source-highlighter", "highlightjs");
150-
attributes.put("highlightjsdir", "js/highlight");
151-
attributes.put("highlightjs-theme", "github");
152-
attributes.put("linkcss", true);
153-
attributes.put("icons", "font");
154-
attributes.put("stylesheet", "css/spring.css");
155-
asciidoctorTask.attributes(attributes);
106+
private void configureAsciidoctorTask(Project project, AbstractAsciidoctorTask asciidoctorTask) {
107+
asciidoctorTask.configurations(EXTENSIONS_CONFIGURATION);
108+
configureCommonAttributes(project, asciidoctorTask);
109+
configureOptions(asciidoctorTask);
110+
asciidoctorTask.baseDirFollowsSourceDir();
111+
createSyncDocumentationSourceTask(project, asciidoctorTask);
112+
if (asciidoctorTask instanceof AsciidoctorTask) {
113+
configureAsciidoctorHtmlTask(project, (AsciidoctorTask) asciidoctorTask);
114+
}
156115
}
157116

158117
private void configureCommonAttributes(Project project, AbstractAsciidoctorTask asciidoctorTask) {
@@ -169,43 +128,23 @@ private String determineGitHubTag(Project project) {
169128
return (version.endsWith("-SNAPSHOT")) ? "master" : version;
170129
}
171130

172-
/**
173-
* {@link Task} for unzipping the documentation resources.
174-
*/
175-
public static class UnzipDocumentationResources extends DefaultTask {
176-
177-
private FileCollection resources;
178-
179-
private File outputDir;
180-
181-
@InputFiles
182-
public FileCollection getResources() {
183-
return this.resources;
184-
}
185-
186-
public void setResources(FileCollection resources) {
187-
this.resources = resources;
188-
}
189-
190-
@OutputDirectory
191-
public File getOutputDir() {
192-
return this.outputDir;
193-
}
194-
195-
public void setOutputDir(File outputDir) {
196-
this.outputDir = outputDir;
197-
}
131+
private void configureOptions(AbstractAsciidoctorTask asciidoctorTask) {
132+
asciidoctorTask.options(Collections.singletonMap("doctype", "book"));
133+
}
198134

199-
@TaskAction
200-
void syncDocumentationResources() {
201-
getProject().sync((copySpec) -> {
202-
copySpec.into(this.outputDir);
203-
for (File resource : this.resources) {
204-
copySpec.from(getProject().zipTree(resource));
205-
}
206-
});
207-
}
135+
private Sync createSyncDocumentationSourceTask(Project project, AbstractAsciidoctorTask asciidoctorTask) {
136+
Sync syncDocumentationSource = project.getTasks()
137+
.create("syncDocumentationSourceFor" + StringUtils.capitalize(asciidoctorTask.getName()), Sync.class);
138+
File syncedSource = new File(project.getBuildDir(), "docs/src/" + asciidoctorTask.getName());
139+
syncDocumentationSource.setDestinationDir(syncedSource);
140+
syncDocumentationSource.from("src/docs/");
141+
asciidoctorTask.dependsOn(syncDocumentationSource);
142+
asciidoctorTask.setSourceDir(project.relativePath(new File(syncedSource, "asciidoc/")));
143+
return syncDocumentationSource;
144+
}
208145

146+
private void configureAsciidoctorHtmlTask(Project project, AsciidoctorTask asciidoctorTask) {
147+
asciidoctorTask.outputOptions((outputOptions) -> outputOptions.backends("spring-html"));
209148
}
210149

211150
}

buildSrc/src/main/java/org/springframework/boot/build/context/properties/ConfigurationTable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,7 +46,7 @@ void addEntry(ConfigurationTableEntry... entries) {
4646

4747
String toAsciidocTable() {
4848
AsciidocBuilder builder = new AsciidocBuilder();
49-
builder.appendln("[cols=\"2,1,1\", options=\"header\"]");
49+
builder.appendln("[cols=\"4,3,3\", options=\"header\"]");
5050
builder.appendln("|===");
5151
builder.appendln("|Key|Default Value|Description");
5252
builder.appendln();

buildSrc/src/test/java/org/springframework/boot/build/context/properties/ConfigurationTableTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,7 +38,7 @@ void simpleTable() {
3838
"This is another description.", false);
3939
table.addEntry(new SingleConfigurationTableEntry(first));
4040
table.addEntry(new SingleConfigurationTableEntry(second));
41-
assertThat(table.toAsciidocTable()).isEqualTo("[cols=\"2,1,1\", options=\"header\"]" + NEWLINE + "|==="
41+
assertThat(table.toAsciidocTable()).isEqualTo("[cols=\"4,3,3\", options=\"header\"]" + NEWLINE + "|==="
4242
+ NEWLINE + "|Key|Default Value|Description" + NEWLINE + NEWLINE
4343
+ "|[[spring.test.other]]<<spring.test.other,`+spring.test.other+`>>" + NEWLINE + "|`+other value+`"
4444
+ NEWLINE + "|+++This is another description.+++" + NEWLINE + NEWLINE

spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ plugins {
1111
description = "Spring Boot Actuator AutoConfigure"
1212

1313
configurations {
14-
asciidoctorExtensions {
15-
extendsFrom dependencyManagement
16-
}
1714
documentation
1815
}
1916

@@ -170,14 +167,12 @@ tasks.withType(org.asciidoctor.gradle.jvm.AbstractAsciidoctorTask) {
170167
}
171168

172169
asciidoctor {
173-
configurations "asciidoctorExtensions"
174170
sources {
175171
include "index.adoc"
176172
}
177173
}
178174

179175
asciidoctorPdf {
180-
configurations "asciidoctorExtensions"
181176
sources {
182177
include "index.adoc"
183178
}

spring-boot-project/spring-boot-docs/build.gradle

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ description = "Spring Boot Docs"
1010

1111
configurations {
1212
actuatorApiDocumentation
13-
asciidoctorExtensions {
14-
extendsFrom dependencyManagement
15-
}
1613
autoConfiguration
1714
configurationProperties
1815
gradlePluginDocumentation
@@ -46,7 +43,6 @@ plugins.withType(EclipsePlugin) {
4643
dependencies {
4744
actuatorApiDocumentation(project(path: ":spring-boot-project:spring-boot-actuator-autoconfigure", configuration: "documentation"))
4845

49-
asciidoctorExtensions("io.spring.asciidoctor:spring-asciidoctor-extensions-block-switch")
5046
asciidoctorExtensions("io.spring.asciidoctor:spring-asciidoctor-extensions-spring-boot")
5147
asciidoctorExtensions(project(path: ":spring-boot-project:spring-boot-actuator-autoconfigure"))
5248
asciidoctorExtensions(project(path: ":spring-boot-project:spring-boot-autoconfigure"))
@@ -192,7 +188,6 @@ task documentConfigurationProperties(type: org.springframework.boot.build.contex
192188

193189
tasks.withType(org.asciidoctor.gradle.jvm.AbstractAsciidoctorTask) {
194190
dependsOn dependencyVersions
195-
configurations "asciidoctorExtensions"
196191
baseDirFollowsSourceDir()
197192
asciidoctorj {
198193
fatalWarnings = ['^((?!successfully validated).)*$']

spring-boot-project/spring-boot-parent/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ bom {
151151
library("Spring Asciidoctor Extensions", "0.5.0") {
152152
group("io.spring.asciidoctor") {
153153
modules = [
154-
"spring-asciidoctor-extensions-block-switch",
155154
"spring-asciidoctor-extensions-spring-boot"
156155
]
157156
}

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ toolchain {
1515
}
1616

1717
configurations {
18-
asciidoctorExtensions {
19-
extendsFrom dependencyManagement
20-
}
2118
documentation
2219
}
2320

@@ -31,8 +28,6 @@ repositories {
3128
}
3229

3330
dependencies {
34-
asciidoctorExtensions("io.spring.asciidoctor:spring-asciidoctor-extensions-block-switch")
35-
3631
implementation(project(":spring-boot-project:spring-boot-tools:spring-boot-buildpack-platform"))
3732
implementation(project(":spring-boot-project:spring-boot-tools:spring-boot-loader-tools"))
3833
implementation("io.spring.gradle:dependency-management-plugin")
@@ -85,7 +80,6 @@ tasks.withType(org.asciidoctor.gradle.jvm.AbstractAsciidoctorTask) {
8580
}
8681

8782
asciidoctor {
88-
configurations "asciidoctorExtensions"
8983
sources {
9084
include "index.adoc"
9185
}

0 commit comments

Comments
 (0)