Skip to content

Commit

Permalink
Bump maven-site-plugin and doxia
Browse files Browse the repository at this point in the history
* Use SLF4J in site module (apache/maven-doxia#5)
* Unify Doxia versions in parent pom
* Use same Doxia version for doxia-core and doxia-site-renderer
* Use javax.inject.Named instead of custom Plexus
* Add skin to IT (mandatory since v4.0.0-M2)
* Bump maven-site-plugin, doxia, Fluido skins
  • Loading branch information
abelsromero committed Feb 13, 2024
1 parent d9d6f81 commit 332dd6f
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
<skin>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-fluido-skin</artifactId>
<version>2.0.0-M6</version>
<version>2.0.0-M8</version>
</skin>
</project>
5 changes: 0 additions & 5 deletions asciidoctor-parser-doxia-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@
<artifactId>doxia-core</artifactId>
<version>${doxia.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-module-markdown</artifactId>
<version>${doxia.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-site-renderer</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
@@ -1,5 +1,11 @@
package org.asciidoctor.maven.site.parser;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.StringReader;
import java.io.StringWriter;

import lombok.SneakyThrows;
import org.apache.maven.doxia.parser.AbstractTextParser;
import org.apache.maven.doxia.parser.ParseException;
Expand All @@ -10,8 +16,6 @@
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.io.*;

import static org.asciidoctor.maven.site.parser.AsciidoctorAstDoxiaParserTest.TestMocks.mockAsciidoctorDoxiaParser;
import static org.asciidoctor.maven.site.parser.processors.test.ReflectionUtils.extractField;
import static org.asciidoctor.maven.site.parser.processors.test.StringTestUtils.clean;
Expand Down Expand Up @@ -44,143 +48,143 @@ void should_convert_html_without_any_configuration() throws FileNotFoundExceptio
String result = parse(parser, srcAsciidoc);

assertThat(result)
.isEqualTo("<h1>Document Title</h1>" +
"<p>Preamble paragraph.</p>" +
"<h2><a name=\"Section_A\"></a>Section A</h2>" +
"<p><strong>Section A</strong> paragraph.</p>" +
"<h3><a name=\"Section_A_Subsection\"></a>Section A Subsection</h3>" +
"<p><strong>Section A</strong> 'subsection' paragraph.</p>" +
"<h2><a name=\"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>");
.isEqualTo("<h1>Document Title</h1><p>Preamble paragraph.</p>" +
"<h2><a id=\"id_section_a\"></a>Section A</h2>" +
"<p><strong>Section A</strong> paragraph.</p>" +
"<h3><a id=\"id_section_a_subsection\"></a>Section A Subsection</h3>" +
"<p><strong>Section A</strong> 'subsection' paragraph.</p>" +
"<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>");
}

@Test
void should_convert_html_with_an_attribute() throws ParseException {
final String source = "= Document Title\n\n" +
"== Section A\n\n" +
"My attribute value is {custom-attribute}.\n";
"== Section A\n\n" +
"My attribute value is {custom-attribute}.\n";

AsciidoctorAstDoxiaParser parser = mockAsciidoctorDoxiaParser(
"<configuration>\n" +
" <asciidoc>\n" +
" <attributes>\n" +
" <custom-attribute>a_value</custom-attribute>\n" +
" </attributes>\n" +
" </asciidoc>\n" +
"</configuration>");
"<configuration>\n" +
" <asciidoc>\n" +
" <attributes>\n" +
" <custom-attribute>a_value</custom-attribute>\n" +
" </attributes>\n" +
" </asciidoc>\n" +
"</configuration>");

String result = parse(parser, source);

assertThat(result)
.contains("<p>My attribute value is a_value.</p>");
.contains("<p>My attribute value is a_value.</p>");
}

@Test
void should_process_empty_selfclosing_XML_attributes() throws ParseException {
final String source = sectionsSample();

AsciidoctorAstDoxiaParser parser = mockAsciidoctorDoxiaParser(
"<configuration>\n" +
" <asciidoc>\n" +
" <attributes>\n" +
" <sectnums/>\n" +
" </attributes>\n" +
" </asciidoc>\n" +
"</configuration>");
"<configuration>\n" +
" <asciidoc>\n" +
" <attributes>\n" +
" <sectnums/>\n" +
" </attributes>\n" +
" </asciidoc>\n" +
"</configuration>");

String result = parse(parser, source);

assertThat(result)
.contains("</a>1. Section A</h2>")
.contains("</a>1.1. Section A Subsection</h3>")
.contains("</a>2. Section B</h2>")
.contains("</a>2.1. Section B Subsection</h3>");
.contains("</a>1. Section A</h2>")
.contains("</a>1.1. Section A Subsection</h3>")
.contains("</a>2. Section B</h2>")
.contains("</a>2.1. Section B Subsection</h3>");
}

