From 1e96e3e71a7be17a560a37530d030e34bb297047 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 28 Sep 2021 10:36:30 +0100 Subject: [PATCH] Raise the minimum supported version of AsciidoctorJ to 2.5 Closes gh-751 --- docs/src/docs/asciidoc/getting-started.adoc | 2 +- gradle.properties | 1 + samples/rest-notes-spring-data-rest/pom.xml | 5 +- settings.gradle | 4 -- spring-restdocs-asciidoctor-1.5/build.gradle | 19 ------ ...tAttributesAsciidoctorJ15Preprocessor.java | 40 ----------- ...stDocsAsciidoctorJ15ExtensionRegistry.java | 50 -------------- ...ibutesAsciidoctorJ15PreprocessorTests.java | 67 ------------------- spring-restdocs-asciidoctor-1.6/build.gradle | 19 ------ ...stDocsAsciidoctorJ16ExtensionRegistry.java | 50 -------------- ...ibutesAsciidoctorJ16PreprocessorTests.java | 67 ------------------- spring-restdocs-asciidoctor-2.x/build.gradle | 18 ----- ...tAttributesAsciidoctorJ2xPreprocessor.java | 39 ----------- .../build.gradle | 12 ---- spring-restdocs-asciidoctor/build.gradle | 36 +--------- .../DefaultAttributesPreprocessor.java | 4 +- .../RestDocsExtensionRegistry.java | 11 ++- .../SnippetsDirectoryResolver.java | 2 +- ...sciidoctor.extension.spi.ExtensionRegistry | 2 - ...ctor.jruby.extension.spi.ExtensionRegistry | 2 +- .../extensions/operation_block_macro.rb | 0 .../AbstractOperationBlockMacroTests.java | 5 +- .../DefaultAttributesPreprocessorTests.java | 12 ++-- .../GradleOperationBlockMacroTests.java | 12 ++-- .../MavenOperationBlockMacroTests.java | 10 +-- .../SnippetsDirectoryResolverTests.java | 2 +- spring-restdocs-platform/build.gradle | 3 +- 27 files changed, 37 insertions(+), 457 deletions(-) delete mode 100644 spring-restdocs-asciidoctor-1.5/build.gradle delete mode 100644 spring-restdocs-asciidoctor-1.5/src/main/java/org/springframework/restdocs/asciidoctor/DefaultAttributesAsciidoctorJ15Preprocessor.java delete mode 100644 spring-restdocs-asciidoctor-1.5/src/main/java/org/springframework/restdocs/asciidoctor/RestDocsAsciidoctorJ15ExtensionRegistry.java delete mode 100644 spring-restdocs-asciidoctor-1.5/src/test/java/org/springframework/restdocs/asciidoctor/DefaultAttributesAsciidoctorJ15PreprocessorTests.java delete mode 100644 spring-restdocs-asciidoctor-1.6/build.gradle delete mode 100644 spring-restdocs-asciidoctor-1.6/src/main/java/org/springframework/restdocs/asciidoctor/RestDocsAsciidoctorJ16ExtensionRegistry.java delete mode 100644 spring-restdocs-asciidoctor-1.6/src/test/java/org/springframework/restdocs/asciidoctor/DefaultAttributesAsciidoctorJ16PreprocessorTests.java delete mode 100644 spring-restdocs-asciidoctor-2.x/build.gradle delete mode 100644 spring-restdocs-asciidoctor-2.x/src/main/java/org/springframework/restdocs/asciidoctor/DefaultAttributesAsciidoctorJ2xPreprocessor.java delete mode 100644 spring-restdocs-asciidoctor-support/build.gradle rename spring-restdocs-asciidoctor-1.6/src/main/java/org/springframework/restdocs/asciidoctor/DefaultAttributesAsciidoctorJ16Preprocessor.java => spring-restdocs-asciidoctor/src/main/java/org/springframework/restdocs/asciidoctor/DefaultAttributesPreprocessor.java (90%) rename spring-restdocs-asciidoctor-2.x/src/main/java/org/springframework/restdocs/asciidoctor/RestDocsAsciidoctorJ2xExtensionRegistry.java => spring-restdocs-asciidoctor/src/main/java/org/springframework/restdocs/asciidoctor/RestDocsExtensionRegistry.java (71%) rename {spring-restdocs-asciidoctor-support => spring-restdocs-asciidoctor}/src/main/java/org/springframework/restdocs/asciidoctor/SnippetsDirectoryResolver.java (97%) delete mode 100644 spring-restdocs-asciidoctor/src/main/resources/META-INF/services/org.asciidoctor.extension.spi.ExtensionRegistry rename {spring-restdocs-asciidoctor-support => spring-restdocs-asciidoctor}/src/main/resources/extensions/operation_block_macro.rb (100%) rename spring-restdocs-asciidoctor-2.x/src/test/java/org/springframework/restdocs/asciidoctor/DefaultAttributesAsciidoctorJ2xPreprocessorTests.java => spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/DefaultAttributesPreprocessorTests.java (85%) rename {spring-restdocs-asciidoctor-support => spring-restdocs-asciidoctor}/src/test/java/org/springframework/restdocs/asciidoctor/SnippetsDirectoryResolverTests.java (98%) diff --git a/docs/src/docs/asciidoc/getting-started.adoc b/docs/src/docs/asciidoc/getting-started.adoc index 7e586aba..9e39dce2 100644 --- a/docs/src/docs/asciidoc/getting-started.adoc +++ b/docs/src/docs/asciidoc/getting-started.adoc @@ -106,7 +106,7 @@ the configuration are described in the following listings: <2> org.asciidoctor asciidoctor-maven-plugin - 1.5.8 + 2.2.1 generate-docs diff --git a/gradle.properties b/gradle.properties index de5af153..934f07db 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,4 +13,5 @@ asciidoctorj24Version=2.4.3 asciidoctorj25Version=2.5.1 javaFormatVersion=0.0.27 + jmustacheVersion=1.12 diff --git a/samples/rest-notes-spring-data-rest/pom.xml b/samples/rest-notes-spring-data-rest/pom.xml index 82453e87..71d008cd 100644 --- a/samples/rest-notes-spring-data-rest/pom.xml +++ b/samples/rest-notes-spring-data-rest/pom.xml @@ -83,7 +83,7 @@ org.asciidoctor asciidoctor-maven-plugin - 1.5.8 + 2.2.1 generate-docs @@ -96,9 +96,6 @@ book true - - DEBUG - diff --git a/settings.gradle b/settings.gradle index 45a29672..2e81bf85 100644 --- a/settings.gradle +++ b/settings.gradle @@ -36,10 +36,6 @@ settings.gradle.projectsLoaded { include "docs" include "spring-restdocs-asciidoctor" -include "spring-restdocs-asciidoctor-1.5" -include "spring-restdocs-asciidoctor-1.6" -include "spring-restdocs-asciidoctor-2.x" -include "spring-restdocs-asciidoctor-support" include "spring-restdocs-core" include "spring-restdocs-mockmvc" include "spring-restdocs-platform" diff --git a/spring-restdocs-asciidoctor-1.5/build.gradle b/spring-restdocs-asciidoctor-1.5/build.gradle deleted file mode 100644 index 05dfb19a..00000000 --- a/spring-restdocs-asciidoctor-1.5/build.gradle +++ /dev/null @@ -1,19 +0,0 @@ -plugins { - id "java" -} - -description = "AsciidoctorJ 1.5 extensions for Spring REST Docs" - -dependencies { - compileOnly("org.asciidoctor:asciidoctorj:$asciidoctorj15Version") - - implementation(project(":spring-restdocs-asciidoctor-support")) - - internal(platform(project(":spring-restdocs-platform"))) - - testImplementation("junit:junit") - testImplementation("org.asciidoctor:asciidoctorj:$asciidoctorj15Version") - testImplementation("org.assertj:assertj-core") - - testRuntimeOnly(project(":spring-restdocs-asciidoctor-support")) -} diff --git a/spring-restdocs-asciidoctor-1.5/src/main/java/org/springframework/restdocs/asciidoctor/DefaultAttributesAsciidoctorJ15Preprocessor.java b/spring-restdocs-asciidoctor-1.5/src/main/java/org/springframework/restdocs/asciidoctor/DefaultAttributesAsciidoctorJ15Preprocessor.java deleted file mode 100644 index d1dd4018..00000000 --- a/spring-restdocs-asciidoctor-1.5/src/main/java/org/springframework/restdocs/asciidoctor/DefaultAttributesAsciidoctorJ15Preprocessor.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2014-2019 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.restdocs.asciidoctor; - -import org.asciidoctor.ast.Document; -import org.asciidoctor.extension.Preprocessor; -import org.asciidoctor.extension.PreprocessorReader; - -/** - * {@link Preprocessor} that sets defaults for REST Docs-related {@link Document} - * attributes. - * - * @author Andy Wilkinson - */ -final class DefaultAttributesAsciidoctorJ15Preprocessor extends Preprocessor { - - private final SnippetsDirectoryResolver snippetsDirectoryResolver = new SnippetsDirectoryResolver(); - - @Override - public PreprocessorReader process(Document document, PreprocessorReader reader) { - document.setAttr("snippets", this.snippetsDirectoryResolver.getSnippetsDirectory(document.getAttributes()), - false); - return reader; - } - -} diff --git a/spring-restdocs-asciidoctor-1.5/src/main/java/org/springframework/restdocs/asciidoctor/RestDocsAsciidoctorJ15ExtensionRegistry.java b/spring-restdocs-asciidoctor-1.5/src/main/java/org/springframework/restdocs/asciidoctor/RestDocsAsciidoctorJ15ExtensionRegistry.java deleted file mode 100644 index 8c0734c0..00000000 --- a/spring-restdocs-asciidoctor-1.5/src/main/java/org/springframework/restdocs/asciidoctor/RestDocsAsciidoctorJ15ExtensionRegistry.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2014-2019 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.restdocs.asciidoctor; - -import org.asciidoctor.Asciidoctor; -import org.asciidoctor.extension.spi.ExtensionRegistry; - -/** - * AsciidoctorJ 1.5 {@link ExtensionRegistry} for Spring REST Docs. - * - * @author Andy Wilkinson - */ -public final class RestDocsAsciidoctorJ15ExtensionRegistry implements ExtensionRegistry { - - @Override - public void register(Asciidoctor asciidoctor) { - if (!asciidoctorJ15()) { - return; - } - asciidoctor.javaExtensionRegistry().preprocessor(new DefaultAttributesAsciidoctorJ15Preprocessor()); - asciidoctor.rubyExtensionRegistry() - .loadClass(RestDocsAsciidoctorJ15ExtensionRegistry.class - .getResourceAsStream("/extensions/operation_block_macro.rb")) - .blockMacro("operation", "OperationBlockMacro"); - } - - private boolean asciidoctorJ15() { - try { - return !Class.forName("org.asciidoctor.extension.JavaExtensionRegistry").isInterface(); - } - catch (Throwable ex) { - return false; - } - } - -} diff --git a/spring-restdocs-asciidoctor-1.5/src/test/java/org/springframework/restdocs/asciidoctor/DefaultAttributesAsciidoctorJ15PreprocessorTests.java b/spring-restdocs-asciidoctor-1.5/src/test/java/org/springframework/restdocs/asciidoctor/DefaultAttributesAsciidoctorJ15PreprocessorTests.java deleted file mode 100644 index 1dcd9153..00000000 --- a/spring-restdocs-asciidoctor-1.5/src/test/java/org/springframework/restdocs/asciidoctor/DefaultAttributesAsciidoctorJ15PreprocessorTests.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2014-2019 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.restdocs.asciidoctor; - -import java.io.File; - -import org.asciidoctor.Asciidoctor; -import org.asciidoctor.Attributes; -import org.asciidoctor.Options; -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link DefaultAttributesAsciidoctorJ15Preprocessor}. - * - * @author Andy Wilkinson - */ -public class DefaultAttributesAsciidoctorJ15PreprocessorTests { - - @Test - public void snippetsAttributeIsSet() { - String converted = createAsciidoctor().convert("{snippets}", createOptions("projectdir=../../..")); - assertThat(converted).contains("build" + File.separatorChar + "generated-snippets"); - } - - @Test - public void snippetsAttributeFromConvertArgumentIsNotOverridden() { - String converted = createAsciidoctor().convert("{snippets}", - createOptions("snippets=custom projectdir=../../..")); - assertThat(converted).contains("custom"); - } - - @Test - public void snippetsAttributeFromDocumentPreambleIsNotOverridden() { - String converted = createAsciidoctor().convert(":snippets: custom\n{snippets}", - createOptions("projectdir=../../..")); - assertThat(converted).contains("custom"); - } - - private Options createOptions(String attributes) { - Options options = new Options(); - options.setAttributes(new Attributes(attributes)); - return options; - } - - private Asciidoctor createAsciidoctor() { - Asciidoctor asciidoctor = Asciidoctor.Factory.create(); - asciidoctor.javaExtensionRegistry().preprocessor(new DefaultAttributesAsciidoctorJ15Preprocessor()); - return asciidoctor; - } - -} diff --git a/spring-restdocs-asciidoctor-1.6/build.gradle b/spring-restdocs-asciidoctor-1.6/build.gradle deleted file mode 100644 index 7a9695a6..00000000 --- a/spring-restdocs-asciidoctor-1.6/build.gradle +++ /dev/null @@ -1,19 +0,0 @@ -plugins { - id "java" -} - -description = "AsciidoctorJ 1.6 extensions for Spring REST Docs" - -dependencies { - compileOnly("org.asciidoctor:asciidoctorj:$asciidoctorj16Version") - - implementation(project(":spring-restdocs-asciidoctor-support")) - - internal(platform(project(":spring-restdocs-platform"))) - - testImplementation("junit:junit") - testImplementation("org.asciidoctor:asciidoctorj:$asciidoctorj16Version") - testImplementation("org.assertj:assertj-core") - - testRuntimeOnly(project(":spring-restdocs-asciidoctor-support")) -} diff --git a/spring-restdocs-asciidoctor-1.6/src/main/java/org/springframework/restdocs/asciidoctor/RestDocsAsciidoctorJ16ExtensionRegistry.java b/spring-restdocs-asciidoctor-1.6/src/main/java/org/springframework/restdocs/asciidoctor/RestDocsAsciidoctorJ16ExtensionRegistry.java deleted file mode 100644 index b115bd98..00000000 --- a/spring-restdocs-asciidoctor-1.6/src/main/java/org/springframework/restdocs/asciidoctor/RestDocsAsciidoctorJ16ExtensionRegistry.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2014-2019 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.restdocs.asciidoctor; - -import org.asciidoctor.Asciidoctor; -import org.asciidoctor.extension.spi.ExtensionRegistry; - -/** - * AsciidoctorJ 1.6 {@link ExtensionRegistry} for Spring REST Docs. - * - * @author Andy Wilkinson - */ -public final class RestDocsAsciidoctorJ16ExtensionRegistry implements ExtensionRegistry { - - @Override - public void register(Asciidoctor asciidoctor) { - if (!asciidoctorJ16()) { - return; - } - asciidoctor.javaExtensionRegistry().preprocessor(new DefaultAttributesAsciidoctorJ16Preprocessor()); - asciidoctor.rubyExtensionRegistry() - .loadClass(RestDocsAsciidoctorJ16ExtensionRegistry.class - .getResourceAsStream("/extensions/operation_block_macro.rb")) - .blockMacro("operation", "OperationBlockMacro"); - } - - private boolean asciidoctorJ16() { - try { - return Class.forName("org.asciidoctor.extension.JavaExtensionRegistry").isInterface(); - } - catch (Throwable ex) { - return false; - } - } - -} diff --git a/spring-restdocs-asciidoctor-1.6/src/test/java/org/springframework/restdocs/asciidoctor/DefaultAttributesAsciidoctorJ16PreprocessorTests.java b/spring-restdocs-asciidoctor-1.6/src/test/java/org/springframework/restdocs/asciidoctor/DefaultAttributesAsciidoctorJ16PreprocessorTests.java deleted file mode 100644 index ec91a339..00000000 --- a/spring-restdocs-asciidoctor-1.6/src/test/java/org/springframework/restdocs/asciidoctor/DefaultAttributesAsciidoctorJ16PreprocessorTests.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2014-2019 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.restdocs.asciidoctor; - -import java.io.File; - -import org.asciidoctor.Asciidoctor; -import org.asciidoctor.Attributes; -import org.asciidoctor.Options; -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link DefaultAttributesAsciidoctorJ16Preprocessor}. - * - * @author Andy Wilkinson - */ -public class DefaultAttributesAsciidoctorJ16PreprocessorTests { - - @Test - public void snippetsAttributeIsSet() { - String converted = createAsciidoctor().convert("{snippets}", createOptions("projectdir=../../..")); - assertThat(converted).contains("build" + File.separatorChar + "generated-snippets"); - } - - @Test - public void snippetsAttributeFromConvertArgumentIsNotOverridden() { - String converted = createAsciidoctor().convert("{snippets}", - createOptions("snippets=custom projectdir=../../..")); - assertThat(converted).contains("custom"); - } - - @Test - public void snippetsAttributeFromDocumentPreambleIsNotOverridden() { - String converted = createAsciidoctor().convert(":snippets: custom\n{snippets}", - createOptions("projectdir=../../..")); - assertThat(converted).contains("custom"); - } - - private Options createOptions(String attributes) { - Options options = new Options(); - options.setAttributes(new Attributes(attributes)); - return options; - } - - private Asciidoctor createAsciidoctor() { - Asciidoctor asciidoctor = Asciidoctor.Factory.create(); - asciidoctor.javaExtensionRegistry().preprocessor(new DefaultAttributesAsciidoctorJ16Preprocessor()); - return asciidoctor; - } - -} diff --git a/spring-restdocs-asciidoctor-2.x/build.gradle b/spring-restdocs-asciidoctor-2.x/build.gradle deleted file mode 100644 index bc6361e7..00000000 --- a/spring-restdocs-asciidoctor-2.x/build.gradle +++ /dev/null @@ -1,18 +0,0 @@ -plugins { - id "java" -} -description = "AsciidoctorJ 2.x extensions for Spring REST Docs" - -dependencies { - compileOnly("org.asciidoctor:asciidoctorj:$asciidoctorj20Version") - - implementation(project(":spring-restdocs-asciidoctor-support")) - - internal(platform(project(":spring-restdocs-platform"))) - - testImplementation("junit:junit") - testImplementation("org.asciidoctor:asciidoctorj:$asciidoctorj20Version") - testImplementation("org.assertj:assertj-core") - - testRuntimeOnly(project(":spring-restdocs-asciidoctor-support")) -} diff --git a/spring-restdocs-asciidoctor-2.x/src/main/java/org/springframework/restdocs/asciidoctor/DefaultAttributesAsciidoctorJ2xPreprocessor.java b/spring-restdocs-asciidoctor-2.x/src/main/java/org/springframework/restdocs/asciidoctor/DefaultAttributesAsciidoctorJ2xPreprocessor.java deleted file mode 100644 index 3ed0a62c..00000000 --- a/spring-restdocs-asciidoctor-2.x/src/main/java/org/springframework/restdocs/asciidoctor/DefaultAttributesAsciidoctorJ2xPreprocessor.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2014-2019 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.restdocs.asciidoctor; - -import org.asciidoctor.ast.Document; -import org.asciidoctor.extension.Preprocessor; -import org.asciidoctor.extension.PreprocessorReader; - -/** - * {@link Preprocessor} that sets defaults for REST Docs-related {@link Document} - * attributes. - * - * @author Andy Wilkinson - */ -final class DefaultAttributesAsciidoctorJ2xPreprocessor extends Preprocessor { - - private final SnippetsDirectoryResolver snippetsDirectoryResolver = new SnippetsDirectoryResolver(); - - @Override - public void process(Document document, PreprocessorReader reader) { - document.setAttribute("snippets", this.snippetsDirectoryResolver.getSnippetsDirectory(document.getAttributes()), - false); - } - -} diff --git a/spring-restdocs-asciidoctor-support/build.gradle b/spring-restdocs-asciidoctor-support/build.gradle deleted file mode 100644 index a6ef58c4..00000000 --- a/spring-restdocs-asciidoctor-support/build.gradle +++ /dev/null @@ -1,12 +0,0 @@ -plugins { - id "java" -} - -description = "Support code for AsciidoctorJ extensions for Spring REST Docs" - -dependencies { - internal(platform(project(":spring-restdocs-platform"))) - - testImplementation("junit:junit") - testImplementation("org.assertj:assertj-core") -} diff --git a/spring-restdocs-asciidoctor/build.gradle b/spring-restdocs-asciidoctor/build.gradle index 1a6d429b..149c81e2 100644 --- a/spring-restdocs-asciidoctor/build.gradle +++ b/spring-restdocs-asciidoctor/build.gradle @@ -1,51 +1,19 @@ plugins { - id "io.spring.compatibility-test" version "0.0.1" id "java-library" id "maven-publish" } description = "Spring REST Docs Asciidoctor Extension" -configurations { - merge - testRuntimeOnly { extendsFrom merge } -} - dependencies { - internal(platform(project(":spring-restdocs-platform"))) + implementation("org.asciidoctor:asciidoctorj") - merge project(":spring-restdocs-asciidoctor-1.5") - merge project(":spring-restdocs-asciidoctor-1.6") - merge project(":spring-restdocs-asciidoctor-2.x") + internal(platform(project(":spring-restdocs-platform"))) testImplementation("junit:junit") testImplementation("org.apache.pdfbox:pdfbox") - testImplementation("org.asciidoctor:asciidoctorj:1.5.8.1") testImplementation("org.assertj:assertj-core") testImplementation("org.springframework:spring-core") testRuntimeOnly("org.asciidoctor:asciidoctorj-pdf") } - -jar { - dependsOn(":spring-restdocs-asciidoctor-1.5:jar") - dependsOn(":spring-restdocs-asciidoctor-1.6:jar") - dependsOn(":spring-restdocs-asciidoctor-2.x:jar") - from configurations.merge.collect { file -> zipTree(file) } -} - -compatibilityTest { - dependency('AsciidoctorJ') { asciidoctorJ -> - asciidoctorJ.groupId = "org.asciidoctor" - asciidoctorJ.artifactId = "asciidoctorj" - asciidoctorJ.versions = [ - asciidoctorj16Version, - asciidoctorj20Version, - asciidoctorj21Version, - asciidoctorj22Version, - asciidoctorj23Version, - asciidoctorj24Version, - asciidoctorj25Version, - ] - } -} diff --git a/spring-restdocs-asciidoctor-1.6/src/main/java/org/springframework/restdocs/asciidoctor/DefaultAttributesAsciidoctorJ16Preprocessor.java b/spring-restdocs-asciidoctor/src/main/java/org/springframework/restdocs/asciidoctor/DefaultAttributesPreprocessor.java similarity index 90% rename from spring-restdocs-asciidoctor-1.6/src/main/java/org/springframework/restdocs/asciidoctor/DefaultAttributesAsciidoctorJ16Preprocessor.java rename to spring-restdocs-asciidoctor/src/main/java/org/springframework/restdocs/asciidoctor/DefaultAttributesPreprocessor.java index 409cf658..1d1be53b 100644 --- a/spring-restdocs-asciidoctor-1.6/src/main/java/org/springframework/restdocs/asciidoctor/DefaultAttributesAsciidoctorJ16Preprocessor.java +++ b/spring-restdocs-asciidoctor/src/main/java/org/springframework/restdocs/asciidoctor/DefaultAttributesPreprocessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2021 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. @@ -26,7 +26,7 @@ import org.asciidoctor.extension.PreprocessorReader; * * @author Andy Wilkinson */ -final class DefaultAttributesAsciidoctorJ16Preprocessor extends Preprocessor { +final class DefaultAttributesPreprocessor extends Preprocessor { private final SnippetsDirectoryResolver snippetsDirectoryResolver = new SnippetsDirectoryResolver(); diff --git a/spring-restdocs-asciidoctor-2.x/src/main/java/org/springframework/restdocs/asciidoctor/RestDocsAsciidoctorJ2xExtensionRegistry.java b/spring-restdocs-asciidoctor/src/main/java/org/springframework/restdocs/asciidoctor/RestDocsExtensionRegistry.java similarity index 71% rename from spring-restdocs-asciidoctor-2.x/src/main/java/org/springframework/restdocs/asciidoctor/RestDocsAsciidoctorJ2xExtensionRegistry.java rename to spring-restdocs-asciidoctor/src/main/java/org/springframework/restdocs/asciidoctor/RestDocsExtensionRegistry.java index 973b1b8c..f2ad6551 100644 --- a/spring-restdocs-asciidoctor-2.x/src/main/java/org/springframework/restdocs/asciidoctor/RestDocsAsciidoctorJ2xExtensionRegistry.java +++ b/spring-restdocs-asciidoctor/src/main/java/org/springframework/restdocs/asciidoctor/RestDocsExtensionRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2021 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. @@ -20,18 +20,17 @@ import org.asciidoctor.Asciidoctor; import org.asciidoctor.jruby.extension.spi.ExtensionRegistry; /** - * AsciidoctorJ 2.x {@link ExtensionRegistry} for Spring REST Docs. + * {@link ExtensionRegistry} for Spring REST Docs. * * @author Andy Wilkinson */ -public final class RestDocsAsciidoctorJ2xExtensionRegistry implements ExtensionRegistry { +public final class RestDocsExtensionRegistry implements ExtensionRegistry { @Override public void register(Asciidoctor asciidoctor) { - asciidoctor.javaExtensionRegistry().preprocessor(new DefaultAttributesAsciidoctorJ2xPreprocessor()); + asciidoctor.javaExtensionRegistry().preprocessor(new DefaultAttributesPreprocessor()); asciidoctor.rubyExtensionRegistry() - .loadClass(RestDocsAsciidoctorJ2xExtensionRegistry.class - .getResourceAsStream("/extensions/operation_block_macro.rb")) + .loadClass(RestDocsExtensionRegistry.class.getResourceAsStream("/extensions/operation_block_macro.rb")) .blockMacro("operation", "OperationBlockMacro"); } diff --git a/spring-restdocs-asciidoctor-support/src/main/java/org/springframework/restdocs/asciidoctor/SnippetsDirectoryResolver.java b/spring-restdocs-asciidoctor/src/main/java/org/springframework/restdocs/asciidoctor/SnippetsDirectoryResolver.java similarity index 97% rename from spring-restdocs-asciidoctor-support/src/main/java/org/springframework/restdocs/asciidoctor/SnippetsDirectoryResolver.java rename to spring-restdocs-asciidoctor/src/main/java/org/springframework/restdocs/asciidoctor/SnippetsDirectoryResolver.java index 87c83cad..af2e9482 100644 --- a/spring-restdocs-asciidoctor-support/src/main/java/org/springframework/restdocs/asciidoctor/SnippetsDirectoryResolver.java +++ b/spring-restdocs-asciidoctor/src/main/java/org/springframework/restdocs/asciidoctor/SnippetsDirectoryResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2021 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. diff --git a/spring-restdocs-asciidoctor/src/main/resources/META-INF/services/org.asciidoctor.extension.spi.ExtensionRegistry b/spring-restdocs-asciidoctor/src/main/resources/META-INF/services/org.asciidoctor.extension.spi.ExtensionRegistry deleted file mode 100644 index ccdd8d45..00000000 --- a/spring-restdocs-asciidoctor/src/main/resources/META-INF/services/org.asciidoctor.extension.spi.ExtensionRegistry +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.restdocs.asciidoctor.RestDocsAsciidoctorJ15ExtensionRegistry -org.springframework.restdocs.asciidoctor.RestDocsAsciidoctorJ16ExtensionRegistry diff --git a/spring-restdocs-asciidoctor/src/main/resources/META-INF/services/org.asciidoctor.jruby.extension.spi.ExtensionRegistry b/spring-restdocs-asciidoctor/src/main/resources/META-INF/services/org.asciidoctor.jruby.extension.spi.ExtensionRegistry index 249b935a..7123d5b5 100644 --- a/spring-restdocs-asciidoctor/src/main/resources/META-INF/services/org.asciidoctor.jruby.extension.spi.ExtensionRegistry +++ b/spring-restdocs-asciidoctor/src/main/resources/META-INF/services/org.asciidoctor.jruby.extension.spi.ExtensionRegistry @@ -1 +1 @@ -org.springframework.restdocs.asciidoctor.RestDocsAsciidoctorJ2xExtensionRegistry +org.springframework.restdocs.asciidoctor.RestDocsExtensionRegistry diff --git a/spring-restdocs-asciidoctor-support/src/main/resources/extensions/operation_block_macro.rb b/spring-restdocs-asciidoctor/src/main/resources/extensions/operation_block_macro.rb similarity index 100% rename from spring-restdocs-asciidoctor-support/src/main/resources/extensions/operation_block_macro.rb rename to spring-restdocs-asciidoctor/src/main/resources/extensions/operation_block_macro.rb diff --git a/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/AbstractOperationBlockMacroTests.java b/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/AbstractOperationBlockMacroTests.java index e44b3b79..52445aa5 100644 --- a/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/AbstractOperationBlockMacroTests.java +++ b/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/AbstractOperationBlockMacroTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2021 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. @@ -34,7 +34,6 @@ import org.apache.pdfbox.pdmodel.PDDocument; import org.asciidoctor.Asciidoctor; import org.asciidoctor.Attributes; import org.asciidoctor.Options; -import org.asciidoctor.OptionsBuilder; import org.asciidoctor.SafeMode; import org.junit.After; import org.junit.Before; @@ -64,7 +63,7 @@ public abstract class AbstractOperationBlockMacroTests { @Before public void setUp() throws IOException { prepareOperationSnippets(getBuildOutputLocation()); - this.options = OptionsBuilder.options().safe(SafeMode.UNSAFE).baseDir(getSourceLocation()).get(); + this.options = Options.builder().safe(SafeMode.UNSAFE).baseDir(getSourceLocation()).build(); this.options.setAttributes(getAttributes()); CapturingLogHandler.clear(); } diff --git a/spring-restdocs-asciidoctor-2.x/src/test/java/org/springframework/restdocs/asciidoctor/DefaultAttributesAsciidoctorJ2xPreprocessorTests.java b/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/DefaultAttributesPreprocessorTests.java similarity index 85% rename from spring-restdocs-asciidoctor-2.x/src/test/java/org/springframework/restdocs/asciidoctor/DefaultAttributesAsciidoctorJ2xPreprocessorTests.java rename to spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/DefaultAttributesPreprocessorTests.java index 4bb84aab..154cd73f 100644 --- a/spring-restdocs-asciidoctor-2.x/src/test/java/org/springframework/restdocs/asciidoctor/DefaultAttributesAsciidoctorJ2xPreprocessorTests.java +++ b/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/DefaultAttributesPreprocessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2021 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. @@ -26,11 +26,11 @@ import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; /** - * Tests for {@link DefaultAttributesAsciidoctorJ2xPreprocessor}. + * Tests for {@link DefaultAttributesPreprocessor}. * * @author Andy Wilkinson */ -public class DefaultAttributesAsciidoctorJ2xPreprocessorTests { +public class DefaultAttributesPreprocessorTests { @Test public void snippetsAttributeIsSet() { @@ -53,14 +53,14 @@ public class DefaultAttributesAsciidoctorJ2xPreprocessorTests { } private Options createOptions(String attributes) { - Options options = new Options(); - options.setAttributes(new Attributes(attributes)); + Options options = Options.builder().build(); + options.setAttributes(Attributes.builder().arguments(attributes).build()); return options; } private Asciidoctor createAsciidoctor() { Asciidoctor asciidoctor = Asciidoctor.Factory.create(); - asciidoctor.javaExtensionRegistry().preprocessor(new DefaultAttributesAsciidoctorJ2xPreprocessor()); + asciidoctor.javaExtensionRegistry().preprocessor(new DefaultAttributesPreprocessor()); return asciidoctor; } diff --git a/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/GradleOperationBlockMacroTests.java b/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/GradleOperationBlockMacroTests.java index 04eddf35..df594537 100644 --- a/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/GradleOperationBlockMacroTests.java +++ b/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/GradleOperationBlockMacroTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2021 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. @@ -42,22 +42,24 @@ public class GradleOperationBlockMacroTests extends AbstractOperationBlockMacroT return new Object[] { "projectdir", "gradle-projectdir" }; } + @Override protected Attributes getAttributes() { - Attributes attributes = new Attributes(); - attributes.setAttribute(this.attributeName, new File(temp.getRoot(), "gradle-project").getAbsolutePath()); + Attributes attributes = Attributes.builder() + .attribute(this.attributeName, new File(this.temp.getRoot(), "gradle-project").getAbsolutePath()) + .build(); return attributes; } @Override protected File getBuildOutputLocation() { - File outputLocation = new File(temp.getRoot(), "gradle-project/build"); + File outputLocation = new File(this.temp.getRoot(), "gradle-project/build"); outputLocation.mkdirs(); return outputLocation; } @Override protected File getSourceLocation() { - File sourceLocation = new File(temp.getRoot(), "gradle-project/src/docs/asciidoc"); + File sourceLocation = new File(this.temp.getRoot(), "gradle-project/src/docs/asciidoc"); if (!sourceLocation.exists()) { sourceLocation.mkdirs(); } diff --git a/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/MavenOperationBlockMacroTests.java b/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/MavenOperationBlockMacroTests.java index 0738144c..702ed06b 100644 --- a/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/MavenOperationBlockMacroTests.java +++ b/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/MavenOperationBlockMacroTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2021 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. @@ -40,12 +40,12 @@ public class MavenOperationBlockMacroTests extends AbstractOperationBlockMacroTe System.clearProperty("maven.home"); } + @Override protected Attributes getAttributes() { try { File sourceLocation = getSourceLocation(); new File(sourceLocation.getParentFile().getParentFile().getParentFile(), "pom.xml").createNewFile(); - Attributes attributes = new Attributes(); - attributes.setAttribute("docdir", sourceLocation.getAbsolutePath()); + Attributes attributes = Attributes.builder().attribute("docdir", sourceLocation.getAbsolutePath()).build(); return attributes; } catch (IOException ex) { @@ -55,14 +55,14 @@ public class MavenOperationBlockMacroTests extends AbstractOperationBlockMacroTe @Override protected File getBuildOutputLocation() { - File outputLocation = new File(temp.getRoot(), "maven-project/target"); + File outputLocation = new File(this.temp.getRoot(), "maven-project/target"); outputLocation.mkdirs(); return outputLocation; } @Override protected File getSourceLocation() { - File sourceLocation = new File(temp.getRoot(), "maven-project/src/main/asciidoc"); + File sourceLocation = new File(this.temp.getRoot(), "maven-project/src/main/asciidoc"); if (!sourceLocation.exists()) { sourceLocation.mkdirs(); } diff --git a/spring-restdocs-asciidoctor-support/src/test/java/org/springframework/restdocs/asciidoctor/SnippetsDirectoryResolverTests.java b/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/SnippetsDirectoryResolverTests.java similarity index 98% rename from spring-restdocs-asciidoctor-support/src/test/java/org/springframework/restdocs/asciidoctor/SnippetsDirectoryResolverTests.java rename to spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/SnippetsDirectoryResolverTests.java index abf59eca..dafeb467 100644 --- a/spring-restdocs-asciidoctor-support/src/test/java/org/springframework/restdocs/asciidoctor/SnippetsDirectoryResolverTests.java +++ b/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/SnippetsDirectoryResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2021 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. diff --git a/spring-restdocs-platform/build.gradle b/spring-restdocs-platform/build.gradle index 529dae93..4d04aa5f 100644 --- a/spring-restdocs-platform/build.gradle +++ b/spring-restdocs-platform/build.gradle @@ -16,8 +16,9 @@ dependencies { api("junit:junit:4.12") api("io.rest-assured:rest-assured:4.4.0") api("org.apache.pdfbox:pdfbox:2.0.7") + api("org.asciidoctor:asciidoctorj:2.5.2") + api("org.asciidoctor:asciidoctorj-pdf:1.6.0") api("org.assertj:assertj-core:3.11.1") - api("org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.18") api("org.hamcrest:hamcrest-core:1.3") api("org.hamcrest:hamcrest-library:1.3") api("org.hibernate.validator:hibernate-validator:6.0.9.Final")