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
12
13
14
15
16
17
18
19 public class CopyDocumentationMojo
20 extends AbstractSiteMojo
21 {
22
23
24
25
26
27 private File mappingsSourceDirectory;
28
29
30
31
32
33
34 private File mappingsOutputDirectory;
35
36
37
38
39
40
41 private File carRentalSystemSourcePath;
42
43
44
45
46
47
48 private File carRentalSystemOutputDirectory;
49
50
51
52
53
54
55 private File animalQuizSourcePath;
56
57
58
59
60
61
62 private File animalQuizOutputDirectory;
63
64
65
66
67
68
69 private File documentationSourceDirectory;
70
71
72
73
74
75
76 private File documentationOutputDirectory;
77
78
79
80
81
82
83 @SuppressWarnings("unused")
84 private String projectName;
85
86
87
88
89
90
91 protected MavenProject project;
92
93
94
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
113
114
115
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
147
148
149
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
181
182
183
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
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
221
222
223
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
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 }