Skip to content

Commit

Permalink
resolves #170, #180, #179, #168 & #160 enable configuration for site …
Browse files Browse the repository at this point in the history
…parser

- rewrite Maven Site parser to make more organized and extensible
- pass AsciiDoc configuration in Maven Site plugin to Asciidoctor API
- enhance Maven Site integration test
  - add custom template
  - add include
  - add source highlighting
  - make validation code compatible with Java 6
- enable integration tests on Travis
- remove unused legacy site module
  • Loading branch information
mojavelinux committed Dec 14, 2015
1 parent 50922eb commit 4228725
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jdk:
install:
- mvn package -DskipTests=true -Dmaven.javadoc.skip=true -B -V
script:
- mvn test jacoco:report
- mvn verify -Prun-its jacoco:report
after_success:
# 'coveralls:report' goal is responsible for updating coverall.io stats once travisCI build completes
# Look for the article 'Coveralls.io configuration for maven projects' in the wiki (https://github.com/asciidoctor/asciidoctor/wiki) for more details
Expand Down
25 changes: 20 additions & 5 deletions src/it/maven-site-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,33 @@
<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>

<groupId>org.asciidoctor</groupId>
<artifactId>maven-site-test</artifactId>
<artifactId>maven-site-plugin-it</artifactId>
<version>1.0-SNAPSHOT</version>

<name>Maven Site Plugin Test</name>

<name>Maven Site Plugin IT</name>
<build>
<plugins>
<!-- tag::plugin-decl[] -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<configuration>
<asciidoc>
<templateDir>src/site/asciidoc/templates</templateDir>
<requires>
<require>time</require>
</requires>
<attributes>
<source-highlighter>coderay</source-highlighter>
<coderay-css>style</coderay-css>
<toclevels>2</toclevels>
</attributes>
</asciidoc>
<moduleExcludes>
<asciidoc>**/_*.adoc</asciidoc>
</moduleExcludes>
</configuration>
<dependencies>
<dependency>
<groupId>org.asciidoctor</groupId>
Expand All @@ -23,6 +37,7 @@
</dependency>
</dependencies>
</plugin>
<!-- end::plugin-decl[] -->
</plugins>
</build>
</project>
1 change: 1 addition & 0 deletions src/it/maven-site-plugin/src/site/asciidoc/_include.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Content included from the file _include.adoc.
26 changes: 20 additions & 6 deletions src/it/maven-site-plugin/src/site/asciidoc/file-with-toc.adoc
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
= Maven Site Plugin Test
= File with TOC
:toc:

This is an example file to test asciidoctor-maven-plugin with maven-site-plugin.
[.lead]
This is an example file that was processed by the site module in the Asciidoctor Maven Plugin.

== First section

= First section
This is the first section of the page.

== Sub section
include::_include.adoc[]

=== Sub section

This is a subsection of the first section

= Second section
TIP: You can control the number of section levels displayed in the TOC using the `toclevels` attribute.

== Second section

This is the first section of the page.

== Sub section
=== Sub section

This is a subsection of the second section.

[source,xml,indent=0]
----
include::../../../pom.xml[tag=plugin-decl]
----
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
p class=role =content
8 changes: 8 additions & 0 deletions src/it/maven-site-plugin/src/site/site.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<project name="Maven Site Plugin IT">
<body>
<menu name="AsciiDoc Pages">
<item name="File with TOC" href="/file-with-toc.html"/>
</menu>
${reports}
</body>
</project>
71 changes: 57 additions & 14 deletions src/it/maven-site-plugin/validate.bsh
Original file line number Diff line number Diff line change
@@ -1,37 +1,52 @@
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

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

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

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

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

for ( String expectedFile : expectedFiles )
{
File file = new File( outputDir, expectedFile );
System.out.println( "Checking for existence of " + file );
if ( !file.isFile() )
{
throw new Exception( "Missing file " + file );
for (String expectedFile : expectedFiles) {
File file = new File(outputDir, expectedFile);
System.out.println("Checking for presence of " + file);
if (!file.isFile()) {
throw new Exception("Missing file " + file);
}

List lines = new ArrayList();
Closeable resource = null;
try {
String line = null;
BufferedReader bReader = new BufferedReader(resource = new FileReader(file));
while ((line = bReader.readLine()) != null) {
lines.add(line);
}
}
finally {
try {
resource.close();
}
catch (IOException ignore) {}
}

System.out.println("Ensuring that id's match TOC links");
List lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
System.out.println("Ensuring IDs match TOC links");

List tocEntries = new ArrayList();

for (String line : lines) {
Matcher matcher = null;

matcher = tocEntry.matcher(line);
if (matcher.matches()) {
Expand All @@ -48,7 +63,35 @@ for ( String expectedFile : expectedFiles )
}

if (tocEntries.size() != 0) {
throw new Exception("Couldn't find matching ids for the following TOC entries: " + tocEntries);
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 _include.adoc")) {
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.");
}
}

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);
}
}

Expand Down

This file was deleted.

Loading

0 comments on commit 4228725

Please sign in to comment.