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  
17  package org.forgerock.doc.maven;
18  
19  import org.apache.maven.plugin.MojoExecutionException;
20  import org.apache.maven.plugin.MojoFailureException;
21  import org.apache.maven.plugins.annotations.LifecyclePhase;
22  import org.apache.maven.plugins.annotations.Mojo;
23  import org.forgerock.doc.maven.pre.ArtifactBuilder;
24  import org.forgerock.doc.maven.pre.AsciidocToDocBook;
25  import org.forgerock.doc.maven.pre.Branding;
26  import org.forgerock.doc.maven.pre.CommonContent;
27  import org.forgerock.doc.maven.pre.ConditionalText;
28  import org.forgerock.doc.maven.pre.CurrentDocId;
29  import org.forgerock.doc.maven.pre.CustomCss;
30  import org.forgerock.doc.maven.pre.CreateThumbs;
31  import org.forgerock.doc.maven.pre.Dpi;
32  import org.forgerock.doc.maven.pre.Filter;
33  import org.forgerock.doc.maven.pre.HeaderColor;
34  import org.forgerock.doc.maven.pre.ImageData;
35  import org.forgerock.doc.maven.pre.JCite;
36  import org.forgerock.doc.maven.pre.KeepTogether;
37  import org.forgerock.doc.maven.pre.ModifiableCopy;
38  import org.forgerock.doc.maven.pre.PlantUml;
39  import org.forgerock.doc.maven.pre.XCite;
40  
41  /**
42   * Call other classes to pre-process documentation sources.
43   */
44  @Mojo(name = "process", defaultPhase = LifecyclePhase.PRE_SITE)
45  public class PreProcessMojo extends AbstractDocbkxMojo {
46  
47      /**
48       * Call other classes to pre-process documentation sources.
49       *
50       * @throws MojoExecutionException   Failed to process successfully.
51       * @throws MojoFailureException     Failed to process successfully.
52       */
53      @Override
54      public void execute() throws MojoExecutionException, MojoFailureException {
55  
56          if (getBuildDirectory() == null) {
57              throw new MojoExecutionException("No build directory available.");
58          }
59  
60          if (!getBuildDirectory().exists()) {
61              if (!getBuildDirectory().mkdir()) {
62                  throw new MojoExecutionException("Could not create build directory");
63              }
64          }
65  
66          // Get branding.
67          new Branding(this).execute();
68  
69          // Make a copy of the source files that the plugin can edit.
70          new ModifiableCopy(this).execute();
71          new ConditionalText(this).execute();
72  
73          if (!doUsePreProcessedSources()) {  // Sources require pre-processing.
74              new CommonContent(this).execute();
75              new AsciidocToDocBook(this).execute();
76              new JCite(this).execute();
77              new XCite(this).execute();
78              new Filter(this).execute();
79              new ImageData(this).execute();
80              new HeaderColor(this).execute();
81              new PlantUml(this).execute();
82              if (getFormats().contains(Format.pdf) || getFormats().contains(Format.rtf)) {
83                  new KeepTogether(this).execute();
84                  new Dpi(this).execute();
85              }
86              if (getFormats().contains(Format.bootstrap)) {
87                  new CreateThumbs(this).execute();
88              }
89              new CurrentDocId(this).execute();
90              new CustomCss(this).execute();
91          }
92  
93          if (doCreateArtifacts()) {
94              new ArtifactBuilder(this).execute();
95          }
96      }
97  }