View Javadoc
1   package org.andromda.maven.plugin.site;
2   
3   import java.io.File;
4   import org.apache.commons.lang.exception.ExceptionUtils;
5   import org.apache.maven.plugin.MojoExecutionException;
6   import org.apache.maven.plugin.MojoFailureException;
7   import org.apache.maven.project.MavenProject;
8   
9   /**
10   * Goal that unpacks the required AndroMDA site zip packages to suitable locations preparing
11   * for deployment.
12   *
13   * @phase site
14   * @goal unpack-documentation
15   * @description Goal to unpack required site files prior to site deployment
16   * @author vancek
17   */
18  public class UnpackDocumentationMojo
19      extends AbstractSiteMojo
20  {
21      /**
22       * Path to the JMI 1.4 API zip source
23       *
24       * @parameter expression="${basedir}/src/site/resources/resources/jmi-uml1.4.zip"
25       */
26      private File jmiApiSourcePath;
27  
28      /**
29       * Path to the JMI 1.4 API destination extraction directory
30       *
31       * @parameter expression="${basedir}/../../target/site"
32       */
33      private File jmiApiOutputDirectory;
34  
35      /**
36       * Path to the UmlDoc car-rental-sample zip source
37       *
38       * @parameter expression="${basedir}/src/site/resources/resources/car-rental-umldoc.zip"
39       */
40      private File umlDocCarRentalSampleSourcePath;
41  
42      /**
43       * Path to the UmlDoc car-rental-sample extraction directory
44       *
45       * @parameter expression="${basedir}/../../target/site"
46       */
47      private File umlDocCarRentalSampleOutputDirectory;
48  
49      /**
50       * The name of the project injected from pom.xml. Not used.
51       *
52       * @parameter default-value="${project.name}"
53       */
54      @SuppressWarnings("unused")
55      private String projectName;
56  
57      /**
58       * @parameter expression="${project}"
59       * @required
60       * @readonly
61       */
62      protected MavenProject project;
63  
64      /**
65       * @see org.apache.maven.plugin.Mojo#execute()
66       */
67      public void execute()
68          throws MojoExecutionException, MojoFailureException
69      {
70          this.getLog().info("-----------------------------------------------------------------------------");
71          this.getLog().info("  A n d r o M D A   S i t e   D o c   U n p a c k");
72          this.getLog().info("-----------------------------------------------------------------------------");
73  
74          this.unpackUmlDocCarRentalSample();
75          this.unpackJmiApi();
76  
77          this.getLog().info("SITE DOCUMENTATION UNPACK SUCCESSFUL");
78      }
79  
80      /**
81       * Unpack the JMI 1.4 API
82       *
83       * @throws MojoExecutionException
84       * @throws MojoFailureException
85       */
86      private void unpackJmiApi()
87          throws MojoExecutionException, MojoFailureException
88      {
89          try
90          {
91              if (!this.jmiApiSourcePath.exists())
92              {
93                  throw new MojoExecutionException("JMI API source location is invalid");
94              }
95  
96              this.unpack(
97                      this.jmiApiSourcePath,
98                      this.jmiApiOutputDirectory);
99          }
100         catch (final Throwable throwable)
101         {
102             if (throwable instanceof MojoExecutionException)
103             {
104                 throw (MojoExecutionException)throwable;
105             }
106             throw new MojoExecutionException("An error occurred unpacking JMI 1.4 API '" +
107                 this.project.getArtifactId() + '\'',
108                 ExceptionUtils.getRootCause(throwable));
109         }
110     }
111 
112     /**
113      * Unpack the UmlDoc for the car-rental-sample
114      *
115      * @throws MojoExecutionException
116      * @throws MojoFailureException
117      */
118     private void unpackUmlDocCarRentalSample()
119         throws MojoExecutionException, MojoFailureException
120     {
121         try
122         {
123             if (!this.umlDocCarRentalSampleSourcePath.exists())
124             {
125                 throw new MojoExecutionException("UmlDoc car-rental-sample source location is invalid");
126             }
127 
128             this.unpack(
129                     this.umlDocCarRentalSampleSourcePath,
130                     this.umlDocCarRentalSampleOutputDirectory);
131         }
132         catch (final Throwable throwable)
133         {
134             if (throwable instanceof MojoExecutionException)
135             {
136                 throw (MojoExecutionException)throwable;
137             }
138             throw new MojoExecutionException("An error occurred unpacking UmlDoc for car-rental-sample '" +
139                 this.project.getArtifactId() + '\'',
140                 ExceptionUtils.getRootCause(throwable));
141         }
142     }
143 }