View Javadoc
1   package org.apache.maven.plugins.surefire.report;
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 org.apache.maven.plugins.annotations.Execute;
24  import org.apache.maven.plugins.annotations.LifecyclePhase;
25  import org.apache.maven.plugins.annotations.Mojo;
26  import org.apache.maven.plugins.annotations.Parameter;
27  import org.apache.maven.project.MavenProject;
28  
29  
30  /**
31   * Creates a nicely formatted Surefire Test Report in html format.
32   *
33   * @author <a href="mailto:jruiz@exist.com">Johnny R. Ruiz III</a>
34   */
35  @Mojo( name = "report", inheritByDefault = false )
36  @Execute( lifecycle = "surefire", phase = LifecyclePhase.TEST )
37  public class SurefireReportMojo
38      extends AbstractSurefireReportMojo
39  {
40  
41      /**
42       * The filename to use for the report.
43       */
44      @Parameter( defaultValue = "surefire-report", property = "outputName", required = true )
45      private String outputName;
46  
47      /**
48       * If set to true the surefire report will be generated even when there are no surefire result files.
49       * Defaults to {@code true} to preserve legacy behaviour pre 2.10.
50       * @since 2.11
51       */
52      @Parameter( defaultValue = "true", property = "alwaysGenerateSurefireReport" )
53      private boolean alwaysGenerateSurefireReport;
54  
55      /**
56       * If set to true the surefire report generation will be skipped.
57       * @since 2.11
58       */
59      @Parameter( defaultValue = "false", property = "skipSurefireReport" )
60      private boolean skipSurefireReport;
61  
62      @Override
63      protected File getSurefireReportsDirectory( MavenProject subProject )
64      {
65          String buildDir = subProject.getBuild().getDirectory();
66          return new File( buildDir + "/surefire-reports" );
67      }
68  
69      @Override
70      public String getOutputName()
71      {
72          return outputName;
73      }
74  
75      @Override
76      protected boolean isSkipped()
77      {
78          return skipSurefireReport;
79      }
80  
81      @Override
82      protected boolean isGeneratedWhenNoResults()
83      {
84          return alwaysGenerateSurefireReport;
85      }
86  }