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 2012-2014 ForgeRock AS
15   */
16  
17  package org.forgerock.doc.maven.build;
18  
19  import org.apache.maven.plugin.MojoExecutionException;
20  import org.forgerock.doc.maven.AbstractDocbkxMojo;
21  import org.twdata.maven.mojoexecutor.MojoExecutor;
22  
23  import java.io.File;
24  import java.util.ArrayList;
25  
26  /**
27   * Build man page output.
28   */
29  public class Manpage {
30  
31      /**
32       * The Mojo that holds configuration and related methods.
33       */
34      private AbstractDocbkxMojo m;
35  
36      /**
37       * The Executor to run docbkx-tools.
38       */
39      private final Executor executor;
40  
41      /**
42       * Constructor setting the Mojo that holds the configuration.
43       *
44       * @param mojo The Mojo that holds the configuration.
45       */
46      public Manpage(final AbstractDocbkxMojo mojo) {
47          m = mojo;
48          this.executor = new Executor();
49      }
50  
51      /**
52       * Build documents from DocBook XML sources.
53       *
54       * @throws MojoExecutionException Failed to build output.
55       */
56      public void execute() throws MojoExecutionException {
57          executor.prepareOlinkDB();
58          executor.build();
59      }
60  
61      /**
62       * Enclose methods to run plugins.
63       */
64      class Executor extends MojoExecutor {
65  
66          /**
67           * Prepare olink target database from DocBook XML sources.
68           *
69           * @throws MojoExecutionException Failed to build target database.
70           */
71          void prepareOlinkDB() throws MojoExecutionException {
72              // No plans to implement this for man pages.
73          }
74  
75          /**
76           * Build documents from DocBook XML sources.
77           *
78           * @throws MojoExecutionException Failed to build the output.
79           */
80          void build() throws MojoExecutionException {
81              ArrayList<Element> cfg = new ArrayList<MojoExecutor.Element>();
82              cfg.addAll(m.getBaseConfiguration());
83              cfg.add(element(name("includes"), "*/" + m.getDocumentSrcName()));
84              cfg.add(element(name("manpagesCustomization"), m.path(m.getManpagesCustomization())));
85  
86              File manPageOutputDir = new File(m.getDocbkxOutputDirectory(), "manpages");
87              cfg.add(element(name("targetDirectory"), m.path(manPageOutputDir)));
88  
89              executeMojo(
90                      plugin(
91                              groupId("com.agilejava.docbkx"),
92                              artifactId("docbkx-maven-plugin"),
93                              version(m.getDocbkxVersion())),
94                      goal("generate-manpages"),
95                      configuration(cfg.toArray(new Element[cfg.size()])),
96                      executionEnvironment(m.getProject(), m.getSession(), m.getPluginManager()));
97  
98              // Man page generation replaces spaces in path name with underscores.
99              // If necessary, this is corrected during post-processing.
100             m.getLog().info("Man page output directory: "
101                     + manPageOutputDir.getAbsolutePath().replace(' ', '_'));
102         }
103     }
104 }