1 package org.apache.maven.plugins.surefire.report;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.plugins.annotations.Execute;
23 import org.apache.maven.plugins.annotations.LifecyclePhase;
24 import org.apache.maven.plugins.annotations.Mojo;
25 import org.apache.maven.plugins.annotations.Parameter;
26 import org.apache.maven.project.MavenProject;
27
28 import java.io.File;
29 import java.util.Locale;
30 import java.util.ResourceBundle;
31
32 import static org.apache.maven.shared.utils.StringUtils.isEmpty;
33
34
35
36
37
38
39 @Mojo( name = "report", inheritByDefault = false )
40 @Execute( lifecycle = "surefire", phase = LifecyclePhase.TEST )
41 @SuppressWarnings( "unused" )
42 public class SurefireReportMojo
43 extends AbstractSurefireReportMojo
44 {
45
46
47
48
49 @Parameter( defaultValue = "surefire-report", property = "outputName", required = true )
50 private String outputName;
51
52
53
54
55
56
57 @Parameter( defaultValue = "true", property = "alwaysGenerateSurefireReport" )
58 private boolean alwaysGenerateSurefireReport;
59
60
61
62
63
64 @Parameter( defaultValue = "false", property = "skipSurefireReport" )
65 private boolean skipSurefireReport;
66
67
68
69
70
71 @Parameter( defaultValue = "", property = "surefire.report.title" )
72 private String title;
73
74
75
76
77
78 @Parameter( defaultValue = "", property = "surefire.report.description" )
79 private String description;
80
81 @Override
82 protected File getSurefireReportsDirectory( MavenProject subProject )
83 {
84 String buildDir = subProject.getBuild().getDirectory();
85 return new File( buildDir + "/surefire-reports" );
86 }
87
88 @Override
89 public String getOutputName()
90 {
91 return outputName;
92 }
93
94 @Override
95 protected LocalizedProperties getBundle( Locale locale, ClassLoader resourceBundleClassLoader )
96 {
97 ResourceBundle bundle = ResourceBundle.getBundle( "surefire-report", locale, resourceBundleClassLoader );
98 return new LocalizedProperties( bundle )
99 {
100 @Override
101 public String getReportName()
102 {
103 return isEmpty( SurefireReportMojo.this.getTitle() )
104 ? toLocalizedValue( "report.surefire.name" ) : SurefireReportMojo.this.getTitle();
105 }
106
107 @Override
108 public String getReportDescription()
109 {
110 return isEmpty( SurefireReportMojo.this.getDescription() )
111 ? toLocalizedValue( "report.surefire.description" ) : SurefireReportMojo.this.getDescription();
112 }
113
114 @Override
115 public String getReportHeader()
116 {
117 return isEmpty( SurefireReportMojo.this.getTitle() )
118 ? toLocalizedValue( "report.surefire.header" ) : SurefireReportMojo.this.getTitle();
119 }
120 };
121 }
122
123 @Override
124 protected boolean isSkipped()
125 {
126 return skipSurefireReport;
127 }
128
129 @Override
130 protected boolean isGeneratedWhenNoResults()
131 {
132 return alwaysGenerateSurefireReport;
133 }
134
135 @Override
136 public void setTitle( String title )
137 {
138 this.title = title;
139 }
140
141 @Override
142 public String getTitle()
143 {
144 return title;
145 }
146
147 @Override
148 public void setDescription( String description )
149 {
150 this.description = description;
151 }
152
153 @Override
154 public String getDescription()
155 {
156 return description;
157 }
158 }