A lifecycle and custom mojos to isolate the building of asciidoctor documentation from the default lifecycle with the asciidoctor-maven-plugin.
In this section I will tell you the most recent changes. This section will disappear with the final release.
-
Added
phase beforeasciidoctor-prepare-resources
asciidoctor-theme
-
Added
phase afterasciidoctor-verify
phase.asciidoctor-post-publish
-
Renamed
toasciidoctor-prepare-convert
.asciidoctor-pre-convert
-
Renamed
toasciidoctor-prepare-notify
.asciidoctor-pre-notify
-
Renamed
toasciidoctor-prepare-publish
.asciidoctor-pre-publish
-
Renamed
toasciidoctor-prepare-theme
.asciidoctor-pre-theme
-
Renamed
toPrepareSourcesMojo.java
(and integration test related files).CopySourcesMojo.java
-
Takari tests were replaced with Integration Testing Framework.
-
JUnit4 was replaced with JUnit5 and AssertJ.
-
Some tests now owns their own IT class.
-
Removed one ignored test (publishWithProxy) and one redundant test (publishWithoutProxy).
-
Now tests can be executed in parallel with
.-Pparallel
-
Now jacoco execution is optional. You can enable it with
.-Pquality
-
Files
README.adoc
andlifecycle.adoc
updated. -
Added phases
asciidoctor-prepare-notify
andasciidoctor-notify
. -
Renamed phase
prepare-build
toasciidoctor-prepare-convert
. -
Renamed phase
build
toasciidoctor-convert
. -
Renamed phase
prepare-theme
toasciidoctor-prepare-theme
. -
Renamed phase
theme
toasciidoctor-theme
. -
Renamed all files and examples to conform to new names.
-
Big redesign of
UploadMojo
code (now calledPublishMojo
). -
upload
phase renamed toasciidoctor-publish
.
-
Source code refactorization in order to support more features.
-
Test code refactorization; it is more easily create a new integration test now, with the AbstractMojoIT.
-
Updated
README.adoc
to reflect Maven [3.3.9,3.6.1] versions supported. -
Updated
invoker.properties
files forinvoker.maven.version
. -
Updated
pom.xml
file to Maven [3.3.9,3.6.1] requirement.
-
Maven requirements reduced to 3.3.9.
-
Apache 2 license badge in
README.adoc
. -
Improvements in coverage.
-
Mixin the it and unit test coverage.
-
Reduce number of branches in
ThemeMojo.java
.
-
Integration with coveralls.
-
Some unit tests developed.
-
asciidoctor-maven-plugin:process-asciidoc
goal mapped tobuild
phase.
-
Initial support for uploading generated files to a wagon repository. You need to configure the wagon provider in
asciidoctor-lifecycle-maven-plugin
dependencies. -
Documentation improved (Javadoc).
-
English fixes in README.adoc (thanks to my friend Manuel Vicente, I still need your help).
-
Renamed the
theme-download
phase totheme
phase, because in this phase we do other things, as unzip and create properties, and the download is done only if the artifact is not in the local repository. -
Renamed the
pre-build
phase toprepare-build
. -
Renamed the
pre-upload
phase toprepare-upload
. -
Added a basic support for the
upload
phase, the UploadMojo. -
The property names are refactorized.
-
Added the Maven site (basic).
-
Documentation updated.
-
In the
theme
phase for each downloaded theme, a property is created. Its value is the path where it was unzipped. -
Documentation updated.
This project offers a new Maven plugin, with the following functionalities (this is a work in progress):
-
A new lifecycle, designed for resolving some of the needs I’ve found in my personal projects.
-
A mojo for downloading themes for using with Asciidoctor Maven Plugin.
-
A mojo for publish generated files with the help of Maven Wagon API, in the same way as the
maven-site-plugin
.
I hope this plugin helps others to write a cleaner separation between the build of the asciidoc documentation
This project tries to cover those aspects of asciidoctor-maven-plugin that doesn’t fit well with the Maven default lifecycle. What are this aspects?
-
When a project contains asciidoc documentation and code, you need a complicated configuration to build only asciidoc or only code. Profiles here may be a solution, specifying modules to build in every one, but…
-
The default lifecycle seems oriented to code building; this is not something negative in itself, but the name of the phases are confusing enough if we think about documentation and not code (
compile
,test
,verify
). -
If you want to build the site documentation, Maven offers you another lifecycle: the site lifecycle.
-
If you need to download a theme for generating a pdf (for example) you need to use the
dependency:get
as a solution, and if you need to do something more with the theme content you need to write too much configuration.
So, why not develop a custom lifecycle?
This project is a Work In Progress, in early stage of development. You can test or use it in your own projects, but you should understand:
-
Something can change at any time before the first release, breaking compatibility with pre releases versions.
-
There is no version available in any repository yet.
-
You have to build it with your own hands (it is not difficult, it is a standard Maven project).
This lifecycle add a defined sequence of phases that helps to build the Asciidoctor documents without the use of profiles. These are the phases of this lifecycle (in sequential order):
Phase | Description | Mojo |
---|---|---|
asciidoctor-pre-theme |
Prepare the theme download. |
|
asciidoctor-theme |
In this phase the themes are downloaded from remote repositories, if required, unzipped and copying common resources to a folder. |
ThemeMojo |
asciidoctor-pre-convert |
Actions required before the asciidoctor conversion. |
|
asciidoctor-convert |
The |
|
asciidoctor-pre-publish |
Actions required before publishing documents. |
|
asciidoctor-publish |
Publishing generated content in a remote webdav server, a local filesystem… |
PublishMojo |
asciidoctor-pre-notice |
Actions required before notifying users new documentation version. |
|
asciidoctor-notice |
Actions required for notifying users new documentation version. |
At the moment a theme in asciidoctor-lifecycle is only an artifact wich zip packaging. This requirement allow us uncompress its contents to a folder.
At the moment it has not been formally defined or its contents established.
You can define the use of a theme (downloading and unpacking it to a directory) as part of the
asciidoctor-lifecycle-maven-plugin
configuration.
You can configure so many themes as you desire.
The themes are expressed as Maven coordinates as:
<groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>
So a valid theme expression is:
groupId:artifactId:zip:3.3.3
The Asciidoctor Lifecycle Maven Pluging does the following operations for every configured theme:
-
Tries to download the artifact (theme).
-
Tries to unzip the contents of the artifact downloaded to a directory, specified by the configuration property
asciidoctor.lifecycle.outputDirectory
as parent directory, and the directory child name is the same as itsartifactId
. -
Creates a property with the value of the path of the directory where the theme was unzipped.
-
If any of the previous operations fails, it breaks the build.
All these operations are done at theme
phase, so using the Asciidoctor Lifecycle
you can use in the rest of the phases the property created automatically at this phase.
It is very easy use this new lifecycle. It is a standard Maven plugin.
<plugin>
<groupId>com.coutemeier.maven.plugins</groupId>
<artifactId>asciidoctor-lifecycle-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<extensions>true</extensions> <!--(1)-->
</plugin>
-
We use the plugin as an extension.
We configure the
asciidoctor-maven-plugin
attaching the process-asciidoc
goal to the build
phase.
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.8</version>
<executions>
<!-- So many executions as you need -->
<execution>
<id>output-html</id>
<phase>build</phase> <!--(1)-->
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>html5</backend>
</configuration>
</execution>
</executions>
</plugin>
-
We attach the
asciidoctor-maven-plugin:process-asciidoc
goal to the build phase of theasciidoctor-lifecycle-build
lifecycle.
We are ready to generate our documentation separate of the normal build of our code.
At this moment the asciidoctor-publish
phase is implemented in its basic functionality.
It uses the Maven Wagon API,
so you have to configure the dependency to the implementation provider (if needed).
I’ve tested it to publish files to a webdav server and to copy them to a directory in filesystem, and it is possible that works with another wagon providers.
With last changes proxy feature was implemented as in maven-site-plugin.
This is a simple example to configure the upload to a directory in your filesystem:
<plugin>
<groupId>com.coutemeier.maven.plugins</groupId>
<artifactId>asciidoctor-lifecycle-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<extensions>true</extensions>
<configuration>
<serverId>nexus</serverId> <!--(1)-->
<publishToRepository>dav://http://my-own-webdav-server/file-repository</publishToRepository> <!--(2)-->
<publishToRepository>file://${project.build.directory}/file-repository</publishToRepository> <!--(2)-->
<publishToDirectory>${project.artifactId}/${project.version}</publishToDirectory> <!--(3)-->
</configuration>
<!-- No dependency needed -->
</plugin>
-
server
identifier insettings.xml
for authorization. -
The base path for storing the files in http webdav server or filesystem (choose one).
-
The directory in the base path where you want to store the files.
If ${project.artifactId} = theArtifact
and ${project.version} = 1.0.0
then generated files will be copied to `${project.build.directory}/file-repository/theArtifact/1.0.0`directory.
mvn asciidoctor-publish
|
The |
Therefore,
if you follow the convention of writing a shared configuration in the plugin configuration,
and an execution for each of the output formats,
you will also obtain the default format established by the plugin,
which at the time of writing this documentation is docbook
.
To avoid this additional execution you can write the corresponding one of the executions in the plugin configuration, together with the shared configuration, and the other formats in the configuration of their corresponding executors.
If you follows the shared configuration convention you will write something similar to:
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>${asciidoctor.maven.plugin.version}</version>
<configuration> <!--(1)-->
<sourceDirectory>src/docs/asciidoc</sourceDirectory>
<sourceHighlighter>coderay</sourceHighlighter>
<attributes>
<!-- Shared attributes-->
<sourcedir>${project.build.sourceDirectory}</sourcedir>
<project-version>${project.version}</project-version>
<imagesdir>./images</imagesdir>
<icons>font</icons>
</attributes>
</configuration>
<executions>
<execution>
<id>generate-html5-doc</id> <!--(2)-->
<phase>build</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>html5</backend>
<attributes>
<docinfo1>true</docinfo1>
<idprefix/>
<idseparator>-</idseparator>
<sectanchors>true</sectanchors>
<toc>left</toc>
</attributes>
</configuration>
</execution>
<execution>
<id>generate-pdf-doc</id> <!--(3)-->
<phase>build</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>pdf</backend>
<attributes>
<idprefix/>
<idseparator>-</idseparator>
<pagenums/>
<toc/>
<sectanchors>false</sectanchors>
</attributes>
</configuration>
</execution>
</executions>
</plugin>
-
Shared configuration at plugin configuration.
-
Configuration for HTML5 output format at its own execution configuration.
-
Configuration for PDF output format at its own execution configuration.
When executing mvn build
it will also launch the execution associated with the configuration of the plugin,
associated with backend = docbook
.
💡
|
Of course, you can continue to configure the plugin in this way if you wish. |
If you want to avoid the default backend generation:
Below we show you how to configure the asciidoctor-maven-plugin
plugin to use it in conjunction
with asciidoctor-lifecycle-maven-plugin
and avoid additional backend generation by default.
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>${asciidoctor.maven.plugin.version}</version>
<configuration>
<!-- Shared configuration -->
<sourceDirectory>src/docs/asciidoc</sourceDirectory> <!--(1)-->
<sourceHighlighter>coderay</sourceHighlighter> <!--(1)-->
<!-- Specificy HTML5 configuration -->
<backend>html5</backend> <!--(2)-->
<attributes>
<!-- Shared attributes-->
<sourcedir>${project.build.sourceDirectory}</sourcedir> <!--(1)-->
<project-version>${project.version}</project-version> <!--(1)-->
<imagesdir>./images</imagesdir> <!--(1)-->
<icons>font</icons> <!--(1)-->
<!-- HTML configuration -->
<docinfo1>true</docinfo1> <!--(2)-->
<idprefix/><!--(2)-->
<idseparator>-</idseparator> <!--(2)-->
<sectanchors>true</sectanchors> <!--(2)-->
<toc>left</toc> <!--(2)-->
</attributes>
</configuration>
<executions>
<execution>
<id>generate-pdf-doc</id> <!--(3)-->
<phase>build</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>pdf</backend>
<attributes>
<docinfo1>false</docinfo1>
<idprefix/>
<idseparator>-</idseparator>
<pagenums/>
<toc/>
<sectanchors>false</sectanchors>
</attributes>
</configuration>
</execution>
</executions>
</plugin>
-
Shared configuration at plugin configuration.
-
Configuration for HTML5 output format at plugin configuration.
-
Configuration for PDF output format at its own execution configuration.
Suposse you configure the asciidoctor-maven-plugin
and the asciidoctor-lifecycle-maven-plugin
as (I show you only the relevant configuration for this purpose):
<plugin>
<groupId>com.coutemeier.maven.plugins</groupId>
<artifactId>asciidoctor-lifecycle-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<extensions>true</extensions>
<configuration>
<themesBaseDir>${project.build.directory}/asciidoctor-themes</themesBaseDir> <!--(1)-->
<themes>
<theme>com.coutemeier.maven.plugins:theme-example-1:zip:1.2.0</theme> <!--(2)-->
<theme>com.coutemeier.maven.plugins:theme-example-2:zip:2.2.1</theme>
</themes>
</configuration>
</plugin>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>${asciidoctor.maven.plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj-pdf</artifactId>
<version>${asciidoctorj.pdf.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>generate-pdf-doc-custom-theme</id>
<phase>build</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>pdf</backend>
<outputDirectory>${project.build.directory}/generated-docs-custom-theme</outputDirectory>
<sourceHighlighter>coderay</sourceHighlighter>
<doctype>book</doctype>
<attributes>
<!--
The property "asciidoctor.theme.theme-example-1.path" is created at `theme` phase,
so it is not needed to define it in the pom.xml.
-->
<pdf-stylesdir>${asciidoctor.theme.theme-example-1.path}/pdf</pdf-stylesdir> <!--(3)-->
<pdf-style>custom</pdf-style>
<icons>font</icons>
<pagenums/>
<toc/>
<idprefix/>
<idseparator>-</idseparator>
</attributes>
</configuration>
</execution>
</executions>
</plugin>
-
The directory where themes will be unzipped (this is the default value).
-
You need the plugin whose coordinates are
com.coutemeier.maven.plugins:theme-example-1:zip:1.2.0
. -
You configure the path of the theme using the property
asciidoctor.theme.theme-example-1.path
, created attheme
phase.
After the theme
phase execution you’ll get:
-
Two directories in the
target/asciidoctor-themes
:-
theme-example-1
-
theme-example-2
-
-
Two properties are created in this phase, so you can use them in later phases.
-
asciidoctor.theme.theme-example-1.path = ${project.output.dir}/asciidoctor-themes/theme-example1
-
asciidoctor.theme.theme-example-2.path = ${project.output.dir}/asciidoctor-themes/theme-example2
-
In the build
phase execution:
-
The property
asciidoctor.theme.theme-example-1.path
andasciidoctor.theme.theme-example-2.path
are defined, so you can use them as a property to configure the path of the YAML file.
Let’s see an example to publish files to a webdav repository:
<plugin>
<groupId>com.coutemeier.maven.plugins</groupId>
<artifactId>asciidoctor-lifecycle-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<extensions>true</extensions>
<configuration>
<serverId>webdav-snapshots</serverId> <!--(1)-->
<publishToRepository>dav:http://localhost:8081/nexus/content/sites/test-site/</publishToRepository> <!--(2)-->
<publishToDirectory>${project.artifactId}/${project.version}</publishToDirectory> <!--(3)-->
</configuration>
<!--
You need the wagon-webdav-jackrabbit dependency
if you want to publish to a webdav server
-->
<dependencies>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-webdav-jackrabbit</artifactId> <!--(4)-->
<version>3.0.0</version>
</dependency>
</dependencies>
</plugin>
-
The server id corresponding to a
server
entry insettings.xml
, with credentials to publishing the files to the server. -
The url to which you want to publish the files.
-
The directory where you want to publish the files.
-
The dependency for wagon webdav support.
You can build the project with Maven [3.3.9,4.0) versions and Java 8.
mvn clean package
You can launch the integration tests:
mvn clean verify -Prun-it
The profile with id=parallel
allows running tests in parallel,
so you can launch the tests as:
mvn clean test -Pparallel
or
mvn clean verify -Pparallel
Tests were redesigned using JUnit5 to run in CONCURRENT mode, so the reports are affected by the bug JUnit 5 in parallel execution mode confuses Surefire reports.
So please, ignore for the moment the wrong number of tests in surefire report, like:
[INFO] Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.214 s - in com.coutemeier.maven.plugins.asciidoctor.lifecycle.util.ZipUtilTestCase
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.266 s - in com.coutemeier.maven.plugins.asciidoctor.lifecycle.util.FileUtilTestCase
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.21 s - in com.coutemeier.maven.plugins.asciidoctor.lifecycle.util.ArtifactUtilOtherTestCase
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.418 s - in com.coutemeier.maven.plugins.asciidoctor.lifecycle.util.ArtifactUtilTestCase
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.925 s - in com.coutemeier.maven.plugins.asciidoctor.lifecycle.util.WagonUtilTestCase