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 java.util.Locale;
24  import java.util.ResourceBundle;
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 Failsafe Test Report in html format.
32   * This goal does not run the tests, it only builds the reports.
33   * See <a href="https://issues.apache.org/jira/browse/SUREFIRE-257">
34   *     https://issues.apache.org/jira/browse/SUREFIRE-257</a>
35   *
36   * @author Stephen Connolly
37   * @since 2.10
38   */
39  @Mojo( name = "failsafe-report-only" )
40  public class FailsafeReportMojo
41      extends AbstractSurefireReportMojo
42  {
43  
44      /**
45       * The filename to use for the report.
46       */
47      @Parameter( defaultValue = "failsafe-report", property = "outputName", required = true )
48      private String outputName;
49  
50      /**
51       * If set to true the failsafe report will be generated even when there are no failsafe result files.
52       * Defaults to {@code false} to preserve legacy behaviour pre 2.10.
53       * @since 2.11
54       */
55      @Parameter( defaultValue = "false", property = "alwaysGenerateFailsafeReport" )
56      private boolean alwaysGenerateFailsafeReport;
57  
58      /**
59       * If set to true the failsafe report generation will be skipped.
60       * @since 2.11
61       */
62      @Parameter( defaultValue = "false", property = "skipFailsafeReport" )
63      private boolean skipFailsafeReport;
64  
65      @Override
66      protected File getSurefireReportsDirectory( MavenProject subProject )
67      {
68          String buildDir = subProject.getBuild().getDirectory();
69          return new File( buildDir + "/failsafe-reports" );
70      }
71  
72      @Override
73      public String getOutputName()
74      {
75          return outputName;
76      }
77  
78      @Override
79      protected boolean isSkipped()
80      {
81          return skipFailsafeReport;
82      }
83  
84      @Override
85      protected boolean isGeneratedWhenNoResults()
86      {
87          return alwaysGenerateFailsafeReport;
88      }
89  
90      /**
91       * {@inheritDoc}
92       */
93      @Override
94      public String getName( Locale locale )
95      {
96          return getBundle( locale ).getString( "report.failsafe.name" );
97      }
98  
99      /**
100      * {@inheritDoc}
101      */
102     @Override
103     public String getDescription( Locale locale )
104     {
105         return getBundle( locale ).getString( "report.failsafe.description" );
106     }
107 
108 
109     /*
110     * This is currently a copy of the getBundle() method of the AbstractSurefireReportMojo class,
111     * cause the failsafe report only different in two names for the bundles.
112     */
113     private ResourceBundle getBundle( Locale locale )
114     {
115         return ResourceBundle.getBundle( "surefire-report", locale, getClass().getClassLoader() );
116     }
117 }