View Javadoc
1   package org.andromda.maven.plugin.site;
2   
3   import java.io.File;
4   import java.io.FilenameFilter;
5   import org.apache.commons.lang.exception.ExceptionUtils;
6   import org.apache.maven.plugin.MojoExecutionException;
7   import org.apache.maven.plugin.MojoFailureException;
8   import org.apache.maven.project.MavenProject;
9   
10  /**
11   * Goal that copies the required AndroMDA site files to suitable locations preparing
12   * for deployment.
13   *
14   * @phase site
15   * @goal copy-documentation
16   * @description Goal to copy required site files prior to site deployment
17   * @author vancek
18   */
19  public class CopyDocumentationMojo
20      extends AbstractSiteMojo
21  {
22      /**
23       * Path to the mapping source directory containing the mappings
24       *
25       * @parameter expression="${basedir}/../andromda-etc/mappings"
26       */
27      private File mappingsSourceDirectory;
28  
29      /**
30       * Path to the mapping destination directory
31       *
32       * @parameter expression="${project.reporting.outputDirectory}/mappings"
33       */
34      private File mappingsOutputDirectory;
35  
36      /**
37       * Path to the car-rental-system model
38       *
39       * @parameter expression="${basedir}/../samples/car-rental-system/mda/src/main/uml/CarRentalSystem.xml.zip"
40       */
41      private File carRentalSystemSourcePath;
42  
43      /**
44       * Path to the destination directory to copy the car-rental-system model
45       *
46       * @parameter expression="${project.reporting.outputDirectory}"
47       */
48      private File carRentalSystemOutputDirectory;
49  
50      /**
51       * Path to the animal-quiz model
52       *
53       * @parameter expression="${basedir}/../samples/animal-quiz/mda/src/main/uml/AnimalQuiz.xml.zip"
54       */
55      private File animalQuizSourcePath;
56  
57      /**
58       * Path to the destination directory to copy the animal-quiz model
59       *
60       * @parameter expression="${project.reporting.outputDirectory}"
61       */
62      private File animalQuizOutputDirectory;
63  
64      /**
65       * The directory containing the documentation site reporting artifacts
66       *
67       * @parameter expression="${project.reporting.outputDirectory}"
68       */
69      private File documentationSourceDirectory;
70  
71      /**
72       * The documentation output directory used to copy the generated site reporting artifacts
73       *
74       * @parameter expression="${project.reporting.outputDirectory}"
75       */
76      private File documentationOutputDirectory;
77  
78      /**
79       * The name of the project injected from pom.xml. Not used.
80       *
81       * @parameter default-value="${project.name}"
82       */
83      @SuppressWarnings("unused")
84      private String projectName;
85  
86      /**
87       * @parameter expression="${project}"
88       * @required
89       * @readonly
90       */
91      protected MavenProject project;
92  
93      /**
94       * @see org.apache.maven.plugin.Mojo#execute()
95       */
96      public void execute()
97          throws MojoExecutionException, MojoFailureException
98      {
99          this.getLog().info("-----------------------------------------------------------------------------");
100         this.getLog().info("  A n d r o M D A   S i t e   D o c   C o p y");
101         this.getLog().info("-----------------------------------------------------------------------------");
102 
103         this.copyAnimalQuizModel();
104         this.copyCarRentalSystemModel();
105         this.copyMappings();
106         this.copyDocumentationReportArtifacts();
107 
108         this.getLog().info("SITE DOCUMENTATION COPY SUCCESSFUL");
109     }
110 
111     /**
112      * Copy the animal-quiz model for site reference
113      *
114      * @throws MojoExecutionException
115      * @throws MojoFailureException
116      */
117     private void copyAnimalQuizModel()
118         throws MojoExecutionException, MojoFailureException
119     {
120         try
121         {
122             if (!this.animalQuizSourcePath.exists())
123             {
124                 throw new MojoExecutionException("The animal-quiz model location is invalid");
125             }
126 
127             this.copyFile(
128                     this.animalQuizSourcePath,
129                     new File(
130                             this.animalQuizOutputDirectory,
131                             this.animalQuizSourcePath.getName()));
132         }
133         catch (final Throwable throwable)
134         {
135             if (throwable instanceof MojoExecutionException)
136             {
137                 throw (MojoExecutionException)throwable;
138             }
139             throw new MojoExecutionException("An error occurred copying the animal-quiz model '" +
140                 this.project.getArtifactId() + '\'',
141                 ExceptionUtils.getRootCause(throwable));
142         }
143     }
144 
145     /**
146      * Copy the car-rental-system model for site reference
147      *
148      * @throws MojoExecutionException
149      * @throws MojoFailureException
150      */
151     private void copyCarRentalSystemModel()
152         throws MojoExecutionException, MojoFailureException
153     {
154         try
155         {
156             if (!this.carRentalSystemSourcePath.exists())
157             {
158                 throw new MojoExecutionException("The car-rental-system model location is invalid");
159             }
160 
161             this.copyFile(
162                     this.carRentalSystemSourcePath,
163                     new File(
164                             this.carRentalSystemOutputDirectory,
165                             this.carRentalSystemSourcePath.getName()));
166         }
167         catch (final Throwable throwable)
168         {
169             if (throwable instanceof MojoExecutionException)
170             {
171                 throw (MojoExecutionException)throwable;
172             }
173             throw new MojoExecutionException("An error occurred copying the car-rental-system model '" +
174                 this.project.getArtifactId() + '\'',
175                 ExceptionUtils.getRootCause(throwable));
176         }
177     }
178 
179     /**
180      * Copy the mapping files to site documentation location
181      *
182      * @throws MojoExecutionException
183      * @throws MojoFailureException
184      */
185     private void copyMappings()
186         throws MojoExecutionException, MojoFailureException
187     {
188         try
189         {
190             if (!this.mappingsSourceDirectory.exists())
191             {
192                 throw new MojoExecutionException("Mapping source location is invalid");
193             }
194 
195             final File[] files = this.mappingsSourceDirectory.listFiles();
196             for (File file : files)
197             {
198                 // Ignore SVN dir/files
199                 if (!".svn".equalsIgnoreCase(file.getName()))
200                 {
201                     this.copyFile(
202                             file,
203                             new File(this.mappingsOutputDirectory, file.getName()));
204                 }
205             }
206         }
207         catch (final Throwable throwable)
208         {
209             if (throwable instanceof MojoExecutionException)
210             {
211                 throw (MojoExecutionException)throwable;
212             }
213             throw new MojoExecutionException("An error occurred copying mappings '" +
214                 this.project.getArtifactId() + '\'',
215                 ExceptionUtils.getRootCause(throwable));
216         }
217     }
218 
219     /**
220      * Copy the documentation reporting artifacts
221      *
222      * @throws MojoExecutionException
223      * @throws MojoFailureException
224      */
225     private void copyDocumentationReportArtifacts()
226         throws MojoExecutionException, MojoFailureException
227     {
228         try
229         {
230             if (!this.documentationSourceDirectory.exists())
231             {
232                 throw new MojoExecutionException("Documentation source location is invalid");
233             }
234 
235             /**
236              * Retrieve a directory listing with a filename filter
237              */
238             FilenameFilter filter = new FilenameFilter()
239             {
240                 final String[] filteredReports =
241                 {
242                         ".svn",
243                         "integration.html",
244                         "dependencies.html",
245                         "dependency-convergence.html",
246                         "issue-tracking.html",
247                         "mailing-lists.html",
248                         "license.html",
249                         "project-summary.html",
250                         "team-list.html",
251                         "source-repository.html"
252                 };
253 
254                 public boolean accept(File dir, String name)
255                 {
256                     boolean accept = true;
257                     for (String filteredReport : filteredReports)
258                     {
259                         if (name.equalsIgnoreCase(filteredReport))
260                         {
261                             accept = false;
262                         }
263                     }
264                     return accept;
265                 }
266             };
267             final File[] files = this.documentationSourceDirectory.listFiles(filter);
268             for (File file : files)
269             {
270                 this.copyFile(
271                         file,
272                         new File(
273                                 this.documentationOutputDirectory,
274                                 file.getName()));
275             }
276         }
277         catch (final Throwable throwable)
278         {
279             if (throwable instanceof MojoExecutionException)
280             {
281                 throw (MojoExecutionException)throwable;
282             }
283             throw new MojoExecutionException("An error occurred copying documentation/reporting artifacts '" +
284                 this.project.getArtifactId() + '\'',
285                 ExceptionUtils.getRootCause(throwable));
286         }
287     }
288 }