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

Split plugin and site modules #595

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
118 changes: 118 additions & 0 deletions asciidoctor-doxia-module/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-tools</artifactId>
<version>3.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-doxia-module</artifactId>
<packaging>jar</packaging>

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

<properties>
<doxia.version>1.11.1</doxia.version>
<maven.coveralls.plugin.version>4.3.0</maven.coveralls.plugin.version>
<plexus.component.metadata.version>1.7</plexus.component.metadata.version>
</properties>

<dependencies>
<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-commons</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj</artifactId>
<version>${asciidoctorj.version}</version>
</dependency>
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby</artifactId>
<version>${jruby.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-core</artifactId>
<version>${doxia.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven.project.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<version>${plexus.component.metadata.version}</version>
<executions>
<execution>
<goals>
<goal>generate-metadata</goal>
</goals>
</execution>
</executions>
</plugin>
<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>

<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<versionRange>[${plexus.component.metadata.version},)</versionRange>
<goals>
<goal>generate-metadata</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute/>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<dependencies>
<dependency><!-- add Asciidoctor Doxia Parser Module to maven-site-plugin -->
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<artifactId>asciidoctor-doxia-module</artifactId>
<version>@project.version@</version>
</dependency>
</dependencies>
Expand Down
96 changes: 96 additions & 0 deletions asciidoctor-doxia-module/src/it/maven-site-plugin/validate.bsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import java.nio.file.Files;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

File outputDir = new File(basedir, "target/site");

final String[] expectedFiles = {
"file-with-toc.html",
"sample.html"
};

final String[] unexpectedFiles = {
"_include.html"
};

final Pattern tocEntry = Pattern.compile("<li><a href=\"#(.*?)\">.*");
final Pattern elementIdPattern = Pattern.compile(".* id=\"(.*?)\".*");

for (String expectedFile : expectedFiles) {
final File file = new File(outputDir, expectedFile);
System.out.println("Checking for presence of " + file);

if (!file.isFile()) {
throw new Exception("Missing file " + file);
}
if (file.length() == 0) {
throw new Exception("Empty file " + file);
}

if (expectedFile.equals("file-with-toc.html")) {
List lines = Files.readAllLines(file.toPath());
System.out.println("Ensuring IDs match TOC links");

List tocEntries = new ArrayList();
for (String line : lines) {
Matcher matcher = tocEntry.matcher(line);
if (matcher.matches()) {
tocEntries.add(matcher.group(1));
}

matcher = elementIdPattern.matcher(line);
if (matcher.matches()) {
String elementId = matcher.group(1);
if (tocEntries.contains(elementId)) {
tocEntries.remove(tocEntries.indexOf(elementId));
}
}
}

if (tocEntries.size() != 0) {
throw new Exception("Couldn't find matching IDs for the following TOC entries: " + tocEntries);
}

boolean includeResolved = false;
boolean sourceHighlighted = false;

for (String line : lines) {
if (!includeResolved && line.contains("Content included from the file ")) {
includeResolved = true;
}
else if (!sourceHighlighted && line.contains("<span style=\"color:#070;font-weight:bold\">&lt;plugin&gt;</span>")) {
sourceHighlighted = true;
}
}

if (!includeResolved) {
throw new Exception("Include file was not resolved.");
}

if (!sourceHighlighted) {
throw new Exception("Source code was not highlighted.");
}

// validate that maven properties are replaced same as attributes
boolean foundReplacement = false;
for (String line : lines) {
if (line.contains("v1.2.3")) {
foundReplacement = true;
break;
}
}
if (!foundReplacement) {
throw new Exception("Maven properties not replaced.");
}
}
}

for (String unexpectedFile : unexpectedFiles) {
File file = new File(outputDir, unexpectedFile);
System.out.println("Checking for absence of " + file);
if (file.isFile()) {
throw new Exception("Unexpected file " + file);
}
}

return true;
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ public class AsciidoctorDoxiaParserModule extends AbstractParserModule {
public static final String SOURCE_DIRECTORY = AsciidoctorDoxiaParser.ROLE_HINT;

/**
* The extension for AsciiDoc files.
* The extensions for AsciiDoc files.
*/
// TODO change type to String[] and value to { "adoc", "asciidoc" } once available in Doxia
public static final String FILE_EXTENSION = "adoc";
public static final String[] FILE_EXTENSIONS = new String[]{"adoc", "asciidoc"};

/**
* Build a new instance of {@link AsciidoctorDoxiaParserModule}.
*/
public AsciidoctorDoxiaParserModule() {
super(SOURCE_DIRECTORY, FILE_EXTENSION, AsciidoctorDoxiaParser.ROLE_HINT);
super(SOURCE_DIRECTORY, AsciidoctorDoxiaParser.ROLE_HINT, FILE_EXTENSIONS);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.asciidoctor.maven.site;

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.project.MavenProject;
import org.asciidoctor.AttributesBuilder;
import org.asciidoctor.OptionsBuilder;
import org.asciidoctor.maven.process.AsciidoctorHelper;
import org.asciidoctor.maven.commons.AsciidoctorHelper;
import org.codehaus.plexus.util.xml.Xpp3Dom;

import java.io.File;
Expand All @@ -14,6 +15,9 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.asciidoctor.maven.commons.StringUtils.isBlank;

public class SiteConversionConfigurationParser {

private final MavenProject project;
Expand All @@ -37,7 +41,7 @@ SiteConversionConfiguration processAsciiDocConfig(Xpp3Dom siteConfig,
return new SiteConversionConfiguration(options.get(), Collections.emptyList());
}

AsciidoctorHelper.addMavenProperties(project, presetAttributes);
AsciidoctorHelper.addProperties(project.getProperties(), presetAttributes);

final List<String> gemsToRequire = new ArrayList<>();
for (Xpp3Dom asciidocOpt : asciidocConfig.getChildren()) {
Expand All @@ -50,15 +54,15 @@ SiteConversionConfiguration processAsciiDocConfig(Xpp3Dom siteConfig,
if (requireNode.getValue().contains(",")) {
// <requires>time, base64</requires>
Stream.of(requireNode.getValue().split(","))
.filter(StringUtils::isNotBlank)
.map(String::trim)
.filter(this::isNotBlank)
.forEach(value -> gemsToRequire.add(value));
} else {
// <requires>
// <require>time</require>
// </requires>
String value = requireNode.getValue();
if (value.trim().length() > 0)
if (!isBlank(value))
gemsToRequire.add(value.trim());
}
}
Expand All @@ -83,12 +87,6 @@ SiteConversionConfiguration processAsciiDocConfig(Xpp3Dom siteConfig,
return new SiteConversionConfiguration(presetOptions.attributes(presetAttributes).get(), gemsToRequire);
}

public boolean isNotBlank(String value) {
return value != null
&& !value.isEmpty()
&& value.chars().anyMatch(c -> !Character.isWhitespace(c));
}

private File resolveProjectDir(MavenProject project, String path) {
File filePath = new File(path);
if (!filePath.isAbsolute()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

public class AsciidoctorDoxiaParserTest {

private static final String TEST_DOCS_PATH = "src/test/resources/src/asciidoctor";
private static final String TEST_DOCS_PATH = "src/test/resources/";

@Test
public void should_convert_html_without_any_configuration() throws FileNotFoundException, ParseException {
Expand Down Expand Up @@ -213,7 +213,7 @@ public void should_process_empty_value_XML_attributes() throws FileNotFoundExcep
}

@Test
public void should_fail_when_logHandler_failIf_is_WARNING() throws FileNotFoundException, ParseException {
public void should_fail_when_logHandler_failIf_is_WARNING() {
// given
final File srcAsciidoc = new File(TEST_DOCS_PATH, "errors/document-with-missing-include.adoc");
final Sink sink = createSinkMock();
Expand All @@ -233,7 +233,6 @@ public void should_fail_when_logHandler_failIf_is_WARNING() throws FileNotFoundE
// when
Throwable throwable = catchThrowable(() -> parser.parse(new FileReader(srcAsciidoc), sink));


// then: 'issues with WARN and ERROR are returned'
assertThat(throwable)
.isInstanceOf(org.apache.maven.doxia.parser.ParseException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ private MavenProject fakeProject(Map<String, String> properties) {
return project;
}


private Map<String, Object> map(Map.Entry<String, Object>... entries) {
final Map<String, Object> map = new HashMap<>();
for (Map.Entry<String, Object> entry : entries) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
println "HelloWorld from Groovy on ${new Date()}"

println "HelloWorld from Groovy on ${new Date()}"
28 changes: 28 additions & 0 deletions asciidoctor-doxia-module/src/test/resources/sample.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Document Title
==============
Doc Writer <thedoc@asciidoctor.org>
:idprefix: id_

Preamble paragraph.

NOTE: This is a test, only a test.

== Section A

*Section A* paragraph.

=== Section A Subsection

*Section A* 'subsection' paragraph.

== Section B

*Section B* paragraph.

.Section B list
* Item 1
* Item 2
* Item 3

[source,ruby]
require 'asciidoctor'