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.Execute;
26  import org.apache.maven.plugins.annotations.LifecyclePhase;
27  import org.apache.maven.plugins.annotations.Mojo;
28  import org.apache.maven.plugins.annotations.Parameter;
29  import org.apache.maven.project.MavenProject;
30  import org.codehaus.plexus.i18n.I18N;
31  
32  /**
33   * Creates a nicely formatted Surefire Test Report in html format.
34   *
35   * @author <a href="mailto:jruiz@exist.com">Johnny R. Ruiz III</a>
36   */
37  @Mojo(name = "report")
38  @Execute(lifecycle = "surefire", phase = LifecyclePhase.TEST)
39  @SuppressWarnings("unused")
40  public class SurefireReport extends AbstractSurefireReport {
41  
42      /**
43       * The filename to use for the report.
44       */
45      @Parameter(defaultValue = "surefire", property = "outputName", required = true)
46      private String outputName;
47  
48      /**
49       * If set to true, the surefire report will be generated even when there are no surefire result files.
50       * Defaults to {@code true} to preserve legacy behaviour pre 2.10.
51       * @since 2.11
52       */
53      @Parameter(defaultValue = "true", property = "alwaysGenerateSurefireReport")
54      private boolean alwaysGenerateSurefireReport;
55  
56      /**
57       * If set to true, the surefire report generation will be skipped.
58       * @since 2.11
59       */
60      @Parameter(defaultValue = "false", property = "skipSurefireReport")
61      private boolean skipSurefireReport;
62  
63      @Inject
64      public SurefireReport(I18N i18n) {
65          super(i18n);
66      }
67  
68      @Override
69      protected File getSurefireReportsDirectory(MavenProject subProject) {
70          String buildDir = subProject.getBuild().getDirectory();
71          return new File(buildDir, "surefire-reports");
72      }
73  
74      @Override
75      public String getOutputName() {
76          return outputName;
77      }
78  
79      @Override
80      protected boolean isSkipped() {
81          return skipSurefireReport;
82      }
83  
84      @Override
85      protected boolean isGeneratedWhenNoResults() {
86          return alwaysGenerateSurefireReport;
87      }
88  
89      @Override
90      protected String getI18Nsection() {
91          return "surefire";
92      }
93  }