@Test
void should_process_config_with_sectnumlevels() throws ParseException {
final String source = sectionsSample();

AsciidoctorAstDoxiaParser parser = mockAsciidoctorDoxiaParser(
"<configuration>\n" +
" <asciidoc>\n" +
" <attributes>\n" +
" <sectnums/>\n" +
" <sectnumlevels>1</sectnumlevels>\n" +
" </attributes>\n" +
" </asciidoc>\n" +
"</configuration>");
"<configuration>\n" +
" <asciidoc>\n" +
" <attributes>\n" +
" <sectnums/>\n" +
" <sectnumlevels>1</sectnumlevels>\n" +
" </attributes>\n" +
" </asciidoc>\n" +
"</configuration>");

String result = parse(parser, source);

assertThat(result)
.contains("</a>1. Section A</h2>")
.contains("</a>Section A Subsection</h3>")
.contains("</a>2. Section B</h2>")
.contains("</a>Section B Subsection</h3>");
.contains("</a>1. Section A</h2>")
.contains("</a>Section A Subsection</h3>")
.contains("</a>2. Section B</h2>")
.contains("</a>Section B Subsection</h3>");
}

@Test
void should_process_empty_value_XML_attributes() throws ParseException {
final String source = sectionsSample();

AsciidoctorAstDoxiaParser parser = mockAsciidoctorDoxiaParser(
"<configuration>\n" +
" <asciidoc>\n" +
" <attributes>\n" +
" <sectnums></sectnums>\n" +
" </attributes>\n" +
" </asciidoc>\n" +
"</configuration>");
"<configuration>\n" +
" <asciidoc>\n" +
" <attributes>\n" +
" <sectnums></sectnums>\n" +
" </attributes>\n" +
" </asciidoc>\n" +
"</configuration>");

String result = parse(parser, source);

assertThat(result)
.contains("</a>1. Section A</h2>")
.contains("</a>1.1. Section A Subsection</h3>")
.contains("</a>2. Section B</h2>")
.contains("</a>2.1. Section B Subsection</h3>");
.contains("</a>1. Section A</h2>")
.contains("</a>1.1. Section A Subsection</h3>")
.contains("</a>2. Section B</h2>")
.contains("</a>2.1. Section B Subsection</h3>");
}

private static String sectionsSample() {
return "= Document Title\n\n" +
"== Section A\n\n" +
"Section A paragraph.\n\n" +
"=== Section A Subsection\n\n" +
"Section A 'subsection' paragraph.\n\n" +
"== Section B\n\n" +
"*Section B* paragraph.\n\n" +
"=== Section B Subsection\n\n" +
"Section B 'subsection' paragraph.\n\n";
"== Section A\n\n" +
"Section A paragraph.\n\n" +
"=== Section A Subsection\n\n" +
"Section A 'subsection' paragraph.\n\n" +
"== Section B\n\n" +
"*Section B* paragraph.\n\n" +
"=== Section B Subsection\n\n" +
"Section B 'subsection' paragraph.\n\n";
}

@Test
void should_fail_when_logHandler_failIf_is_WARNING() {
final String source = "= My Document\n\n" +
"include::unexistingdoc.adoc[]\n\n" +
"include::unexistingdoc.adoc[]";
"include::unexistingdoc.adoc[]\n\n" +
"include::unexistingdoc.adoc[]";

AsciidoctorAstDoxiaParser parser = mockAsciidoctorDoxiaParser(
"<configuration>\n" +
" <asciidoc>\n" +
" <logHandler>\n" +
" <failIf>\n" +
" <severity>WARN</severity>\n" +
" </failIf>\n" +
" </logHandler>\n" +
" </asciidoc>\n" +
"</configuration>");
"<configuration>\n" +
" <asciidoc>\n" +
" <logHandler>\n" +
" <failIf>\n" +
" <severity>WARN</severity>\n" +
" </failIf>\n" +
" </logHandler>\n" +
" </asciidoc>\n" +
"</configuration>");

Throwable throwable = catchThrowable(() -> parser.parse(new StringReader(source), sink));

