Skip to content

Commit

Permalink
Make plugin compatible with maven-site-plugin 4.0.0-M1 (asciidoctor#585)
Browse files Browse the repository at this point in the history
* Bump Doxia to 2.0.0-M1
* Leave note in docs for release
* Use SLF4J in site module (apache/maven-doxia#5)
* Reorder constructor args in AsciidoctorDoxiaParserModule
* Update IT test site.xml

Fixes asciidoctor#578

Bump doxia-core to v2.0.0-M3 (asciidoctor#590)

* Bump maven-site-plugin in IT to v4.0.0-M3
* Add skin to IT (mandatory since v4.0.0-M2)

Bump maven-site and doxia to latests

* maven-site-plugin v4.0.0-M8
* doxia & fluido skin 2.0.0-M6
* Sections and tables updated

Bump maven-site to M13, Doxia to M8
  • Loading branch information
abelsromero committed Jan 13, 2024
1 parent b8a34e1 commit 3b0a85d
Showing 15 changed files with 147 additions and 103 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ Bug Fixes::

Improvements::

* Make the site module compatible with maven-site-plugin v4.x.x (#585, #590)
* Split plugin and site integration in sub-modules: asciidoctor-maven-plugin and asciidoctor-doxia-module (#595)
* Add 'asciidoc' as valid file extension in AsciidoctorDoxiaParserModule (#595)
* Fix throwing an exception when registering a non Extension (#596)
16 changes: 15 additions & 1 deletion asciidoctor-converter-doxia-module/pom.xml
Original file line number Diff line number Diff line change
@@ -18,7 +18,8 @@
<url>https://github.com/asciidoctor/asciidoctor-maven-plugin</url>

<properties>
<doxia.version>1.11.1</doxia.version>
<doxia.version>2.0.0-M8</doxia.version>
<maven.coveralls.plugin.version>4.3.0</maven.coveralls.plugin.version>
<plexus.component.metadata.version>2.1.1</plexus.component.metadata.version>
</properties>

@@ -74,6 +75,19 @@
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>${maven.coveralls.plugin.version}</version>
<dependencies>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.3</version>
</dependency>
</dependencies>
</plugin>
</plugins>

Original file line number Diff line number Diff line change
@@ -22,14 +22,13 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.1.2</version>
<version>3.5.0</version>
</plugin>
<!-- tag::plugin-decl[] -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<!-- v2.2.2 of the plugin require Maven Site Plugin 3.1x.0 alongside Doxia 1.11.1 -->
<version>3.12.1</version>
<version>4.0.0-M13</version>
<configuration>
<asciidoc>
<baseDir>${project.basedir}/src/site/asciidoc</baseDir>
Original file line number Diff line number Diff line change
@@ -10,6 +10,6 @@
<skin>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-fluido-skin</artifactId>
<version>1.11.1</version>
<version>2.0.0-M6</version>
</skin>
</project>
Original file line number Diff line number Diff line change
@@ -13,13 +13,14 @@
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import javax.inject.Provider;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.util.logging.Logger;

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

private final Logger logger = LoggerFactory.getLogger(AsciidoctorConverterDoxiaParser.class);

@Inject
protected Provider<MavenProject> mavenProjectProvider;

@@ -52,7 +55,7 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept
source = "";
}
} catch (IOException ex) {
getLog().error("Could not read AsciiDoc source: " + ex.getLocalizedMessage());
logger.error("Could not read AsciiDoc source: " + ex.getLocalizedMessage());
return;
}

@@ -79,7 +82,7 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept
String asciidocHtml = convertAsciiDoc(asciidoctor, source, conversionConfig.getOptions());
try {
// process log messages according to mojo configuration
new LogRecordsProcessors(logHandler, siteDirectory, errorMessage -> getLog().error(errorMessage))
new LogRecordsProcessors(logHandler, siteDirectory, errorMessage -> logger.error(errorMessage))
.processLogRecords(memoryLogHandler);
} catch (Exception exception) {
throw new ParseException(exception.getMessage(), exception);
@@ -90,11 +93,10 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept

private MemoryLogHandler asciidoctorLoggingSetup(Asciidoctor asciidoctor, LogHandler logHandler, File siteDirectory) {

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

@@ -136,7 +138,7 @@ private void requireLibrary(Asciidoctor asciidoctor, String require) {
try {
asciidoctor.requireLibrary(require);
} catch (Exception ex) {
getLog().error(ex.getLocalizedMessage());
logger.error(ex.getLocalizedMessage());
}
}
}
16 changes: 15 additions & 1 deletion asciidoctor-parser-doxia-module/pom.xml
Original file line number Diff line number Diff line change
@@ -17,7 +17,8 @@
<description>Asciidoctor Doxia Module based on Asciidoctor AST processing (for Maven Site integration)</description>

<properties>
<doxia.version>1.11.1</doxia.version>
<doxia.version>2.0.0-M6</doxia.version>
<maven.coveralls.plugin.version>4.3.0</maven.coveralls.plugin.version>
<plexus.component.metadata.version>2.1.1</plexus.component.metadata.version>
</properties>

@@ -78,6 +79,19 @@
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>${maven.coveralls.plugin.version}</version>
<dependencies>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.3</version>
</dependency>
</dependencies>
</plugin>
</plugins>

Original file line number Diff line number Diff line change
@@ -17,13 +17,13 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.1.2</version>
<version>3.5.0</version>
</plugin>
<!-- tag::plugin-decl[] -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.12.1</version>
<version>4.0.0-M8</version>
<configuration>
<asciidoc>
<baseDir>${project.basedir}/src/site/asciidoc</baseDir>
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<project name="Maven Site Plugin IT">
<body>
<menu ref="reports"/>
<menu name="AsciiDoc Pages">
<item name="Sample" href="sample.html"/>
</menu>
${reports}
</body>
<!-- Skins are mandatory since maven-site-plugin v4.0.0-M2 -->
<skin>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-fluido-skin</artifactId>
<version>2.0.0-M6</version>
</skin>
</project>
Original file line number Diff line number Diff line change
@@ -95,13 +95,13 @@ class HtmlAsserter {
void containsSectionTitle(String value, int level) {
def found = -1

def id = value.replaceAll(" ", "_")
def id = value.toLowerCase().replaceAll(" ", "_")
if (level == 2) {
found = find("<h2><a name=\"$id\"></a>$value</h2>")
found = find("<h2><a id=\"$id\"></a>$value</h2>")
} else if (level == 3) {
found = find("<h3><a name=\"$id\"></a>$value</h3>")
found = find("<h3><a id=\"$id\"></a>$value</h3>")
} else if (level == 4) {
found = find("<h4><a name=\"$id\"></a>$value</h4>")
found = find("<h4><a id=\"$id\"></a>$value</h4>")
}
assertFound("Section Title (level:$level)", value, found)
}
Original file line number Diff line number Diff line change
@@ -17,13 +17,14 @@
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import javax.inject.Provider;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.util.logging.Logger;

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

@@ -37,6 +38,8 @@
@Component(role = Parser.class, hint = AsciidoctorAstDoxiaParser.ROLE_HINT)
public class AsciidoctorAstDoxiaParser extends AbstractTextParser {

private final Logger logger = LoggerFactory.getLogger(AsciidoctorAstDoxiaParser.class);

@Inject
protected Provider<MavenProject> mavenProjectProvider;

@@ -56,7 +59,7 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept
source = "";
}
} catch (IOException ex) {
getLog().error("Could not read AsciiDoc source: " + ex.getLocalizedMessage());
logger.error("Could not read AsciiDoc source: " + ex.getLocalizedMessage());
return;
}

@@ -81,13 +84,13 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept

sink.body();
if (isNotBlank(reference))
getLog().debug("Document loaded: " + reference);
logger.debug("Document loaded: " + reference);

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

try {
// process log messages according to mojo configuration
new LogRecordsProcessors(logHandler, siteDirectory, errorMessage -> getLog().error(errorMessage))
new LogRecordsProcessors(logHandler, siteDirectory, errorMessage -> logger.error(errorMessage))
.processLogRecords(memoryLogHandler);

} catch (Exception exception) {
@@ -101,11 +104,10 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept

private MemoryLogHandler asciidoctorLoggingSetup(Asciidoctor asciidoctor, LogHandler logHandler, File siteDirectory) {

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

@@ -147,7 +149,7 @@ private void requireLibrary(Asciidoctor asciidoctor, String require) {
try {
asciidoctor.requireLibrary(require);
} catch (Exception ex) {
getLog().error(ex.getLocalizedMessage());
logger.error(ex.getLocalizedMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -5,9 +5,13 @@
import org.asciidoctor.ast.StructuralNode;
import org.asciidoctor.jruby.ast.impl.SectionImpl;
import org.asciidoctor.maven.site.ast.NodeProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SectionNodeProcessor extends AbstractSinkNodeProcessor implements NodeProcessor {

private final Logger logger = LoggerFactory.getLogger(SectionNodeProcessor.class);

public SectionNodeProcessor(Sink sink) {
super(sink);
}
@@ -24,45 +28,33 @@ public void process(StructuralNode node) {

private void sectionTitle(Sink sink, int level, String title, Section node) {
final String formattedTitle = formatTitle(title, node);
switch (level) {
case 0:
// Kept for completeness, real document title is treated in
// DocumentNodeProcessor
sink.rawText("<h1>" + formattedTitle + "</h1>");
break;
case 1:
sink.sectionTitle1();
sink.text(formattedTitle);
sink.sectionTitle1_();
break;
case 2:
sink.sectionTitle2();
sink.text(formattedTitle);
sink.sectionTitle2_();
break;
case 3:
sink.sectionTitle3();
sink.text(formattedTitle);
sink.sectionTitle3_();
break;
case 4:
sink.sectionTitle4();
sink.text(formattedTitle);
sink.sectionTitle4_();
break;
case 5:
sink.sectionTitle5();
sink.text(formattedTitle);
sink.sectionTitle5_();
break;
case 6:
sink.sectionTitle6();
sink.text(formattedTitle);
sink.sectionTitle6_();
break;

if (level == 0) {
// Kept for completeness, real document title is treated in
// DocumentNodeProcessor
sink.sectionTitle1();
sink.text(formattedTitle);
sink.sectionTitle1_();
} else {
// Asciidoctor supports up o 6 levels, but Xhtml5BaseSink only up to 5
int siteLevel = level + 1;
if (level >= 5) {
// TODO generate code manually or request change
logger.warn("Site module does not support level 6 sections. Re-writing as 5");
siteLevel = 5;
}
sink.sectionTitle(siteLevel, null);
anchor(sink, node);
sink.text(formattedTitle);
sink.sectionTitle_(siteLevel);
}
}

private static void anchor(Sink sink, Section node) {
sink.anchor(node.getId());
sink.anchor_();
}

private String formatTitle(String title, Section node) {
final Boolean numbered = node.isNumbered();
final Long sectnumlevels = getSectnumlevels(node);
Original file line number Diff line number Diff line change
@@ -45,16 +45,17 @@ void should_convert_html_without_any_configuration() throws FileNotFoundExceptio

assertThat(result)
.isEqualTo("<h1>Document Title</h1><p>Preamble paragraph.</p>" +
"<h2><a name=\"Section_A\"></a>Section A</h2>" +
"<h2><a id=\"id_section_a\"></a>Section A</h2>" +
"<p><strong>Section A</strong> paragraph.</p>" +
"<h3><a name=\"Section_A_Subsection\"></a>Section A Subsection</h3>" +
"<h3><a id=\"id_section_a_subsection\"></a>Section A Subsection</h3>" +
"<p><strong>Section A</strong> <em>subsection</em> paragraph.</p>" +
"<h2><a name=\"Section_B\"></a>Section B</h2>" +
"<h2><a id=\"id_section_b\"></a>Section B</h2>" +
"<p><strong>Section B</strong> paragraph.</p>" +
"<ul>" +
"<li>Item 1</li>" +
"<li>Item 2</li>" +
"<li>Item 3</li></ul><div class=\"source\"><pre class=\"prettyprint\"><code>require 'asciidoctor'</code></pre></div>");
"<li>Item 3</li></ul>" +
"<div class=\"source\"><pre class=\"prettyprint\"><code>require 'asciidoctor'</code></pre></div>");
}

@Test
Loading

0 comments on commit 3b0a85d

Please sign in to comment.