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

resolves #170, #180, #179, #168 & #160 enable configuration for site parser #182

Merged
merged 1 commit into from
Dec 15, 2015
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
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 -Prun-its verify 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
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ install:
build_script:
- mvn clean package -B -Dmaven.test.skip=true
test_script:
- mvn test -B
- mvn -Prun-its verify -B
cache:
- C:\bin\apache-maven-3.2.5\
34 changes: 29 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,42 @@
<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>
<templateDirs>
<dir>src/site/asciidoc/templates</dir>
</templateDirs>
<!-- or...
<templateDir>src/site/asciidoc/templates</templateDir>
-->
<requires>
<require>base64</require>
<require>time</require>
</requires>
<!-- or...
<requires>base64,time</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 +46,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.