Skip to content

Commit 0abc763

Browse files
committed
Fix incompatibility with AsciidoctorJ 3.0
AsciidoctorJ 3.0 contains a breaking change to the signature of Preprocessor#process. This commit avoids this incompatibility by rewriting the preprocessor extension in Ruby. Fixes gh-949
1 parent 690371b commit 0abc763

File tree

5 files changed

+35
-72
lines changed

5 files changed

+35
-72
lines changed

spring-restdocs-asciidoctor/build.gradle

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
id "java-library"
33
id "maven-publish"
4+
id "io.spring.compatibility-test" version "0.0.3"
45
}
56

67
description = "Spring REST Docs Asciidoctor Extension"
@@ -19,3 +20,11 @@ dependencies {
1920

2021
testRuntimeOnly("org.asciidoctor:asciidoctorj-pdf")
2122
}
23+
24+
compatibilityTest {
25+
dependency("AsciidoctorJ") { asciidoctorj ->
26+
asciidoctorj.groupId = "org.asciidoctor"
27+
asciidoctorj.artifactId = "asciidoctorj"
28+
asciidoctorj.versions = ["3.0.0"]
29+
}
30+
}

spring-restdocs-asciidoctor/src/main/java/org/springframework/restdocs/asciidoctor/RestDocsExtensionRegistry.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2023 the original author or authors.
2+
* Copyright 2014-2024 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.
@@ -28,7 +28,9 @@ public final class RestDocsExtensionRegistry implements ExtensionRegistry {
2828

2929
@Override
3030
public void register(Asciidoctor asciidoctor) {
31-
asciidoctor.javaExtensionRegistry().preprocessor(new DefaultAttributesPreprocessor());
31+
asciidoctor.rubyExtensionRegistry()
32+
.loadClass(RestDocsExtensionRegistry.class.getResourceAsStream("/extensions/default_attributes.rb"))
33+
.preprocessor("DefaultAttributes");
3234
asciidoctor.rubyExtensionRegistry()
3335
.loadClass(RestDocsExtensionRegistry.class.getResourceAsStream("/extensions/operation_block_macro.rb"))
3436
.blockMacro("operation", "OperationBlockMacro");

spring-restdocs-asciidoctor/src/main/java/org/springframework/restdocs/asciidoctor/SnippetsDirectoryResolver.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2021 the original author or authors.
2+
* Copyright 2014-2024 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.
@@ -30,9 +30,14 @@
3030
*
3131
* @author Andy Wilkinson
3232
*/
33-
class SnippetsDirectoryResolver {
33+
public class SnippetsDirectoryResolver {
3434

35-
File getSnippetsDirectory(Map<String, Object> attributes) {
35+
/**
36+
* Returns the snippets directory derived from the given {@code attributes}.
37+
* @param attributes the attributes
38+
* @return the snippets directory
39+
*/
40+
public File getSnippetsDirectory(Map<String, Object> attributes) {
3641
if (System.getProperty("maven.home") != null) {
3742
return getMavenSnippetsDirectory(attributes);
3843
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require 'asciidoctor/extensions'
2+
require 'java'
3+
4+
class DefaultAttributes < Asciidoctor::Extensions::Preprocessor
5+
6+
def process(document, reader)
7+
resolver = org.springframework.restdocs.asciidoctor.SnippetsDirectoryResolver.new()
8+
attributes = document.attributes
9+
attributes["snippets"] = resolver.getSnippetsDirectory(attributes) unless attributes.has_key?("snippets")
10+
false
11+
end
12+
13+
end
14+

spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/DefaultAttributesPreprocessorTests.java

-67
This file was deleted.

0 commit comments

Comments
 (0)