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.java 1618905 2014-08-19 17:23:18Z rfscholte $
37   * @since 2.8
38   */
39  @Mojo( name = "checkstyle-aggregate", aggregator = true, requiresDependencyResolution = ResolutionScope.COMPILE,
40         threadSafe = true )
41  public class CheckstyleAggregateReport
42      extends AbstractCheckstyleReport
43  {
44      /**
45       * The projects in the reactor for aggregation report.
46       *
47       * @since 2.8
48       */
49      @Parameter( property = "reactorProjects", readonly = true )
50      private List<MavenProject> reactorProjects;
51  
52      /** {@inheritDoc} */
53      protected MavenProject getProject()
54      {
55          return project;
56      }
57  
58      /**
59       * {@inheritDoc}
60       */
61      protected CheckstyleExecutorRequest createRequest()
62              throws MavenReportException
63      {
64          CheckstyleExecutorRequest request = new CheckstyleExecutorRequest();
65          request.setAggregate( true )
66              .setReactorProjects( reactorProjects )
67              .setConsoleListener( getConsoleListener() ).setConsoleOutput( consoleOutput )
68              .setExcludes( excludes ).setFailsOnError( failsOnError ).setIncludes( includes )
69              .setIncludeResources( includeResources )
70              .setIncludeTestResources( includeTestResources )
71              .setResourceIncludes( resourceIncludes )
72              .setResourceExcludes( resourceExcludes )
73              .setIncludeTestSourceDirectory( includeTestSourceDirectory ).setListener( getListener() )
74              .setLog( getLog() ).setProject( project ).setSourceDirectories( getSourceDirectories() ).setResources( resources )
75              .setTestResources( testResources )
76              .setStringOutputStream( stringOutputStream ).setSuppressionsLocation( suppressionsLocation )
77              .setTestSourceDirectories( getTestSourceDirectories() ).setConfigLocation( configLocation )
78              .setPropertyExpansion( propertyExpansion ).setHeaderLocation( headerLocation )
79              .setCacheFile( cacheFile ).setSuppressionsFileExpression( suppressionsFileExpression )
80              .setEncoding( encoding ).setPropertiesLocation( propertiesLocation );
81          return request;
82      }
83  
84  
85      /** {@inheritDoc} */
86      public String getOutputName()
87      {
88          return "checkstyle-aggregate";
89      }
90  
91      /** {@inheritDoc} */
92      public boolean canGenerateReport()
93      {
94          // TODO: would be good to scan the files here
95          return !skip && project.isExecutionRoot() && reactorProjects.size() > 1;
96      }
97  }