1 package org.andromda.maven.plugin.cartridge.site;
2
3 import java.io.File;
4 import java.util.List;
5 import org.andromda.maven.plugin.AndroMDAMojo;
6 import org.apache.commons.lang.exception.ExceptionUtils;
7 import org.apache.maven.plugin.MojoExecutionException;
8 import org.apache.maven.plugin.MojoFailureException;
9 import org.apache.maven.project.MavenProject;
10 import org.apache.maven.settings.Settings;
11
12
13
14
15
16
17
18
19
20
21
22
23
24 public class GenerateCartridgeHowtoArtifactsMojo
25 extends AbstractSiteMojo
26 {
27
28
29
30
31
32
33 private File howtoCartridgePicturesSourcePath;
34
35
36
37
38
39
40 private File howtoCartridgePicturesOutputDirectory;
41
42
43
44
45
46
47
48 private String configurationUri;
49
50
51
52
53 private List<String> propertyFiles;
54
55
56
57
58
59
60
61
62
63 private Settings settings;
64
65
66
67
68
69
70 @SuppressWarnings("unused")
71 private String projectName;
72
73
74
75
76
77
78 protected MavenProject project;
79
80
81
82
83
84
85
86 private File modelOutputHistory;
87
88
89
90
91 public void execute()
92 throws MojoExecutionException, MojoFailureException
93 {
94 this.getLog().info("---------------------------------------------------------------------------------------");
95 this.getLog().info(" A n d r o M D A G e n e r a t e C a r t r i d g e H o w T o A r t i f a c t s");
96 this.getLog().info("---------------------------------------------------------------------------------------");
97
98 this.unpackHowToPictures();
99 this.generateHowToSource();
100
101 this.getLog().info("GENERATE CARTRIDGE HOWTO ARTIFACTS SUCCESSFUL");
102 }
103
104
105
106
107
108
109
110 private void unpackHowToPictures()
111 throws MojoExecutionException, MojoFailureException
112 {
113 try
114 {
115 if (!this.howtoCartridgePicturesSourcePath.exists())
116 {
117 throw new MojoExecutionException("Cartridge howto pictures source location is invalid");
118 }
119
120 this.unpack(
121 this.howtoCartridgePicturesSourcePath,
122 this.howtoCartridgePicturesOutputDirectory);
123 }
124 catch (final Throwable throwable)
125 {
126 if (throwable instanceof MojoExecutionException)
127 {
128 throw (MojoExecutionException)throwable;
129 }
130 throw new MojoExecutionException("An error occurred unpacking cartridge howto pictures '" +
131 this.project.getArtifactId() + '\'',
132 ExceptionUtils.getRootCause(throwable));
133 }
134 }
135
136
137
138
139
140
141
142
143 private void generateHowToSource()
144 throws MojoExecutionException, MojoFailureException
145 {
146 try
147 {
148 final AndroMDAMojo andromdaMojo = new AndroMDAMojo();
149 andromdaMojo.setConfigurationUri(this.configurationUri);
150 andromdaMojo.setProject(this.project);
151 andromdaMojo.setSettings(this.settings);
152 andromdaMojo.setPropertyFiles(this.propertyFiles);
153 andromdaMojo.setModelOutputHistory(this.modelOutputHistory);
154 andromdaMojo.execute();
155 }
156 catch (final Throwable throwable)
157 {
158 if (throwable instanceof MojoExecutionException)
159 {
160 throw (MojoExecutionException)throwable;
161 }
162 throw new MojoExecutionException(
163 "An error occurred while running AndroMDA over the cartridge howto model '" +
164 this.project.getArtifactId() + '\'', ExceptionUtils.getRootCause(throwable));
165 }
166 }
167 }