View Javadoc
1   /*
2    * The contents of this file are subject to the terms of the Common Development and
3    * Distribution License (the License). You may not use this file except in compliance with the
4    * License.
5    *
6    * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7    * specific language governing permission and limitations under the License.
8    *
9    * When distributing Covered Software, include this CDDL Header Notice in each file and include
10   * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11   * Header, with the fields enclosed by brackets [] replaced by your own identifying
12   * information: "Portions copyright [year] [name of copyright owner]".
13   *
14   * Copyright 2015 ForgeRock AS.
15   */
16  package org.forgerock.doc.maven.pre;
17  
18  import org.apache.maven.plugin.MojoExecutionException;
19  import org.forgerock.doc.maven.AbstractDocbkxMojo;
20  import org.twdata.maven.mojoexecutor.MojoExecutor;
21  
22  /**
23   * Converts Asciidoc source files to DocBook 5 XML.
24   */
25  public class AsciidocToDocBook {
26  
27      /**
28       * The Mojo that holds configuration and related methods.
29       */
30      private AbstractDocbkxMojo m;
31  
32      /**
33       * The Executor to run the resources plugin.
34       */
35      private final Executor executor;
36  
37      /**
38       * Constructor setting the Mojo that holds the configuration.
39       *
40       * @param mojo The Mojo that holds the configuration.
41       */
42      public AsciidocToDocBook(final AbstractDocbkxMojo mojo) {
43          m = mojo;
44          this.executor = new Executor();
45      }
46  
47      /**
48       * Copies arbitrary resources from sources to pre-site output for HTML formats.
49       *
50       * @throws MojoExecutionException Failed to copy files
51       */
52      public void execute() throws MojoExecutionException {
53          executor.convert();
54      }
55  
56      /**
57       * Enclose methods to run plugins.
58       */
59      class Executor extends MojoExecutor {
60  
61          /**
62           * Converts Asciidoc source files to DocBook 5 XML.
63           *
64           * @throws MojoExecutionException   Failed to convert files
65           */
66          public void convert() throws MojoExecutionException {
67              if (!m.getAsciidocSourceDirectory().exists()) {
68                  return;
69              }
70  
71              executeMojo(
72                      plugin(
73                              groupId("org.asciidoctor"),
74                              artifactId("asciidoctor-maven-plugin"),
75                              version(m.getAsciidoctorPluginVersion())),
76                      goal("process-asciidoc"),
77                      configuration(
78                              element("baseDir", m.path(m.getAsciidocSourceDirectory())),
79                              element("outputDirectory", m.path(m.getDocbkxModifiableSourcesDirectory())),
80                              element("preserveDirectories", "true"),
81                              element("extensions",
82                                      element("extension", ".ad"),
83                                      element("extension", ".adoc"),
84                                      element("extension", ".asciidoc"),
85                                      element("extension", ".txt")),
86                              element("backend", "docbook"),
87                              element("doctype", "book")),
88                      executionEnvironment(m.getProject(), m.getSession(), m.getPluginManager()));
89          }
90      }
91  }