Skip to content

Commit 9a528ac

Browse files
authored
Add compatibility with maven-site-plugin v3.20.0 (#934)
* Bump Doxia and Doxia-sitetools to the same versions as maven-site-plugin (v2.0.x-MX) * Apply required code changes to code and test * Update site.xml in ITs to new novel (https://maven.apache.org/xsd/site-2.0.0.xsd) Fixes #933
1 parent 25cc1e5 commit 9a528ac

File tree

21 files changed

+137
-125
lines changed

21 files changed

+137
-125
lines changed

CHANGELOG.adoc

+2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/main[co
1616
Bug Fixes::
1717

1818
* Fix open IMG tags in parser-doxia-module (#930)
19+
* Fix naming in Asciidoctor Converter Doxia Module pom (#934)
1920

2021
Improvements::
2122

2223
* Added support for AsciidoctorJ v3.0.0 (#651)
24+
* Add compatibility with maven-site-plugin v3.20.0 and Doxia v2.0.0 (#933)
2325

2426
Build / Infrastructure::
2527

asciidoctor-converter-doxia-module/pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<artifactId>asciidoctor-converter-doxia-module</artifactId>
1313
<packaging>jar</packaging>
1414

15-
<name>Asciidoctor Converter Doxia Parser</name>
16-
<description>Asciidoctor Doxia Parser based on Asciidoctor Html converter (for Maven Site integration)</description>
15+
<name>Asciidoctor Converter Doxia Module</name>
16+
<description>Asciidoctor Doxia Module based on Asciidoctor Html converter (for Maven Site integration)</description>
1717
<url>https://github.com/asciidoctor/asciidoctor-maven-plugin</url>
1818

1919
<dependencies>
@@ -46,7 +46,7 @@
4646
<dependency>
4747
<groupId>org.apache.maven.doxia</groupId>
4848
<artifactId>doxia-site-renderer</artifactId>
49-
<version>1.11.1</version>
49+
<version>${doxia.sitetools.version}</version>
5050
<scope>test</scope>
5151
</dependency>
5252
</dependencies>

asciidoctor-converter-doxia-module/src/it/maven-site-plugin/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
<plugin>
2929
<groupId>org.apache.maven.plugins</groupId>
3030
<artifactId>maven-site-plugin</artifactId>
31-
<!-- v2.2.2 of the plugin require Maven Site Plugin 3.1x.0 alongside Doxia 1.11.1 -->
32-
<version>3.12.1</version>
31+
<version>3.20.0</version>
3332
<configuration>
3433
<asciidoc>
3534
<baseDir>${project.basedir}/src/site/asciidoc</baseDir>
@@ -52,6 +51,7 @@
5251
<toclevels>2</toclevels>
5352
</attributes>
5453
</asciidoc>
54+
<relativizeSiteLinks>false</relativizeSiteLinks>
5555
<moduleExcludes>
5656
<asciidoc>**/_*.adoc,**/_*/</asciidoc>
5757
</moduleExcludes>

asciidoctor-converter-doxia-module/src/it/maven-site-plugin/src/site/site.xml

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<project name="Maven Site Plugin IT">
1+
<site xmlns="http://maven.apache.org/SITE/2.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/SITE/2.0.0 https://maven.apache.org/xsd/site-2.0.0.xsd">
24
<body>
35
<breadcrumbs>
46
<item name="Doxia" href="https://maven.apache.org/doxia/index.html"/>
@@ -14,6 +16,6 @@
1416
<skin>
1517
<groupId>org.apache.maven.skins</groupId>
1618
<artifactId>maven-fluido-skin</artifactId>
17-
<version>1.12.0</version>
19+
<version>2.0.0-M9</version>
1820
</skin>
19-
</project>
21+
</site>

asciidoctor-converter-doxia-module/src/main/java/org/asciidoctor/maven/site/AsciidoctorConverterDoxiaParser.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.io.File;
66
import java.io.IOException;
77
import java.io.Reader;
8-
import java.util.logging.Logger;
98

109
import org.apache.maven.doxia.parser.AbstractTextParser;
1110
import org.apache.maven.doxia.parser.ParseException;
@@ -26,6 +25,8 @@
2625
import org.codehaus.plexus.component.annotations.Component;
2726
import org.codehaus.plexus.util.IOUtil;
2827
import org.codehaus.plexus.util.xml.Xpp3Dom;
28+
import org.slf4j.Logger;
29+
import org.slf4j.LoggerFactory;
2930

3031
/**
3132
* This class is used by <a href="https://maven.apache.org/doxia/overview.html">the Doxia framework</a>
@@ -39,6 +40,8 @@
3940
@Component(role = Parser.class, hint = AsciidoctorConverterDoxiaParser.ROLE_HINT)
4041
public class AsciidoctorConverterDoxiaParser extends AbstractTextParser {
4142

43+
private final Logger logger = LoggerFactory.getLogger(AsciidoctorConverterDoxiaParser.class);
44+
4245
@Inject
4346
protected Provider<MavenProject> mavenProjectProvider;
4447

@@ -58,7 +61,7 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept
5861
source = "";
5962
}
6063
} catch (IOException ex) {
61-
getLog().error("Could not read AsciiDoc source: " + ex.getLocalizedMessage());
64+
logger.error("Could not read AsciiDoc source: {}", ex.getLocalizedMessage());
6265
return;
6366
}
6467

@@ -86,7 +89,7 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept
8689

8790
try {
8891
// process log messages according to mojo configuration
89-
new LogRecordsProcessors(logHandler, siteDirectory, errorMessage -> getLog().error(errorMessage))
92+
new LogRecordsProcessors(logHandler, siteDirectory, errorMessage -> logger.error(errorMessage))
9093
.processLogRecords(memoryLogHandler);
9194
} catch (Exception exception) {
9295
throw new ParseException(exception.getMessage(), exception);
@@ -102,10 +105,10 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept
102105
private MemoryLogHandler asciidoctorLoggingSetup(Asciidoctor asciidoctor, LogHandler logHandler, File siteDirectory) {
103106

104107
final MemoryLogHandler memoryLogHandler = new MemoryLogHandler(logHandler.getOutputToConsole(),
105-
logRecord -> getLog().info(LogRecordFormatter.format(logRecord, siteDirectory)));
108+
logRecord -> logger.info(LogRecordFormatter.format(logRecord, siteDirectory)));
106109
asciidoctor.registerLogHandler(memoryLogHandler);
107110
// disable default console output of AsciidoctorJ
108-
Logger.getLogger("asciidoctor").setUseParentHandlers(false);
111+
java.util.logging.Logger.getLogger("asciidoctor").setUseParentHandlers(false);
109112
return memoryLogHandler;
110113
}
111114

@@ -147,7 +150,7 @@ private void requireLibrary(Asciidoctor asciidoctor, String require) {
147150
try {
148151
asciidoctor.requireLibrary(require);
149152
} catch (Exception ex) {
150-
getLog().error(ex.getLocalizedMessage());
153+
logger.error(ex.getLocalizedMessage());
151154
}
152155
}
153156
}

asciidoctor-parser-doxia-module/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<dependency>
4747
<groupId>org.apache.maven.doxia</groupId>
4848
<artifactId>doxia-site-renderer</artifactId>
49-
<version>1.11.1</version>
49+
<version>${doxia.sitetools.version}</version>
5050
<scope>test</scope>
5151
</dependency>
5252
</dependencies>

asciidoctor-parser-doxia-module/src/it/maven-site-plugin/pom.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@
2323
<plugin>
2424
<groupId>org.apache.maven.plugins</groupId>
2525
<artifactId>maven-site-plugin</artifactId>
26-
<version>3.12.1</version>
26+
<version>3.20.0</version>
2727
<configuration>
2828
<asciidoc>
2929
<baseDir>${project.basedir}/src/site/asciidoc</baseDir>
3030
<attributes>
3131
<toclevels>2</toclevels>
3232
</attributes>
3333
</asciidoc>
34+
<relativizeSiteLinks>false</relativizeSiteLinks>
3435
<moduleExcludes>
3536
<asciidoc>**/_*.adoc,**/_*/</asciidoc>
3637
</moduleExcludes>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<project name="Maven Site Plugin IT">
1+
<site xmlns="http://maven.apache.org/SITE/2.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/SITE/2.0.0 https://maven.apache.org/xsd/site-2.0.0.xsd">
24
<body>
35
<breadcrumbs>
46
<item name="Doxia" href="https://maven.apache.org/doxia/index.html"/>
@@ -7,11 +9,11 @@
79
<menu name="AsciiDoc Pages">
810
<item name="Sample" href="sample.html"/>
911
</menu>
10-
${reports}
12+
<menu ref="reports"/>
1113
</body>
1214
<skin>
1315
<groupId>org.apache.maven.skins</groupId>
1416
<artifactId>maven-fluido-skin</artifactId>
15-
<version>1.12.0</version>
17+
<version>2.0.0-M9</version>
1618
</skin>
17-
</project>
19+
</site>

asciidoctor-parser-doxia-module/src/it/maven-site-plugin/validate.groovy

+6-6
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class HtmlAsserter {
136136
}
137137

138138
void containsBreadcrumbs(String value) {
139-
def found = find("<li class=\"active \">${value}</li>")
139+
def found = find("<li class=\"active\">${value}</li>")
140140
assertFound("Breadcrumb", value, found)
141141
}
142142

@@ -153,13 +153,13 @@ class HtmlAsserter {
153153
void containsSectionTitle(String value, int level) {
154154
def found = -1
155155

156-
def id = value.replaceAll(" ", "_")
156+
def id = value.toLowerCase().replaceAll(" ", "_")
157157
if (level == 2) {
158-
found = find("<h2><a name=\"$id\"></a>$value</h2>")
158+
found = find("<h2><a id=\"$id\"></a>$value</h2>")
159159
} else if (level == 3) {
160-
found = find("<h3><a name=\"$id\"></a>$value</h3>")
160+
found = find("<h3><a id=\"$id\"></a>$value</h3>")
161161
} else if (level == 4) {
162-
found = find("<h4><a name=\"$id\"></a>$value</h4>")
162+
found = find("<h4><a id=\"$id\"></a>$value</h4>")
163163
}
164164
assertFound("Section Title (level:$level)", value, found)
165165
}
@@ -185,7 +185,7 @@ class HtmlAsserter {
185185
}
186186

187187
void containsOrderedList(String... values) {
188-
def found = find("<ol style=\"list-style-type: decimal\"><li>${values.join('</li><li>')}</li></ol>")
188+
def found = find("<ol style=\"list-style-type: decimal;\"><li>${values.join('</li><li>')}</li></ol>")
189189
assertFound("Ordered list", values.join(','), found)
190190
}
191191

asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/AsciidoctorAstDoxiaParser.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@
2323
import org.asciidoctor.maven.log.LogRecordFormatter;
2424
import org.asciidoctor.maven.log.LogRecordsProcessors;
2525
import org.asciidoctor.maven.log.MemoryLogHandler;
26-
import org.asciidoctor.maven.site.HeaderMetadata;
2726
import org.asciidoctor.maven.site.HeadParser;
27+
import org.asciidoctor.maven.site.HeaderMetadata;
2828
import org.asciidoctor.maven.site.SiteConversionConfiguration;
2929
import org.asciidoctor.maven.site.SiteConversionConfigurationParser;
3030
import org.asciidoctor.maven.site.SiteLogHandlerDeserializer;
3131
import org.codehaus.plexus.component.annotations.Component;
3232
import org.codehaus.plexus.util.IOUtil;
3333
import org.codehaus.plexus.util.xml.Xpp3Dom;
34+
import org.slf4j.LoggerFactory;
3435

3536
import static org.asciidoctor.maven.commons.StringUtils.isNotBlank;
3637

@@ -45,6 +46,8 @@
4546
@Component(role = Parser.class, hint = AsciidoctorAstDoxiaParser.ROLE_HINT)
4647
public class AsciidoctorAstDoxiaParser extends AbstractTextParser {
4748

49+
private final org.slf4j.Logger logger = LoggerFactory.getLogger(AsciidoctorAstDoxiaParser.class);
50+
4851
@Inject
4952
protected Provider<MavenProject> mavenProjectProvider;
5053

@@ -64,7 +67,7 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept
6467
source = "";
6568
}
6669
} catch (IOException ex) {
67-
getLog().error("Could not read AsciiDoc source: " + ex.getLocalizedMessage());
70+
logger.error("Could not read AsciiDoc source: {}", ex.getLocalizedMessage());
6871
return;
6972
}
7073

@@ -88,13 +91,13 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept
8891
final MemoryLogHandler memoryLogHandler = asciidoctorLoggingSetup(asciidoctor, logHandler, siteDirectory);
8992

9093
if (isNotBlank(reference))
91-
getLog().debug("Document loaded: " + reference);
94+
logger.debug("Document loaded: {}", reference);
9295

9396
Document document = asciidoctor.load(source, conversionConfig.getOptions());
9497

9598
try {
9699
// process log messages according to mojo configuration
97-
new LogRecordsProcessors(logHandler, siteDirectory, errorMessage -> getLog().error(errorMessage))
100+
new LogRecordsProcessors(logHandler, siteDirectory, errorMessage -> logger.error(errorMessage))
98101
.processLogRecords(memoryLogHandler);
99102

100103
} catch (Exception exception) {
@@ -116,7 +119,7 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept
116119
private MemoryLogHandler asciidoctorLoggingSetup(Asciidoctor asciidoctor, LogHandler logHandler, File siteDirectory) {
117120

118121
final MemoryLogHandler memoryLogHandler = new MemoryLogHandler(logHandler.getOutputToConsole(),
119-
logRecord -> getLog().info(LogRecordFormatter.format(logRecord, siteDirectory)));
122+
logRecord -> logger.info(LogRecordFormatter.format(logRecord, siteDirectory)));
120123
asciidoctor.registerLogHandler(memoryLogHandler);
121124
// disable default console output of AsciidoctorJ
122125
Logger.getLogger("asciidoctor").setUseParentHandlers(false);
@@ -161,7 +164,7 @@ private void requireLibrary(Asciidoctor asciidoctor, String require) {
161164
try {
162165
asciidoctor.requireLibrary(require);
163166
} catch (Exception ex) {
164-
getLog().error(ex.getLocalizedMessage());
167+
logger.error(ex.getLocalizedMessage());
165168
}
166169
}
167170
}

asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/ImageNodeProcessor.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ public void process(StructuralNode node) {
4040
final String imagesdir = (String) node.getAttribute("imagesdir");
4141
String imagePath = isBlank(imagesdir) ? target : formatPath(imagesdir, target);
4242
final SinkEventAttributeSet attributes = new SinkEventAttributeSet();
43-
attributes.addAttribute(Attribute.ALT, alt);
43+
if (!isBlank(alt))
44+
attributes.addAttribute(Attribute.ALT, alt);
45+
4446
getSink().figureGraphics(imagePath, attributes);
4547
}
4648

asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/SectionNodeProcessor.java

+27-36
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import org.asciidoctor.ast.StructuralNode;
66
import org.asciidoctor.jruby.ast.impl.SectionImpl;
77
import org.asciidoctor.maven.site.parser.NodeProcessor;
8+
import org.slf4j.Logger;
9+
import org.slf4j.LoggerFactory;
810

911
/**
1012
* Section title processor.
@@ -15,6 +17,8 @@
1517
*/
1618
public class SectionNodeProcessor extends AbstractSinkNodeProcessor implements NodeProcessor {
1719

20+
private final Logger logger = LoggerFactory.getLogger(SectionNodeProcessor.class);
21+
1822
/**
1923
* Constructor.
2024
*
@@ -36,45 +40,32 @@ public void process(StructuralNode node) {
3640

3741
private void sectionTitle(Sink sink, int level, String title, Section node) {
3842
final String formattedTitle = formatTitle(title, node);
39-
switch (level) {
40-
case 0:
41-
// Kept for completeness, real document title is treated in
42-
// DocumentNodeProcessor
43-
sink.rawText("<h1>" + formattedTitle + "</h1>");
44-
break;
45-
case 1:
46-
sink.sectionTitle1();
47-
sink.text(formattedTitle);
48-
sink.sectionTitle1_();
49-
break;
50-
case 2:
51-
sink.sectionTitle2();
52-
sink.text(formattedTitle);
53-
sink.sectionTitle2_();
54-
break;
55-
case 3:
56-
sink.sectionTitle3();
57-
sink.text(formattedTitle);
58-
sink.sectionTitle3_();
59-
break;
60-
case 4:
61-
sink.sectionTitle4();
62-
sink.text(formattedTitle);
63-
sink.sectionTitle4_();
64-
break;
65-
case 5:
66-
sink.sectionTitle5();
67-
sink.text(formattedTitle);
68-
sink.sectionTitle5_();
69-
break;
70-
case 6:
71-
sink.sectionTitle6();
72-
sink.text(formattedTitle);
73-
sink.sectionTitle6_();
74-
break;
43+
if (level == 0) {
44+
// Kept for completeness, real document title is treated in
45+
// DocumentNodeProcessor
46+
sink.sectionTitle1();
47+
sink.text(formattedTitle);
48+
sink.sectionTitle1_();
49+
} else {
50+
// Asciidoctor supports up o 6 levels, but Xhtml5BaseSink only up to 5
51+
int siteLevel = level + 1;
52+
if (level >= 5) {
53+
// TODO generate code manually or request change
54+
logger.warn("Site module does not support level 6 sections. Re-writing as 5");
55+
siteLevel = 5;
56+
}
57+
sink.sectionTitle(siteLevel, null);
58+
anchor(sink, node);
59+
sink.text(formattedTitle);
60+
sink.sectionTitle_(siteLevel);
7561
}
7662
}
7763

64+
private void anchor(Sink sink, Section node) {
65+
sink.anchor(node.getId());
66+
sink.anchor_();
67+
}
68+
7869
private String formatTitle(String title, Section node) {
7970
final Boolean numbered = node.isNumbered();
8071
final Long sectnumlevels = getSectnumlevels(node);

0 commit comments

Comments
 (0)