// 'issues with WARN and ERROR are returned'
assertThat(throwable)
.isInstanceOf(ParseException.class)
.hasMessageContaining("Found 2 issue(s) of severity WARN or higher during conversion");
.isInstanceOf(ParseException.class)
.hasMessageContaining("Found 2 issue(s) of severity WARN or higher during conversion");
}

private String parse(AbstractTextParser parser, File source) throws FileNotFoundException, ParseException {
Expand All @@ -198,9 +202,9 @@ static class TestMocks {
static javax.inject.Provider<MavenProject> createMavenProjectMock(String configuration) {
MavenProject mockProject = Mockito.mock(MavenProject.class);
when(mockProject.getBasedir())
.thenReturn(new File("."));
.thenReturn(new File("."));
when(mockProject.getGoalConfiguration(anyString(), anyString(), anyString(), anyString()))
.thenReturn(configuration != null ? Xpp3DomBuilder.build(new StringReader(configuration)) : null);
.thenReturn(configuration != null ? Xpp3DomBuilder.build(new StringReader(configuration)) : null);

return () -> mockProject;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.asciidoctor.maven.site.parser.processors;

import java.io.StringWriter;
import java.util.Arrays;
import java.util.Collections;

import org.apache.maven.doxia.sink.Sink;
import org.asciidoctor.Asciidoctor;
import org.asciidoctor.Options;
Expand All @@ -9,10 +13,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.StringWriter;
import java.util.Arrays;
import java.util.Collections;

import static org.asciidoctor.maven.site.parser.processors.test.StringTestUtils.clean;
import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -39,9 +39,9 @@ void should_convert_simple_list() {
String html = process(content);

assertThat(html)
.isEqualTo("<ol style=\"list-style-type: decimal\">" +
"<li>ordered item 1</li>" +
"<li>ordered item 2</li></ol>");
.isEqualTo("<ol style=\"list-style-type: decimal;\">" +
"<li>ordered item 1</li>" +
"<li>ordered item 2</li></ol>");
}

@Test
Expand All @@ -51,40 +51,40 @@ void should_convert_nested_list() {
String html = process(content);

assertThat(html)
.isEqualTo("<ol style=\"list-style-type: decimal\">" +
"<li>ordered item 1" +
"<ol style=\"list-style-type: decimal\">" +
"<li>ordered item 1 1</li></ol></li>" +
"<li>ordered item 1 2</li>" +
"<li>ordered item 2" +
"<ol style=\"list-style-type: decimal\">" +
"<li>ordered item 2 1" +
"<ol style=\"list-style-type: decimal\">" +
"<li>ordered item 2 1 1</li></ol></li></ol></li></ol>");
.isEqualTo("<ol style=\"list-style-type: decimal;\">" +
"<li>ordered item 1" +
"<ol style=\"list-style-type: decimal;\">" +
"<li>ordered item 1 1</li></ol></li>" +
"<li>ordered item 1 2</li>" +
"<li>ordered item 2" +
"<ol style=\"list-style-type: decimal;\">" +
"<li>ordered item 2 1" +
"<ol style=\"list-style-type: decimal;\">" +
"<li>ordered item 2 1 1</li></ol></li></ol></li></ol>");
}

private static String buildDocumentWithSimpleList() {
return "= Document tile\n\n"
+ "== Section\n\n"
+ ". ordered item 1\n"
+ ". ordered item 2\n";
+ "== Section\n\n"
+ ". ordered item 1\n"
+ ". ordered item 2\n";
}

private static String buildDocumentWithNestedLists() {
return "= Document tile\n\n"
+ "== Section\n\n"
+ ". ordered item 1\n"
+ ".. ordered item 1 1\n"
+ ". ordered item 1 2\n"
+ ". ordered item 2\n"
+ ".. ordered item 2 1\n"
+ "... ordered item 2 1 1\n";
+ "== Section\n\n"
+ ". ordered item 1\n"
+ ".. ordered item 1 1\n"
+ ". ordered item 1 2\n"
+ ". ordered item 2\n"
+ ".. ordered item 2 1\n"
+ "... ordered item 2 1 1\n";
}

private String process(String content) {
StructuralNode node = asciidoctor.load(content, Options.builder().build())
.findBy(Collections.singletonMap("context", ":olist"))
.get(0);
.findBy(Collections.singletonMap("context", ":olist"))
.get(0);

nodeProcessor.process(node);

Expand Down
Loading

0 comments on commit 332dd6f

Please sign in to comment.