View Javadoc
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 org.apache.maven.plugin.checkstyle.exec.CheckstyleExecutorRequest;
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.project.MavenProject;
27  import org.apache.maven.reporting.MavenReportException;
28  
29  import java.util.List;
30  
31  /**
32   * A reporting task that performs Checkstyle analysis and generates an aggregate
33   * HTML report on the violations that Checkstyle finds in a multi-module reactor
34   * build.
35   *
36   * @version $Id: CheckstyleAggregateReport.html 959038 2015-07-20 17:14:24Z dennisl $
37   */
38  @Mojo( name = "checkstyle-aggregate", aggregator = true, requiresDependencyResolution = ResolutionScope.COMPILE,
39         threadSafe = true )
40  public class CheckstyleAggregateReport
41      extends AbstractCheckstyleReport
42  {
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      {
54          return project;
55      }
56  
57      /**
58       * {@inheritDoc}
59       */
60      protected CheckstyleExecutorRequest createRequest()
61              throws MavenReportException
62      {
63          CheckstyleExecutorRequest request = new CheckstyleExecutorRequest();
64          request.setAggregate( true )
65              .setReactorProjects( reactorProjects )
66              .setConsoleListener( getConsoleListener() ).setConsoleOutput( consoleOutput )
67              .setExcludes( excludes ).setFailsOnError( failsOnError ).setIncludes( includes )
68              .setIncludeResources( includeResources )
69              .setIncludeTestResources( includeTestResources )
70              .setResourceIncludes( resourceIncludes )
71              .setResourceExcludes( resourceExcludes )
72              .setIncludeTestSourceDirectory( includeTestSourceDirectory ).setListener( getListener() )
73              .setProject( project ).setSourceDirectories( getSourceDirectories() )
74              .setResources( resources ).setTestResources( testResources )
75              .setStringOutputStream( stringOutputStream ).setSuppressionsLocation( suppressionsLocation )
76              .setTestSourceDirectories( getTestSourceDirectories() ).setConfigLocation( configLocation )
77              .setPropertyExpansion( propertyExpansion ).setHeaderLocation( headerLocation )
78              .setCacheFile( cacheFile ).setSuppressionsFileExpression( suppressionsFileExpression )
79              .setEncoding( encoding ).setPropertiesLocation( propertiesLocation );
80          return request;
81      }
82  
83  
84      /** {@inheritDoc} */
85      public String getOutputName()
86      {
87          return "checkstyle-aggregate";
88      }
89  
90      /** {@inheritDoc} */
91      public boolean canGenerateReport()
92      {
93          // TODO: would be good to scan the files here
94          return !skip && project.isExecutionRoot() && reactorProjects.size() > 1;
95      }
96  }