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.pre;
18  
19  import org.apache.maven.plugin.MojoExecutionException;
20  import org.forgerock.doc.maven.AbstractDocbkxMojo;
21  import org.twdata.maven.mojoexecutor.MojoExecutor;
22  
23  /**
24   * Unpack branding elements.
25   * The branding is unpacked from a separate artifact.
26   */
27  public class Branding {
28  
29      /**
30       * The Mojo that holds configuration and related methods.
31       */
32      private AbstractDocbkxMojo m;
33  
34      /**
35       * The Executor to run the dependency plugin.
36       */
37      private final Executor executor;
38  
39      /**
40       * Constructor setting the Mojo that holds the configuration.
41       *
42       * @param mojo The Mojo that holds the configuration.
43       */
44      public Branding(final AbstractDocbkxMojo mojo) {
45          m = mojo;
46          this.executor = new Executor();
47      }
48  
49      /**
50       * Augment the modifiable copy of DocBook XML sources with branding elements.
51       *
52       * @throws MojoExecutionException Failed to unpack branding.
53       */
54      public void execute() throws MojoExecutionException {
55          executor.unpack();
56      }
57  
58      /**
59       * Enclose methods to run plugins.
60       */
61      class Executor extends MojoExecutor {
62  
63          /**
64           * Unpack branding elements from the branding artifact.
65           *
66           * @throws MojoExecutionException Failed to unpack branding.
67           */
68          public void unpack() throws MojoExecutionException {
69              final String outputDir = m.path(m.getBuildDirectory());
70  
71              executeMojo(
72                      plugin(
73                              groupId("org.apache.maven.plugins"),
74                              artifactId("maven-dependency-plugin"),
75                              version(m.getMavenDependencyVersion())),
76                      goal("unpack"),
77                      configuration(
78                              element("artifactItems",
79                                      element("artifactItem",
80                                              element("groupId", m.getBrandingGroupId()),
81                                              element("artifactId", m.getBrandingArtifactId()),
82                                              element("version", m.getBrandingVersion()),
83                                              element("type", "jar"),
84                                              element("overWrite", "true"),
85                                              element("outputDirectory", outputDir),
86                                              element("includes", "**/*.*")))),
87                      executionEnvironment(m.getProject(), m.getSession(), m.getPluginManager()));
88          }
89      }
90  }