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.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 extends AbstractSurefireReportMojo {
38  
39      /**
40       * The filename to use for the report.
41       */
42      @Parameter(defaultValue = "surefire-report", property = "outputName", required = true)
43      private String outputName;
44  
45      /**
46       * If set to true the surefire report will be generated even when there are no surefire result files.
47       * Defaults to {@code true} to preserve legacy behaviour pre 2.10.
48       * @since 2.11
49       */
50      @Parameter(defaultValue = "true", property = "alwaysGenerateSurefireReport")
51      private boolean alwaysGenerateSurefireReport;
52  
53      /**
54       * If set to true the surefire report generation will be skipped.
55       * @since 2.11
56       */
57      @Parameter(defaultValue = "false", property = "skipSurefireReport")
58      private boolean skipSurefireReport;
59  
60      @Override
61      protected File getSurefireReportsDirectory(MavenProject subProject) {
62          String buildDir = subProject.getBuild().getDirectory();
63          return new File(buildDir, "surefire-reports");
64      }
65  
66      @Override
67      public String getOutputName() {
68          return outputName;
69      }
70  
71      @Override
72      protected boolean isSkipped() {
73          return skipSurefireReport;
74      }
75  
76      @Override
77      protected boolean isGeneratedWhenNoResults() {
78          return alwaysGenerateSurefireReport;
79      }
80  
81      @Override
82      protected String getI18Nsection() {
83          return "surefire";
84      }
85  }