Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compatibility with maven-site-plugin v3.20.0 #934

2 changes: 2 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/main[co
Bug Fixes::

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

Improvements::

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

Build / Infrastructure::

Expand Down
6 changes: 3 additions & 3 deletions asciidoctor-converter-doxia-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<artifactId>asciidoctor-converter-doxia-module</artifactId>
<packaging>jar</packaging>

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

<dependencies>
Expand Down Expand Up @@ -46,7 +46,7 @@
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-site-renderer</artifactId>
<version>1.11.1</version>
<version>${doxia.sitetools.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
<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>3.20.0</version>
<configuration>
<asciidoc>
<baseDir>${project.basedir}/src/site/asciidoc</baseDir>
Expand All @@ -52,6 +51,7 @@
<toclevels>2</toclevels>
</attributes>
</asciidoc>
<relativizeSiteLinks>false</relativizeSiteLinks>
<moduleExcludes>
<asciidoc>**/_*.adoc,**/_*/</asciidoc>
</moduleExcludes>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<project name="Maven Site Plugin IT">
<site xmlns="http://maven.apache.org/SITE/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SITE/2.0.0 https://maven.apache.org/xsd/site-2.0.0.xsd">
<body>
<breadcrumbs>
<item name="Doxia" href="https://maven.apache.org/doxia/index.html"/>
Expand All @@ -14,6 +16,6 @@
<skin>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-fluido-skin</artifactId>
<version>1.12.0</version>
<version>2.0.0-M9</version>
</skin>
</project>
</site>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.util.logging.Logger;

import org.apache.maven.doxia.parser.AbstractTextParser;
import org.apache.maven.doxia.parser.ParseException;
Expand All @@ -26,6 +25,8 @@
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;

/**
* This class is used by <a href="https://maven.apache.org/doxia/overview.html">the Doxia framework</a>
Expand All @@ -39,6 +40,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;

Expand All @@ -58,7 +61,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;
}

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

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);
Expand All @@ -102,10 +105,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)));
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;
}

Expand Down Expand Up @@ -147,7 +150,7 @@ private void requireLibrary(Asciidoctor asciidoctor, String require) {
try {
asciidoctor.requireLibrary(require);
} catch (Exception ex) {
getLog().error(ex.getLocalizedMessage());
logger.error(ex.getLocalizedMessage());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion asciidoctor-parser-doxia-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-site-renderer</artifactId>
<version>1.11.1</version>
<version>${doxia.sitetools.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.12.1</version>
<version>3.20.0</version>
<configuration>
<asciidoc>
<baseDir>${project.basedir}/src/site/asciidoc</baseDir>
<attributes>
<toclevels>2</toclevels>
</attributes>
</asciidoc>
<relativizeSiteLinks>false</relativizeSiteLinks>
<moduleExcludes>
<asciidoc>**/_*.adoc,**/_*/</asciidoc>
</moduleExcludes>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<project name="Maven Site Plugin IT">
<site xmlns="http://maven.apache.org/SITE/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SITE/2.0.0 https://maven.apache.org/xsd/site-2.0.0.xsd">
<body>
<breadcrumbs>
<item name="Doxia" href="https://maven.apache.org/doxia/index.html"/>
Expand All @@ -7,11 +9,11 @@
<menu name="AsciiDoc Pages">
<item name="Sample" href="sample.html"/>
</menu>
${reports}
<menu ref="reports"/>
</body>
<skin>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-fluido-skin</artifactId>
<version>1.12.0</version>
<version>2.0.0-M9</version>
</skin>
</project>
</site>
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class HtmlAsserter {
}

void containsBreadcrumbs(String value) {
def found = find("<li class=\"active \">${value}</li>")
def found = find("<li class=\"active\">${value}</li>")
assertFound("Breadcrumb", value, found)
}

Expand All @@ -153,13 +153,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)
}
Expand All @@ -185,7 +185,7 @@ class HtmlAsserter {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
import org.asciidoctor.maven.log.LogRecordFormatter;
import org.asciidoctor.maven.log.LogRecordsProcessors;
import org.asciidoctor.maven.log.MemoryLogHandler;
import org.asciidoctor.maven.site.HeaderMetadata;
import org.asciidoctor.maven.site.HeadParser;
import org.asciidoctor.maven.site.HeaderMetadata;
import org.asciidoctor.maven.site.SiteConversionConfiguration;
import org.asciidoctor.maven.site.SiteConversionConfigurationParser;
import org.asciidoctor.maven.site.SiteLogHandlerDeserializer;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.slf4j.LoggerFactory;

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

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

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

@Inject
protected Provider<MavenProject> mavenProjectProvider;

Expand All @@ -64,7 +67,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;
}

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

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) {
Expand All @@ -116,7 +119,7 @@ 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)));
logRecord -> logger.info(LogRecordFormatter.format(logRecord, siteDirectory)));
asciidoctor.registerLogHandler(memoryLogHandler);
// disable default console output of AsciidoctorJ
Logger.getLogger("asciidoctor").setUseParentHandlers(false);
Expand Down Expand Up @@ -161,7 +164,7 @@ private void requireLibrary(Asciidoctor asciidoctor, String require) {
try {
asciidoctor.requireLibrary(require);
} catch (Exception ex) {
getLog().error(ex.getLocalizedMessage());
logger.error(ex.getLocalizedMessage());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public void process(StructuralNode node) {
final String imagesdir = (String) node.getAttribute("imagesdir");
String imagePath = isBlank(imagesdir) ? target : formatPath(imagesdir, target);
final SinkEventAttributeSet attributes = new SinkEventAttributeSet();
attributes.addAttribute(Attribute.ALT, alt);
if (!isBlank(alt))
attributes.addAttribute(Attribute.ALT, alt);

getSink().figureGraphics(imagePath, attributes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.asciidoctor.ast.StructuralNode;
import org.asciidoctor.jruby.ast.impl.SectionImpl;
import org.asciidoctor.maven.site.parser.NodeProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Section title processor.
Expand All @@ -15,6 +17,8 @@
*/
public class SectionNodeProcessor extends AbstractSinkNodeProcessor implements NodeProcessor {

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

/**
* Constructor.
*
Expand All @@ -36,45 +40,32 @@ 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 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);
Expand Down
Loading