Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
MoversReport |
|
| 2.272727272727273;2.273 |
1 | //////////////////////////////////////////////////////////////////////////////// |
|
2 | // |
|
3 | // ObjectLab is sponsoring QALab |
|
4 | // |
|
5 | // Based in London, we are world leaders in the design and development |
|
6 | // of bespoke applications for the Securities Financing markets. |
|
7 | // |
|
8 | // <a href="http://www.objectlab.co.uk/open">Click here to learn more</a> |
|
9 | // ___ _ _ _ _ _ |
|
10 | // / _ \| |__ (_) ___ ___| |_| | __ _| |__ |
|
11 | // | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ |
|
12 | // | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | |
|
13 | // \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ |
|
14 | // |__/ |
|
15 | // |
|
16 | // http://www.ObjectLab.co.uk |
|
17 | // --------------------------------------------------------------------------- |
|
18 | // |
|
19 | //QALab is released under the GNU General Public License. |
|
20 | // |
|
21 | //QALab: Collects QA Statistics from your build over time. |
|
22 | //2005+, ObjectLab Ltd |
|
23 | // |
|
24 | //This library is free software; you can redistribute it and/or |
|
25 | //modify it under the terms of the GNU General Public |
|
26 | //License as published by the Free Software Foundation; either |
|
27 | //version 2.1 of the License, or (at your option) any later version. |
|
28 | // |
|
29 | //This library is distributed in the hope that it will be useful, |
|
30 | //but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
31 | //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
32 | //General Public License for more details. |
|
33 | // |
|
34 | //You should have received a copy of the GNU General Public |
|
35 | //License along with this library; if not, write to the Free Software |
|
36 | //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
37 | // |
|
38 | //////////////////////////////////////////////////////////////////////////////// |
|
39 | package net.objectlab.qalab.m2.report; |
|
40 | ||
41 | import java.io.File; |
|
42 | import java.io.IOException; |
|
43 | import java.util.Locale; |
|
44 | import java.util.ResourceBundle; |
|
45 | import java.io.FileInputStream; |
|
46 | import java.io.InputStream; |
|
47 | ||
48 | import net.objectlab.qalab.m2.BuildStatMoversMojo; |
|
49 | import net.objectlab.qalab.m2.util.Utils; |
|
50 | import net.objectlab.qalab.m2.util.XmlTransformer; |
|
51 | ||
52 | import org.apache.maven.plugin.MojoExecutionException; |
|
53 | import org.apache.maven.project.MavenProject; |
|
54 | import org.apache.maven.reporting.AbstractMavenReport; |
|
55 | import org.apache.maven.reporting.MavenReportException; |
|
56 | ||
57 | import org.codehaus.doxia.site.renderer.SiteRenderer; |
|
58 | import javax.xml.transform.TransformerException; |
|
59 | ||
60 | /** |
|
61 | * *** IMPORTANT: USE this Report AFTER the merge and chart report, it will calculate the |
|
62 | * movers and generate of the Movers report. |
|
63 | * |
|
64 | * @author Benoit Xhenseval. |
|
65 | * @goal report-movers-all |
|
66 | * @phase deploy |
|
67 | */ |
|
68 | 0 | public class MoversReport extends AbstractMavenReport { |
69 | // ~ Movers COMPUTATION ------------------------------------------------------- |
|
70 | /** |
|
71 | * The qalabFile, typically qalab.xml. |
|
72 | * |
|
73 | * @parameter expression="${project.basedir}/qalab.xml" |
|
74 | */ |
|
75 | 0 | private File qalabFile = null; |
76 | ||
77 | /** |
|
78 | * The number of hours to define the time window from now. |
|
79 | * |
|
80 | * @parameter default-value="54" |
|
81 | */ |
|
82 | 0 | private String startTimeHoursOffset = null; |
83 | ||
84 | /** |
|
85 | * Statistic types to be taken into account |
|
86 | * (checkstyle|findbugs|pmd|simian|pmd-cpd|cobertura-line|cobertura-branch). |
|
87 | * Or comma separated combinations. Default is checkstyle, pmd and findbugs. Please note |
|
88 | * that there is no point of adding pmd-cpd or simian as no statistics are |
|
89 | * kept at file level for those. |
|
90 | * |
|
91 | * @parameter default-value="checkstyle,pmd,findbugs,cobertura-line,cobertura-branch" |
|
92 | */ |
|
93 | 0 | private String types = "checkstyle,pmd,findbugs,cobertura-line,cobertura-branch"; |
94 | ||
95 | /** |
|
96 | * The output XML file with ups and downs. |
|
97 | * |
|
98 | * @parameter expression="${project.build.directory}/qalab/qalab-movers.xml" |
|
99 | */ |
|
100 | private File qalabMoversOutputFile; |
|
101 | ||
102 | /** |
|
103 | * If true then any debug logging output will be suppressed. |
|
104 | * |
|
105 | * @parameter default-value=false |
|
106 | */ |
|
107 | 0 | private boolean quiet = false; |
108 | ||
109 | /** |
|
110 | * if true, adjust for weekend ie add 48h if start time falls on a weekend. |
|
111 | * |
|
112 | * @parameter default-value=true |
|
113 | */ |
|
114 | 0 | private boolean weekendAdjustment = true; |
115 | ||
116 | /** |
|
117 | * Start Time Window (instead of using startTimeHoursOffset). parameter |
|
118 | */ |
|
119 | 0 | private String startTimeWindow = null; |
120 | ||
121 | /** |
|
122 | * End Time Window (instead of assuming "now"). parameter |
|
123 | */ |
|
124 | 0 | private String endTimeWindow = null; |
125 | ||
126 | // ~ Instance fields ------------------------------------------------------- |
|
127 | ||
128 | /** |
|
129 | * The report file name. |
|
130 | * |
|
131 | * @parameter expression="movers.xml" |
|
132 | * @required |
|
133 | */ |
|
134 | private String outputFileName; |
|
135 | ||
136 | /** |
|
137 | * The directory where the generated html report will go. @ parameter |
|
138 | * expression="${project.reporting.outputDirectory}/qalab" |
|
139 | * @parameter expression="${project.build.directory}/generated-site/xdoc" |
|
140 | * @required |
|
141 | */ |
|
142 | private String outputDirectory; |
|
143 | ||
144 | /** |
|
145 | * The xslt stylesheet bundled, either qalab-movers-xdoc.xsl or |
|
146 | * qalab-movers-html.xsl. |
|
147 | * |
|
148 | * @parameter default-value="qalab-movers-xdoc.xsl"; |
|
149 | */ |
|
150 | 0 | private String moversBundledXsl = null; |
151 | ||
152 | /** |
|
153 | * Not sure what this is. |
|
154 | * |
|
155 | * @component |
|
156 | */ |
|
157 | private SiteRenderer siteRenderer; |
|
158 | ||
159 | /** |
|
160 | * The maven project. |
|
161 | * |
|
162 | * @parameter expression="${project}" |
|
163 | * @required |
|
164 | * @readonly |
|
165 | */ |
|
166 | private MavenProject project; |
|
167 | ||
168 | /** |
|
169 | * The xml input stream. |
|
170 | */ |
|
171 | 0 | private InputStream theXmlStream = null; |
172 | ||
173 | /** |
|
174 | * The xslt style sheet. |
|
175 | * |
|
176 | * @parameter |
|
177 | */ |
|
178 | 0 | private File moversStyleSheet = null; |
179 | ||
180 | /** |
|
181 | * The xslt style sheet input stream. |
|
182 | */ |
|
183 | 0 | private InputStream theStyleSheetStream = null; |
184 | ||
185 | /** |
|
186 | * generate the actual report. |
|
187 | * |
|
188 | * @param aLocale |
|
189 | * ignored. |
|
190 | * @throws MavenReportException |
|
191 | * if anything goes wrong. |
|
192 | */ |
|
193 | protected final void executeReport(final Locale aLocale) throws MavenReportException { |
|
194 | 0 | getLog().info("----------------------------------------"); |
195 | 0 | getLog().info("QALab Movers Computation and Report"); |
196 | try { |
|
197 | 0 | doCalculateMovers(); |
198 | 0 | } catch (MojoExecutionException e) { |
199 | 0 | throw new MavenReportException("Issue creating the movers file", e); |
200 | 0 | } |
201 | ||
202 | 0 | validate(); |
203 | ||
204 | 0 | final File outdir = new File(getOutputDirectory()); |
205 | 0 | if (!outdir.exists()) { |
206 | 0 | outdir.mkdirs(); |
207 | } |
|
208 | 0 | assert outdir.isDirectory() : "the output directory was not a directory"; |
209 | ||
210 | final File output; |
|
211 | try { |
|
212 | 0 | output = new File(outdir, outputFileName); |
213 | 0 | output.createNewFile(); |
214 | 0 | } catch (IOException ioex) { |
215 | 0 | throw new MavenReportException("could not create output file.", ioex); |
216 | 0 | } |
217 | ||
218 | 0 | final XmlTransformer t = new XmlTransformer(theXmlStream, theStyleSheetStream, output); |
219 | try { |
|
220 | 0 | t.transform(); |
221 | 0 | } catch (TransformerException tex) { |
222 | 0 | throw new MavenReportException("transformation failed.", tex); |
223 | 0 | } |
224 | ||
225 | 0 | } |
226 | ||
227 | private void doCalculateMovers() throws MojoExecutionException { |
|
228 | 0 | BuildStatMoversMojo mojo = new BuildStatMoversMojo(); |
229 | 0 | mojo.setEndTimeWindow(endTimeWindow); |
230 | 0 | mojo.setQalabFile(qalabFile); |
231 | 0 | mojo.setQalabMoversOutputFile(qalabMoversOutputFile); |
232 | 0 | mojo.setQuiet(quiet); |
233 | 0 | mojo.setStartTimeHoursOffset(startTimeHoursOffset); |
234 | 0 | mojo.setStartTimeWindow(startTimeWindow); |
235 | 0 | mojo.setTypes(types); |
236 | 0 | mojo.setWeekendAdjustment(weekendAdjustment); |
237 | 0 | mojo.setPluginContext(getPluginContext()); |
238 | ||
239 | 0 | mojo.execute(); |
240 | 0 | } |
241 | ||
242 | /** |
|
243 | * @return "outputFileName up to the first '.'" |
|
244 | * @see org.apache.maven.reporting.MavenReport#getOutputName() |
|
245 | */ |
|
246 | public final String getOutputName() { |
|
247 | // return "movers"; |
|
248 | 0 | return outputFileName.substring(0, outputFileName.indexOf('.')); |
249 | } |
|
250 | ||
251 | /** |
|
252 | * @return The output directory as configured in your <code>pom.xml</code>. |
|
253 | * @see org.apache.maven.reporting.AbstractMavenReport#getOutputDirectory() |
|
254 | */ |
|
255 | protected final String getOutputDirectory() { |
|
256 | 0 | return outputDirectory; |
257 | } |
|
258 | ||
259 | /** |
|
260 | * @return The Maven Project itself. Used internally to get access to Config |
|
261 | * params etc. |
|
262 | * @see org.apache.maven.reporting.AbstractMavenReport#getProject() |
|
263 | */ |
|
264 | protected final MavenProject getProject() { |
|
265 | 0 | return project; |
266 | } |
|
267 | ||
268 | /** |
|
269 | * @return a direct reference to the site renderer. |
|
270 | * @see org.apache.maven.reporting.AbstractMavenReport#getSiteRenderer() |
|
271 | */ |
|
272 | protected final SiteRenderer getSiteRenderer() { |
|
273 | 0 | return siteRenderer; |
274 | } |
|
275 | ||
276 | /** |
|
277 | * @param aLocale |
|
278 | * The locale. |
|
279 | * @return The locale specific report name. |
|
280 | * @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale) |
|
281 | */ |
|
282 | public final String getName(final Locale aLocale) { |
|
283 | 0 | return getBundle(aLocale).getString("report.qalab.movers.name"); |
284 | } |
|
285 | ||
286 | /** |
|
287 | * @param aLocale |
|
288 | * The locale. |
|
289 | * @return The locale specific report description. |
|
290 | * @see org.apache.maven.reporting.MavenReport#getDescription(java.util.Locale) |
|
291 | */ |
|
292 | public final String getDescription(final Locale aLocale) { |
|
293 | 0 | return getBundle(aLocale).getString("report.qalab.movers.description"); |
294 | } |
|
295 | ||
296 | /** |
|
297 | * @return true. |
|
298 | * @see org.apache.maven.reporting.MavenReport#isExternalReport |
|
299 | */ |
|
300 | public final boolean isExternalReport() { |
|
301 | 0 | return true; |
302 | } |
|
303 | ||
304 | /** |
|
305 | * @param aLocale |
|
306 | * The locale. |
|
307 | * @return the resource bundle for this report. |
|
308 | */ |
|
309 | private static ResourceBundle getBundle(final Locale aLocale) { |
|
310 | 0 | return ResourceBundle.getBundle("qalab-report", aLocale, MainReport.class.getClassLoader()); |
311 | } |
|
312 | ||
313 | /** |
|
314 | * Validates the parameters supplied by maven 2. |
|
315 | * |
|
316 | * @throws MavenReportException |
|
317 | * if any supplied params are wrong. |
|
318 | */ |
|
319 | private void validate() throws MavenReportException { |
|
320 | try { |
|
321 | 0 | Utils.checkFile(qalabMoversOutputFile, "inputMoversFile"); |
322 | 0 | theXmlStream = new FileInputStream(qalabMoversOutputFile); |
323 | 0 | } catch (IOException ioex) { |
324 | 0 | throw new MavenReportException(ioex.getMessage(), ioex); |
325 | 0 | } |
326 | ||
327 | 0 | if (moversStyleSheet == null) { |
328 | try { |
|
329 | 0 | theStyleSheetStream = Utils.extractAsInputStream(moversBundledXsl); |
330 | 0 | } catch (IOException ioex) { |
331 | 0 | throw new MavenReportException("Could not find the default stylesheet. " + ioex.getMessage(), ioex); |
332 | 0 | } |
333 | } else { |
|
334 | try { |
|
335 | 0 | Utils.checkFile(moversStyleSheet, "moversStyleSheet"); |
336 | 0 | theStyleSheetStream = new FileInputStream(moversStyleSheet); |
337 | 0 | } catch (IOException ioex) { |
338 | 0 | throw new MavenReportException(ioex.getMessage(), ioex); |
339 | 0 | } |
340 | } |
|
341 | 0 | } |
342 | } |
|
343 | /* |
|
344 | * ObjectLab is sponsoring QALab |
|
345 | * |
|
346 | * Based in London, we are world leaders in the design and development |
|
347 | * of bespoke applications for the securities financing markets. |
|
348 | * |
|
349 | * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a> |
|
350 | * ___ _ _ _ _ _ |
|
351 | * / _ \| |__ (_) ___ ___| |_| | __ _| |__ |
|
352 | * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ |
|
353 | * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | |
|
354 | * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ |
|
355 | * |__/ |
|
356 | * |
|
357 | * www.ObjectLab.co.uk |
|
358 | */ |