Skip to content

Commit

Permalink
Mark BuildMojo as threadSafe (asciidoctor#364)
Browse files Browse the repository at this point in the history
* Mark BuildMojo as threadSafe

This annotation will remove a maven build warning.

Resolves: asciidoctor#326

* Add integration test for thread safe lable

All three modules produces the same result. If the content
is mixed during the parallel execution the results will
be different and the test fails.

* Make the test java 7 compatible

* Don't generate header and footer

Set 'headerFooter' to 'false'. The generated html files must
not contain timestamps.
  • Loading branch information
timkrueger authored and abelsromero committed Aug 21, 2018
1 parent 869aa78 commit 48d1142
Show file tree
Hide file tree
Showing 10 changed files with 319 additions and 1 deletion.
46 changes: 46 additions & 0 deletions src/it/thread-safe/asciidoctor-project-1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-project-1</artifactId>

<parent>
<groupId>org.asciidoctor</groupId>
<artifactId>test-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<description>Runs asciidoctor-maven-plugin:process-asciidoc</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>html</id>
<phase>generate-resources</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<sourceDirectory>src/main/doc</sourceDirectory>
<outputDirectory>target/docs</outputDirectory>
<backend>html</backend>
<headerFooter>false</headerFooter>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Document Title
==============
Doc Writer <thedoc@asciidoctor.org>
:idprefix: id_

Preamble paragraph.

NOTE: This is 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

== Section C

[source,java]
----
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!!");
}
}
----
46 changes: 46 additions & 0 deletions src/it/thread-safe/asciidoctor-project-2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-project-2</artifactId>

<parent>
<groupId>org.asciidoctor</groupId>
<artifactId>test-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<description>Runs asciidoctor-maven-plugin:process-asciidoc</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>html</id>
<phase>generate-resources</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<sourceDirectory>src/main/doc</sourceDirectory>
<outputDirectory>target/docs</outputDirectory>
<backend>html</backend>
<headerFooter>false</headerFooter>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Document Title
==============
Doc Writer <thedoc@asciidoctor.org>
:idprefix: id_

Preamble paragraph.

NOTE: This is 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

== Section C

[source,java]
----
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!!");
}
}
----
46 changes: 46 additions & 0 deletions src/it/thread-safe/asciidoctor-project-3/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-project-3</artifactId>

<parent>
<groupId>org.asciidoctor</groupId>
<artifactId>test-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<description>Runs asciidoctor-maven-plugin:process-asciidoc</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>html</id>
<phase>generate-resources</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<sourceDirectory>src/main/doc</sourceDirectory>
<outputDirectory>target/docs</outputDirectory>
<backend>html</backend>
<headerFooter>false</headerFooter>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Document Title
==============
Doc Writer <thedoc@asciidoctor.org>
:idprefix: id_

Preamble paragraph.

NOTE: This is 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

== Section C

[source,java]
----
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!!");
}
}
----
1 change: 1 addition & 0 deletions src/it/thread-safe/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=-T3 clean compile
22 changes: 22 additions & 0 deletions src/it/thread-safe/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.asciidoctor</groupId>
<artifactId>test-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<description>Tests that the plugin is thread safe by checking that the result content are not mixed.</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<modules>
<module>asciidoctor-project-1</module>
<module>asciidoctor-project-2</module>
<module>asciidoctor-project-3</module>
</modules>

</project>
37 changes: 37 additions & 0 deletions src/it/thread-safe/validate.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import java.nio.charset.Charset
import java.nio.file.Files

String fileTemplate = "asciidoctor-project-%s/target/docs/sample.html"

List<String> contents = new ArrayList<>()
List<String> files = new ArrayList<>()
for (int i = 1; i <= 3; i++) {
File file = new File(basedir, String.format(fileTemplate, i))
println("Checking for existence of " + file)
if (!file.isFile()) {
throw new Exception("Missing file " + file)
}

StringBuilder contentOfFile = new StringBuilder()
for (String line : Files.readAllLines(file.toPath(), Charset.forName("UTF-8"))) {
contentOfFile.append(line)
}
contents.add(contentOfFile.toString())
files.add(String.format(fileTemplate, i))

}


if(!contents.get(0).equals(contents.get(1))) {
throw new Exception(String.format("The content of two files are different.\n\n%s: %s\n%s: %s", files.get(0), contents.get(0), files.get(1), contents.get(1) ))
}

if(!contents.get(1).equals(contents.get(2))) {
throw new Exception(String.format("The content of two files are different.\n\n%s: %s\n%s: %s", files.get(1), contents.get(1), files.get(2), contents.get(2) ))
}

if(!contents.get(2).equals(contents.get(0))) {
throw new Exception(String.format("The content of two files are different.\n\n%s: %s\n%s: %s", files.get(2), contents.get(2), files.get(0), contents.get(0) ))
}

return true
2 changes: 1 addition & 1 deletion src/main/java/org/asciidoctor/maven/AsciidoctorMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
/**
* Basic maven plugin goal to render AsciiDoc files using Asciidoctor, a ruby port.
*/
@Mojo(name = "process-asciidoc")
@Mojo(name = "process-asciidoc", threadSafe = true)
public class AsciidoctorMojo extends AbstractMojo {
// copied from org.asciidoctor.AsciiDocDirectoryWalker.ASCIIDOC_REG_EXP_EXTENSION
// should probably be configured in AsciidoctorMojo through @Parameter 'extension'
Expand Down

0 comments on commit 48d1142

Please sign in to comment.