View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.surefire.report;
20  
21  import java.io.File;
22  
23  import org.apache.maven.plugins.annotations.Mojo;
24  import org.apache.maven.plugins.annotations.Parameter;
25  import org.apache.maven.project.MavenProject;
26  
27  /**
28   * Creates a nicely formatted Failsafe Test Report in html format.
29   * This goal does not run the tests, it only builds the reports.
30   * See <a href="https://issues.apache.org/jira/browse/SUREFIRE-257">
31   *     https://issues.apache.org/jira/browse/SUREFIRE-257</a>
32   *
33   * @author Stephen Connolly
34   * @since 2.10
35   */
36  @Mojo(name = "failsafe-report-only")
37  @SuppressWarnings("unused")
38  public class FailsafeReportMojo extends AbstractSurefireReportMojo {
39  
40      /**
41       * The filename to use for the report.
42       */
43      @Parameter(defaultValue = "failsafe-report", property = "outputName", required = true)
44      private String outputName;
45  
46      /**
47       * If set to true the failsafe report will be generated even when there are no failsafe result files.
48       * Defaults to {@code false} to preserve legacy behaviour pre 2.10.
49       * @since 2.11
50       */
51      @Parameter(defaultValue = "false", property = "alwaysGenerateFailsafeReport")
52      private boolean alwaysGenerateFailsafeReport;
53  
54      /**
55       * If set to true the failsafe report generation will be skipped.
56       * @since 2.11
57       */
58      @Parameter(defaultValue = "false", property = "skipFailsafeReport")
59      private boolean skipFailsafeReport;
60  
61      @Override
62      protected File getSurefireReportsDirectory(MavenProject subProject) {
63          String buildDir = subProject.getBuild().getDirectory();
64          return new File(buildDir + "/failsafe-reports");
65      }
66  
67      @Override
68      public String getOutputName() {
69          return outputName;
70      }
71  
72      @Override
73      protected boolean isSkipped() {
74          return skipFailsafeReport;
75      }
76  
77      @Override
78      protected boolean isGeneratedWhenNoResults() {
79          return alwaysGenerateFailsafeReport;
80      }
81  
82      @Override
83      protected String getI18Nsection() {
84          return "failsafe";
85      }
86  }