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 javax.inject.Inject;
22  
23  import java.io.File;
24  
25  import org.apache.maven.plugins.annotations.Mojo;
26  import org.apache.maven.plugins.annotations.Parameter;
27  import org.apache.maven.project.MavenProject;
28  import org.codehaus.plexus.i18n.I18N;
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  @SuppressWarnings("unused")
41  public class FailsafeOnlyReport extends AbstractSurefireReport {
42  
43      /**
44       * The filename to use for the report.
45       */
46      @Parameter(defaultValue = "failsafe", property = "outputName", required = true)
47      private String outputName;
48  
49      /**
50       * If set to true the failsafe report will be generated even when there are no failsafe result files.
51       * Defaults to {@code false} to preserve legacy behaviour pre 2.10.
52       * @since 2.11
53       */
54      @Parameter(defaultValue = "false", property = "alwaysGenerateFailsafeReport")
55      private boolean alwaysGenerateFailsafeReport;
56  
57      /**
58       * If set to true the failsafe report generation will be skipped.
59       * @since 2.11
60       */
61      @Parameter(defaultValue = "false", property = "skipFailsafeReport")
62      private boolean skipFailsafeReport;
63  
64      @Inject
65      public FailsafeOnlyReport(I18N i18n) {
66          super(i18n);
67      }
68  
69      @Override
70      protected File getSurefireReportsDirectory(MavenProject subProject) {
71          String buildDir = subProject.getBuild().getDirectory();
72          return new File(buildDir, "failsafe-reports");
73      }
74  
75      @Override
76      public String getOutputName() {
77          return outputName;
78      }
79  
80      @Override
81      protected boolean isSkipped() {
82          return skipFailsafeReport;
83      }
84  
85      @Override
86      protected boolean isGeneratedWhenNoResults() {
87          return alwaysGenerateFailsafeReport;
88      }
89  
90      @Override
91      protected String getI18Nsection() {
92          return "failsafe";
93      }
94  }