Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CheckstyleAggregateReport |
|
| 1.25;1,25 |
1 | package org.apache.maven.plugin.checkstyle; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import java.io.File; | |
23 | import java.util.List; | |
24 | ||
25 | import org.apache.maven.project.MavenProject; | |
26 | import org.apache.maven.reporting.MavenReportException; | |
27 | ||
28 | /** | |
29 | * Perform a Checkstyle analysis, and generate a report on violations, | |
30 | * aggregating the result in the project which started this mojo. | |
31 | * | |
32 | * @version $Id$ | |
33 | * @goal checkstyle-aggregate | |
34 | * @aggregator | |
35 | * @requiresDependencyResolution compile | |
36 | * @threadSafe | |
37 | * @since 2.8 | |
38 | */ | |
39 | 1 | public class CheckstyleAggregateReport |
40 | extends AbstractCheckstyleReport | |
41 | { | |
42 | ||
43 | /** | |
44 | * Specifies the names filter of the source files to be used for Checkstyle. | |
45 | * | |
46 | * @parameter expression="${checkstyle.includes}" default-value="**\/*.java" | |
47 | * @required | |
48 | */ | |
49 | private String includes; | |
50 | ||
51 | /** | |
52 | * Specifies the names filter of the source files to be excluded for | |
53 | * Checkstyle. | |
54 | * | |
55 | * @parameter expression="${checkstyle.excludes}" | |
56 | */ | |
57 | private String excludes; | |
58 | ||
59 | /** | |
60 | * <p> | |
61 | * Specifies the location of the XML configuration to use. | |
62 | * </p> | |
63 | * | |
64 | * <p> | |
65 | * Potential values are a filesystem path, a URL, or a classpath resource. | |
66 | * This parameter expects that the contents of the location conform to the | |
67 | * xml format (Checkstyle <a | |
68 | * href="http://checkstyle.sourceforge.net/config.html#Modules">Checker | |
69 | * module</a>) configuration of rulesets. | |
70 | * </p> | |
71 | * | |
72 | * <p> | |
73 | * This parameter is resolved as resource, URL, then file. If successfully | |
74 | * resolved, the contents of the configuration is copied into the | |
75 | * <code>${project.build.directory}/checkstyle-configuration.xml</code> | |
76 | * file before being passed to Checkstyle as a configuration. | |
77 | * </p> | |
78 | * | |
79 | * <p> | |
80 | * There are 4 predefined rulesets. | |
81 | * </p> | |
82 | * | |
83 | * <ul> | |
84 | * <li><code>config/sun_checks.xml</code>: Sun Checks.</li> | |
85 | * <li><code>config/turbine_checks.xml</code>: Turbine Checks.</li> | |
86 | * <li><code>config/avalon_checks.xml</code>: Avalon Checks.</li> | |
87 | * <li><code>config/maven_checks.xml</code>: Maven Source Checks.</li> | |
88 | * </ul> | |
89 | * | |
90 | * @parameter expression="${checkstyle.config.location}" | |
91 | * default-value="config/sun_checks.xml" | |
92 | */ | |
93 | private String configLocation; | |
94 | ||
95 | /** | |
96 | * <p> | |
97 | * Specifies the location of the properties file. | |
98 | * </p> | |
99 | * | |
100 | * <p> | |
101 | * This parameter is resolved as URL, File then resource. If successfully | |
102 | * resolved, the contents of the properties location is copied into the | |
103 | * <code>${project.build.directory}/checkstyle-checker.properties</code> | |
104 | * file before being passed to Checkstyle for loading. | |
105 | * </p> | |
106 | * | |
107 | * <p> | |
108 | * The contents of the <code>propertiesLocation</code> will be made | |
109 | * available to Checkstyle for specifying values for parameters within the | |
110 | * xml configuration (specified in the <code>configLocation</code> | |
111 | * parameter). | |
112 | * </p> | |
113 | * | |
114 | * @parameter expression="${checkstyle.properties.location}" | |
115 | * @since 2.0-beta-2 | |
116 | */ | |
117 | private String propertiesLocation; | |
118 | ||
119 | /** | |
120 | * Allows for specifying raw property expansion information. | |
121 | * | |
122 | * @parameter | |
123 | */ | |
124 | private String propertyExpansion; | |
125 | ||
126 | /** | |
127 | * <p> | |
128 | * Specifies the location of the License file (a.k.a. the header file) that | |
129 | * can be used by Checkstyle to verify that source code has the correct | |
130 | * license header. | |
131 | * </p> | |
132 | * <p> | |
133 | * You need to use ${checkstyle.header.file} in your Checkstyle xml | |
134 | * configuration to reference the name of this header file. | |
135 | * </p> | |
136 | * <p> | |
137 | * For instance: | |
138 | * </p> | |
139 | * <p> | |
140 | * <code> | |
141 | * <module name="RegexpHeader"> | |
142 | * <property name="headerFile" value="${checkstyle.header.file}"/> | |
143 | * </module> | |
144 | * </code> | |
145 | * </p> | |
146 | * | |
147 | * @parameter expression="${checkstyle.header.file}" default-value="LICENSE.txt" | |
148 | * @since 2.0-beta-2 | |
149 | */ | |
150 | private String headerLocation; | |
151 | ||
152 | /** | |
153 | * Specifies the cache file used to speed up Checkstyle on successive runs. | |
154 | * | |
155 | * @parameter default-value="${project.build.directory}/checkstyle-cachefile" | |
156 | */ | |
157 | private String cacheFile; | |
158 | ||
159 | /** | |
160 | * <p> | |
161 | * Specifies the location of the suppressions XML file to use. | |
162 | * </p> | |
163 | * | |
164 | * <p> | |
165 | * This parameter is resolved as resource, URL, then file. If successfully | |
166 | * resolved, the contents of the suppressions XML is copied into the | |
167 | * <code>${project.build.directory}/checkstyle-supressions.xml</code> file | |
168 | * before being passed to Checkstyle for loading. | |
169 | * </p> | |
170 | * | |
171 | * <p> | |
172 | * See <code>suppressionsFileExpression</code> for the property that will | |
173 | * be made available to your checkstyle configuration. | |
174 | * </p> | |
175 | * | |
176 | * @parameter expression="${checkstyle.suppressions.location}" | |
177 | * @since 2.0-beta-2 | |
178 | */ | |
179 | private String suppressionsLocation; | |
180 | ||
181 | /** | |
182 | * The key to be used in the properties for the suppressions file. | |
183 | * | |
184 | * @parameter expression="${checkstyle.suppression.expression}" | |
185 | * default-value="checkstyle.suppressions.file" | |
186 | * @since 2.1 | |
187 | */ | |
188 | private String suppressionsFileExpression; | |
189 | ||
190 | /** | |
191 | * Specifies if the build should fail upon a violation. | |
192 | * | |
193 | * @parameter default-value="false" | |
194 | */ | |
195 | private boolean failsOnError; | |
196 | ||
197 | /** | |
198 | * Specifies the location of the source directory to be used for Checkstyle. | |
199 | * | |
200 | * @parameter default-value="${project.build.sourceDirectory}" | |
201 | * @required | |
202 | */ | |
203 | private File sourceDirectory; | |
204 | ||
205 | /** | |
206 | * Specifies the location of the test source directory to be used for | |
207 | * Checkstyle. | |
208 | * | |
209 | * @parameter default-value="${project.build.testSourceDirectory}" | |
210 | * @since 2.2 | |
211 | */ | |
212 | private File testSourceDirectory; | |
213 | ||
214 | /** | |
215 | * Include or not the test source directory to be used for Checkstyle. | |
216 | * | |
217 | * @parameter default-value="${false}" | |
218 | * @since 2.2 | |
219 | */ | |
220 | private boolean includeTestSourceDirectory; | |
221 | ||
222 | /** | |
223 | * Output errors to console. | |
224 | * | |
225 | * @parameter default-value="false" | |
226 | */ | |
227 | private boolean consoleOutput; | |
228 | ||
229 | /** | |
230 | * The file encoding to use when reading the source files. If the property <code>project.build.sourceEncoding</code> | |
231 | * is not set, the platform default encoding is used. <strong>Note:</strong> This parameter always overrides the | |
232 | * property <code>charset</code> from Checkstyle's <code>TreeWalker</code> module. | |
233 | * | |
234 | * @parameter expression="${encoding}" default-value="${project.build.sourceEncoding}" | |
235 | * @since 2.2 | |
236 | */ | |
237 | private String encoding; | |
238 | ||
239 | /** | |
240 | * The projects in the reactor for aggregation report. | |
241 | * | |
242 | * @parameter expression="${reactorProjects}" | |
243 | * @readonly | |
244 | * @since 2.8 | |
245 | */ | |
246 | private List<MavenProject> reactorProjects; | |
247 | ||
248 | /** {@inheritDoc} */ | |
249 | protected MavenProject getProject() | |
250 | { | |
251 | 2 | return project; |
252 | } | |
253 | ||
254 | /** | |
255 | * {@inheritDoc} | |
256 | */ | |
257 | protected CheckstyleExecutorRequest createRequest() | |
258 | throws MavenReportException | |
259 | { | |
260 | 2 | CheckstyleExecutorRequest request = new CheckstyleExecutorRequest(); |
261 | 2 | request.setAggregate( true ) |
262 | .setReactorProjects( reactorProjects ) | |
263 | .setConsoleListener( getConsoleListener() ).setConsoleOutput( consoleOutput ) | |
264 | .setExcludes( excludes ).setFailsOnError( failsOnError ).setIncludes( includes ) | |
265 | .setIncludeTestSourceDirectory( includeTestSourceDirectory ).setListener( getListener() ) | |
266 | .setLog( getLog() ).setProject( project ).setSourceDirectory( sourceDirectory ) | |
267 | .setStringOutputStream( stringOutputStream ).setSuppressionsLocation( suppressionsLocation ) | |
268 | .setTestSourceDirectory( testSourceDirectory ).setConfigLocation( configLocation ) | |
269 | .setPropertyExpansion( propertyExpansion ).setHeaderLocation( headerLocation ) | |
270 | .setCacheFile( cacheFile ).setSuppressionsFileExpression( suppressionsFileExpression ) | |
271 | .setEncoding( encoding ).setPropertiesLocation( propertiesLocation ); | |
272 | 2 | return request; |
273 | } | |
274 | ||
275 | ||
276 | /** {@inheritDoc} */ | |
277 | public String getOutputName() | |
278 | { | |
279 | 3 | return "checkstyle-aggregate"; |
280 | } | |
281 | ||
282 | /** {@inheritDoc} */ | |
283 | public boolean canGenerateReport() | |
284 | { | |
285 | // TODO: would be good to scan the files here | |
286 | 4 | return !skip && project.isExecutionRoot(); |
287 | } | |
288 | } |