Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
MainReport |
|
| 2.2;2.2 |
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.util.Utils; |
|
49 | import net.objectlab.qalab.m2.util.XmlTransformer; |
|
50 | ||
51 | import org.apache.maven.project.MavenProject; |
|
52 | import org.apache.maven.reporting.AbstractMavenReport; |
|
53 | import org.apache.maven.reporting.MavenReportException; |
|
54 | ||
55 | import org.codehaus.doxia.site.renderer.SiteRenderer; |
|
56 | import javax.xml.transform.TransformerException; |
|
57 | ||
58 | /** |
|
59 | * Goal that handles the generation of a site report based on the data in the |
|
60 | * qalab.xml file. |
|
61 | * |
|
62 | * @author Dave Sag and Benoit Xhenseval. |
|
63 | * @goal report |
|
64 | * @phase deploy |
|
65 | */ |
|
66 | 0 | public class MainReport extends AbstractMavenReport { |
67 | ||
68 | // ~ Instance fields ------------------------------------------------------- |
|
69 | /** |
|
70 | * The generated qalab.xml file. |
|
71 | * |
|
72 | * @parameter expression="${project.basedir}/qalab.xml" |
|
73 | */ |
|
74 | 0 | private File inputFile = null; |
75 | ||
76 | /** |
|
77 | * The xslt stylesheet bundled, either qalab-chart-xdoc.xsl or |
|
78 | * qalab-chart-html.xsl. |
|
79 | * |
|
80 | * @parameter default-value="qalab-chart-xdoc.xsl"; |
|
81 | */ |
|
82 | 0 | private String moversBundledXsl = null; |
83 | ||
84 | /** |
|
85 | * The directory where the generated html report will go. @ parameter |
|
86 | * expression="${project.reporting.outputDirectory}/qalab" |
|
87 | * @parameter expression="${project.build.directory}/generated-site/xdoc/qalab" |
|
88 | * @required |
|
89 | */ |
|
90 | private String outputDirectory; |
|
91 | ||
92 | /** |
|
93 | * Statistic types, defaulted to |
|
94 | * 'checkstyle,pmd,pmd-cpd,findbugs,simian,cobertura-line,cobertura-branch'. |
|
95 | * |
|
96 | * @parameter default-value="checkstyle,pmd,pmd-cpd,findbugs,simian,cobertura-line,cobertura-branch" |
|
97 | */ |
|
98 | 0 | private String types = "checkstyle,pmd,pmd-cpd,findbugs,simian,cobertura-line,cobertura-branch"; |
99 | ||
100 | /** |
|
101 | * The xml input stream. |
|
102 | */ |
|
103 | 0 | private InputStream theXmlStream = null; |
104 | ||
105 | /** |
|
106 | * The xslt style sheet. |
|
107 | * |
|
108 | * @parameter |
|
109 | */ |
|
110 | 0 | private File styleSheet = null; |
111 | ||
112 | /** |
|
113 | * The xslt style sheet input stream. |
|
114 | */ |
|
115 | 0 | private InputStream theStyleSheetStream = null; |
116 | ||
117 | /** |
|
118 | * The number of hours to define the time window from now. |
|
119 | * |
|
120 | * @parameter default-value="48" |
|
121 | */ |
|
122 | 0 | private String startTimeHoursOffset = "48"; |
123 | ||
124 | /** |
|
125 | * The string version of the actual date computed by the offset set above. |
|
126 | */ |
|
127 | private String theOffset; |
|
128 | ||
129 | /** |
|
130 | * Not sure what this is. |
|
131 | * |
|
132 | * @component |
|
133 | */ |
|
134 | private SiteRenderer siteRenderer; |
|
135 | ||
136 | /** |
|
137 | * The maven project. |
|
138 | * |
|
139 | * @parameter expression="${project}" |
|
140 | * @required |
|
141 | * @readonly |
|
142 | */ |
|
143 | private MavenProject project; |
|
144 | ||
145 | /** |
|
146 | * generate the actual report. |
|
147 | * |
|
148 | * @param aLocale |
|
149 | * ignored. |
|
150 | * @throws MavenReportException |
|
151 | * if anything goes wrong. |
|
152 | */ |
|
153 | protected final void executeReport(final Locale aLocale) throws MavenReportException { |
|
154 | ||
155 | 0 | validate(); |
156 | 0 | final File outdir = new File(getOutputDirectory()); |
157 | 0 | if (!outdir.exists()) { |
158 | 0 | outdir.mkdirs(); |
159 | } |
|
160 | 0 | assert outdir.isDirectory() : "the output directory was not a directory"; |
161 | ||
162 | final File output; |
|
163 | try { |
|
164 | 0 | output = File.createTempFile("qalab", null, outdir); |
165 | 0 | assert output != null : "the temp file is null."; |
166 | ||
167 | 0 | } catch (IOException ioex) { |
168 | 0 | throw new MavenReportException("could not create temp file.", ioex); |
169 | 0 | } |
170 | ||
171 | 0 | final XmlTransformer t = new XmlTransformer(theXmlStream, theStyleSheetStream, output); |
172 | 0 | t.addParameter("targetdir", getOutputDirectory()); |
173 | 0 | t.addParameter("type", types); |
174 | 0 | t.addParameter("offset", theOffset); |
175 | try { |
|
176 | 0 | t.transform(); |
177 | 0 | } catch (TransformerException tex) { |
178 | 0 | throw new MavenReportException("transformation failed.", tex); |
179 | 0 | } |
180 | ||
181 | // clean up the temp file when the plugin is done. |
|
182 | 0 | output.deleteOnExit(); |
183 | 0 | } |
184 | ||
185 | /** |
|
186 | * @return "qalab/index" |
|
187 | * @see org.apache.maven.reporting.MavenReport#getOutputName() |
|
188 | */ |
|
189 | public final String getOutputName() { |
|
190 | 0 | return "qalab/index"; |
191 | } |
|
192 | ||
193 | /** |
|
194 | * @return The output directory as configured in your <code>pom.xml</code>. |
|
195 | * @see org.apache.maven.reporting.AbstractMavenReport#getOutputDirectory() |
|
196 | */ |
|
197 | protected final String getOutputDirectory() { |
|
198 | 0 | return outputDirectory; |
199 | } |
|
200 | ||
201 | /** |
|
202 | * @return The Maven Project itself. Used internally to get access to Config |
|
203 | * params etc. |
|
204 | * @see org.apache.maven.reporting.AbstractMavenReport#getProject() |
|
205 | */ |
|
206 | protected final MavenProject getProject() { |
|
207 | 0 | return project; |
208 | } |
|
209 | ||
210 | /** |
|
211 | * @return a direct reference to the site renderer. |
|
212 | * @see org.apache.maven.reporting.AbstractMavenReport#getSiteRenderer() |
|
213 | */ |
|
214 | protected final SiteRenderer getSiteRenderer() { |
|
215 | 0 | return siteRenderer; |
216 | } |
|
217 | ||
218 | /** |
|
219 | * @param aLocale |
|
220 | * The locale. |
|
221 | * @return The locale specific report name. |
|
222 | * @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale) |
|
223 | */ |
|
224 | public final String getName(final Locale aLocale) { |
|
225 | 0 | return getBundle(aLocale).getString("report.qalab.name"); |
226 | } |
|
227 | ||
228 | /** |
|
229 | * @param aLocale |
|
230 | * The locale. |
|
231 | * @return The locale specific report description. |
|
232 | * @see org.apache.maven.reporting.MavenReport#getDescription(java.util.Locale) |
|
233 | */ |
|
234 | public final String getDescription(final Locale aLocale) { |
|
235 | 0 | return getBundle(aLocale).getString("report.qalab.description"); |
236 | } |
|
237 | ||
238 | /** |
|
239 | * @return true. |
|
240 | * @see org.apache.maven.reporting.MavenReport#isExternalReport |
|
241 | */ |
|
242 | public final boolean isExternalReport() { |
|
243 | 0 | return true; |
244 | } |
|
245 | ||
246 | /** |
|
247 | * @param aLocale |
|
248 | * The locale. |
|
249 | * @return the resource bundle for this report. |
|
250 | */ |
|
251 | private static ResourceBundle getBundle(final Locale aLocale) { |
|
252 | 0 | return ResourceBundle.getBundle("qalab-report", aLocale, MainReport.class.getClassLoader()); |
253 | } |
|
254 | ||
255 | /** |
|
256 | * Validates the parameters supplied by maven 2. |
|
257 | * |
|
258 | * @throws MavenReportException |
|
259 | * if any supplied params are wrong. |
|
260 | */ |
|
261 | private void validate() throws MavenReportException { |
|
262 | try { |
|
263 | 0 | Utils.checkFile(inputFile, "inputFile"); |
264 | 0 | theXmlStream = new FileInputStream(inputFile); |
265 | 0 | } catch (IOException ioex) { |
266 | 0 | throw new MavenReportException(ioex.getMessage(), ioex); |
267 | 0 | } |
268 | ||
269 | 0 | if (styleSheet == null) { |
270 | try { |
|
271 | 0 | theStyleSheetStream = Utils.extractAsInputStream(moversBundledXsl); |
272 | 0 | } catch (IOException ioex) { |
273 | 0 | throw new MavenReportException("Could not find the default stylesheet. " + ioex.getMessage(), ioex); |
274 | 0 | } |
275 | } else { |
|
276 | try { |
|
277 | 0 | Utils.checkFile(styleSheet, "styleSheet"); |
278 | 0 | theStyleSheetStream = new FileInputStream(styleSheet); |
279 | 0 | } catch (IOException ioex) { |
280 | 0 | throw new MavenReportException(ioex.getMessage(), ioex); |
281 | 0 | } |
282 | } |
|
283 | ||
284 | 0 | theOffset = Utils.formatDateBasedOnOffset(startTimeHoursOffset); |
285 | ||
286 | 0 | } |
287 | } |
|
288 | /* |
|
289 | * ObjectLab is sponsoring QALab |
|
290 | * |
|
291 | * Based in London, we are world leaders in the design and development |
|
292 | * of bespoke applications for the securities financing markets. |
|
293 | * |
|
294 | * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a> |
|
295 | * ___ _ _ _ _ _ |
|
296 | * / _ \| |__ (_) ___ ___| |_| | __ _| |__ |
|
297 | * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ |
|
298 | * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | |
|
299 | * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ |
|
300 | * |__/ |
|
301 | * |
|
302 | * www.ObjectLab.co.uk |
|
303 | */ |