View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.checkstyle;
20  
21  import java.util.List;
22  
23  import org.apache.maven.plugins.annotations.Mojo;
24  import org.apache.maven.plugins.annotations.Parameter;
25  import org.apache.maven.plugins.annotations.ResolutionScope;
26  import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorRequest;
27  import org.apache.maven.project.MavenProject;
28  import org.apache.maven.reporting.MavenReportException;
29  
30  /**
31   * A reporting task that performs Checkstyle analysis and generates an aggregate
32   * HTML report on the violations that Checkstyle finds in a multi-module reactor
33   * build.
34   *
35   *
36   */
37  @Mojo(
38          name = "checkstyle-aggregate",
39          aggregator = true,
40          requiresDependencyResolution = ResolutionScope.COMPILE,
41          threadSafe = true)
42  public class CheckstyleAggregateReport extends AbstractCheckstyleReport {
43      /**
44       * The projects in the reactor for aggregation report.
45       *
46       * @since 2.8
47       */
48      @Parameter(property = "reactorProjects", readonly = true)
49      private List<MavenProject> reactorProjects;
50  
51      /** {@inheritDoc} */
52      protected MavenProject getProject() {
53          return project;
54      }
55  
56      /**
57       * {@inheritDoc}
58       */
59      protected CheckstyleExecutorRequest createRequest() throws MavenReportException {
60          CheckstyleExecutorRequest request = new CheckstyleExecutorRequest();
61          request.setAggregate(true)
62                  .setReactorProjects(reactorProjects)
63                  .setConsoleListener(getConsoleListener())
64                  .setConsoleOutput(consoleOutput)
65                  .setExcludes(excludes)
66                  .setFailsOnError(failsOnError)
67                  .setIncludes(includes)
68                  .setResourceIncludes(resourceIncludes)
69                  .setResourceExcludes(resourceExcludes)
70                  .setIncludeResources(includeResources)
71                  .setIncludeTestResources(includeTestResources)
72                  .setIncludeTestSourceDirectory(includeTestSourceDirectory)
73                  .setListener(getListener())
74                  .setProject(project)
75                  .setSourceDirectories(getSourceDirectories())
76                  .setResources(resources)
77                  .setTestResources(testResources)
78                  .setStringOutputStream(stringOutputStream)
79                  .setSuppressionsLocation(suppressionsLocation)
80                  .setTestSourceDirectories(getTestSourceDirectories())
81                  .setPropertyExpansion(propertyExpansion)
82                  .setHeaderLocation(headerLocation)
83                  .setCacheFile(cacheFile)
84                  .setSuppressionsFileExpression(suppressionsFileExpression)
85                  .setEncoding(getInputEncoding())
86                  .setPropertiesLocation(propertiesLocation);
87          return request;
88      }
89  
90      /** {@inheritDoc} */
91      public String getOutputName() {
92          return "checkstyle-aggregate";
93      }
94  
95      /** {@inheritDoc} */
96      public boolean canGenerateReport() {
97          // TODO: would be good to scan the files here
98          return !skip && project.isExecutionRoot() && reactorProjects.size() > 1;
99      }
100 }