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   * Creates a nicely formatted Surefire Test Report in html format.
31   *
32   * @author <a href="mailto:jruiz@exist.com">Johnny R. Ruiz III</a>
33   */
34  @Mojo( name = "report", inheritByDefault = false )
35  @Execute( lifecycle = "surefire", phase = LifecyclePhase.TEST )
36  @SuppressWarnings( "unused" )
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      /**
63       * A custom title of the report for the menu and the project reports page.
64       * @since 2.21.0
65       */
66      @Parameter( defaultValue = "", property = "surefire.report.title" )
67      private String title;
68  
69      /**
70       * A custom description for the project reports page.
71       * @since 2.21.0
72       */
73      @Parameter( defaultValue = "", property = "surefire.report.description" )
74      private String description;
75  
76      @Override
77      protected File getSurefireReportsDirectory( MavenProject subProject )
78      {
79          String buildDir = subProject.getBuild().getDirectory();
80          return new File( buildDir + "/surefire-reports" );
81      }
82  
83      @Override
84      public String getOutputName()
85      {
86          return outputName;
87      }
88  
89      @Override
90      protected boolean isSkipped()
91      {
92          return skipSurefireReport;
93      }
94  
95      @Override
96      protected boolean isGeneratedWhenNoResults()
97      {
98          return alwaysGenerateSurefireReport;
99      }
100 
101     @Override
102     public void setTitle( String title )
103     {
104         this.title = title;
105     }
106 
107     @Override
108     public String getTitle()
109     {
110         return title;
111     }
112 
113     @Override
114     public void setDescription( String description )
115     {
116         this.description = description;
117     }
118 
119     @Override
120     public String getDescription()
121     {
122         return description;
123     }
124 }