diff --git a/buildSrc/src/main/java/io/spring/gradle/convention/AsciidoctorConventionPlugin.java b/buildSrc/src/main/java/io/spring/gradle/convention/AsciidoctorConventionPlugin.java index 94ea2502..f8c54117 100644 --- a/buildSrc/src/main/java/io/spring/gradle/convention/AsciidoctorConventionPlugin.java +++ b/buildSrc/src/main/java/io/spring/gradle/convention/AsciidoctorConventionPlugin.java @@ -66,18 +66,14 @@ import org.gradle.api.tasks.Sync; */ public class AsciidoctorConventionPlugin implements Plugin { + private static final String ASCIIDOCTORJ_VERSION = "2.4.3"; private static final String SPRING_ASCIIDOCTOR_BACKENDS_VERSION = "0.0.5"; - private static final String SPRING_ASCIIDOCTOR_EXTENSIONS_BLOCK_SWITCH_VERSION = "0.6.1"; private static final String SPRING_DOC_RESOURCES_VERSION = "0.2.5"; private static final String SPRING_ASCIIDOCTOR_BACKENDS_DEPENDENCY = String.format("io.spring.asciidoctor.backends:spring-asciidoctor-backends:%s", SPRING_ASCIIDOCTOR_BACKENDS_VERSION); - private static final String SPRING_ASCIIDOCTOR_EXTENSION_BLOCK_SWITCH_DEPENDENCY = - String.format("io.spring.asciidoctor:spring-asciidoctor-extensions-block-switch:%s", - SPRING_ASCIIDOCTOR_EXTENSIONS_BLOCK_SWITCH_VERSION); - @SuppressWarnings("unused") private static final String SPRING_DOC_RESOURCES_DEPENDENCY = String.format("io.spring.docresources:spring-doc-resources:%s", SPRING_DOC_RESOURCES_VERSION); @@ -87,20 +83,16 @@ public class AsciidoctorConventionPlugin implements Plugin { project.getPlugins().withType(AsciidoctorJPlugin.class, asciidoctorPlugin -> { - configureMavenCentralRepositoryForAsciidoctor(project); + setAsciidoctorJVersion(project); makeAllWarningsFatal(project); + createAsciidoctorExtensionsConfiguration(project); - Sync unzipResources = createSyncDocumentationResourcesTask(project); + Sync unzipResources = createUnzipDocumentationResourcesTask(project); project.getTasks().withType(AbstractAsciidoctorTask.class, asciidoctorTask -> { asciidoctorTask.dependsOn(unzipResources); - configureAttributes(project, asciidoctorTask); - configureExtensions(project, asciidoctorTask); - configureForkOptions(asciidoctorTask); - configureOptions(asciidoctorTask); - asciidoctorTask.baseDirFollowsSourceDir(); - asciidoctorTask.useIntermediateWorkDir(); + configureAsciidoctorTask(project, asciidoctorTask); asciidoctorTask.resources(resourcesSpec -> { resourcesSpec.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE); @@ -112,33 +104,49 @@ public class AsciidoctorConventionPlugin implements Plugin { // resourcesSrcDirSpec.include("images/**"); }); }); - - if (asciidoctorTask instanceof AsciidoctorTask) { - configureHtmlOnlyAttributes(project, asciidoctorTask); - } }); }); } - private void configureMavenCentralRepositoryForAsciidoctor(Project project) { - project.getGradle().afterProject(it -> it.getRepositories().mavenCentral()); + private void setAsciidoctorJVersion(Project project) { + project.getExtensions().getByType(AsciidoctorJExtension.class).setVersion(ASCIIDOCTORJ_VERSION); + } + + private void makeAllWarningsFatal(Project project) { + project.getExtensions().getByType(AsciidoctorJExtension.class).fatalWarnings(".*"); + } + + private void createAsciidoctorExtensionsConfiguration(Project project) { + + project.getConfigurations().create("asciidoctorExtensions", configuration -> { + + project.getConfigurations() + .matching(it -> "dependencyManagement".equals(it.getName())) + .all(configuration::extendsFrom); + + configuration.getDependencies() + .add(project.getDependencies().create(SPRING_ASCIIDOCTOR_BACKENDS_DEPENDENCY)); + + // TODO: Why is the asiidoctorj-pdf dependency needed? + configuration.getDependencies() + .add(project.getDependencies().create("org.asciidoctor:asciidoctorj-pdf:1.5.3")); + }); } /** - * Requests the base Spring Documentation Resources from {@literal https://repo.spring.io/release} and uses it - * to format and render documentation. + * Requests the base Spring Documentation Resources from {@literal Maven Central} and uses it to format + * and render documentation. * * @param project {@literal this} Gradle {@link Project}. - * @return a {@link Sync} task used to copy the Spring Documentation Resources to a build directory + * @return a {@link Sync} task that copies Spring Documentation Resources to the build directory * used to generate documentation. - * @see spring-doc-resources * @see org.gradle.api.tasks.Sync * @see org.gradle.api.Project */ @SuppressWarnings("all") - private Sync createSyncDocumentationResourcesTask(Project project) { + private Sync createUnzipDocumentationResourcesTask(Project project) { - Configuration documentationResources = project.getConfigurations().maybeCreate("documentationResources"); + Configuration documentationResources = project.getConfigurations().create("documentationResources"); documentationResources.getDependencies() .add(project.getDependencies().create(SPRING_ASCIIDOCTOR_BACKENDS_DEPENDENCY)); @@ -164,33 +172,45 @@ public class AsciidoctorConventionPlugin implements Plugin { return unzipResources; } - @SuppressWarnings("unused") + private void configureAsciidoctorTask(Project project, AbstractAsciidoctorTask asciidoctorTask) { + + asciidoctorTask.baseDirFollowsSourceDir(); + asciidoctorTask.configurations("asciidoctorExtensions"); + //asciidoctorTask.useIntermediateWorkDir(); + + configureAttributes(project, asciidoctorTask); + configureForkOptions(asciidoctorTask); + configureOptions(asciidoctorTask); + + if (asciidoctorTask instanceof AsciidoctorTask) { + boolean pdf = asciidoctorTask.getName().toLowerCase().contains("pdf"); + String backend = pdf ? "spring-pdf" : "spring-html"; + ((AsciidoctorTask) asciidoctorTask).outputOptions((outputOptions) -> outputOptions.backends(backend)); + configureHtmlOnlyAttributes(asciidoctorTask); + } + } + private void configureAttributes(Project project, AbstractAsciidoctorTask asciidoctorTask) { Map attributes = new HashMap<>(); attributes.put("attribute-missing", "warn"); attributes.put("docinfo", "shared"); - attributes.put("icons", "font"); attributes.put("idprefix", ""); attributes.put("idseparator", "-"); attributes.put("sectanchors", ""); attributes.put("sectnums", ""); attributes.put("today-year", LocalDate.now().getYear()); + Object version = project.getVersion(); + + if (version != null && !Project.DEFAULT_VERSION.equals(version)) { + attributes.put("revnumber", version); + } + asciidoctorTask.attributes(attributes); } - private void configureExtensions(Project project, AbstractAsciidoctorTask asciidoctorTask) { - - Configuration extensionsConfiguration = project.getConfigurations().maybeCreate("asciidoctorExtensions"); - - extensionsConfiguration.defaultDependencies(dependencies -> dependencies.add(project.getDependencies() - .create(SPRING_ASCIIDOCTOR_EXTENSION_BLOCK_SWITCH_DEPENDENCY))); - - asciidoctorTask.configurations(extensionsConfiguration); - } - private void configureForkOptions(AbstractAsciidoctorTask asciidoctorTask) { if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) { asciidoctorTask.forkOptions(options -> options.jvmArgs( @@ -200,28 +220,18 @@ public class AsciidoctorConventionPlugin implements Plugin { } } - private void configureHtmlOnlyAttributes(Project project, AbstractAsciidoctorTask asciidoctorTask) { + private void configureHtmlOnlyAttributes(AbstractAsciidoctorTask asciidoctorTask) { Map attributes = new HashMap<>(); - attributes.put("source-highlighter", "highlight.js"); attributes.put("highlightjsdir", "js/highlight"); attributes.put("highlightjs-theme", "github"); - attributes.put("linkcss", true); + attributes.put("source-highlighter", "highlight.js"); attributes.put("icons", "font"); - - asciidoctorTask.getAttributeProviders().add(() -> { - - Object version = project.getVersion(); - - Map localAttributes = new HashMap<>(); - - if (version != null && !Project.DEFAULT_VERSION.equals(version)) { - localAttributes.put("revnumber", version); - } - - return localAttributes; - }); + attributes.put("imagesdir", "./images"); + attributes.put("linkcss", true); + attributes.put("stylesdir", "css/"); + //attributes.put("stylesheet", "spring.css"); asciidoctorTask.attributes(attributes); } @@ -229,8 +239,4 @@ public class AsciidoctorConventionPlugin implements Plugin { private void configureOptions(AbstractAsciidoctorTask asciidoctorTask) { asciidoctorTask.options(Collections.singletonMap("doctype", "book")); } - - private void makeAllWarningsFatal(Project project) { - project.getExtensions().getByType(AsciidoctorJExtension.class).fatalWarnings(".*"); - } } diff --git a/spring-geode-project/spring-geode-docs/spring-geode-docs.gradle b/spring-geode-project/spring-geode-docs/spring-geode-docs.gradle index f12221ae..19ab5a1c 100644 --- a/spring-geode-project/spring-geode-docs/spring-geode-docs.gradle +++ b/spring-geode-project/spring-geode-docs/spring-geode-docs.gradle @@ -9,10 +9,6 @@ apply plugin: 'io.spring.convention.spring-test' description = "Generate Javadoc and Reference Documentation on Spring Boot for Apache Geode" -repositories { - maven { url "https://repo.spring.io/release" } -} - dependencies { implementation project(':spring-geode-starter')