1 package org.apache.maven.surefire.booter;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.PrintStream;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.Properties;
27 import org.apache.maven.surefire.report.AbstractConsoleReporter;
28 import org.apache.maven.surefire.report.AbstractFileReporter;
29 import org.apache.maven.surefire.report.BriefConsoleReporter;
30 import org.apache.maven.surefire.report.BriefFileReporter;
31 import org.apache.maven.surefire.report.ConsoleOutputDirectReporter;
32 import org.apache.maven.surefire.report.ConsoleOutputFileReporter;
33 import org.apache.maven.surefire.report.ConsoleReporter;
34 import org.apache.maven.surefire.report.DetailedConsoleReporter;
35 import org.apache.maven.surefire.report.FileReporter;
36 import org.apache.maven.surefire.report.Reporter;
37 import org.apache.maven.surefire.report.XMLReporter;
38
39
40
41
42
43
44
45
46 public class StartupReportConfiguration
47 {
48 private final boolean useFile;
49
50 private final boolean printSummary;
51
52 private final String reportFormat;
53
54 private final String reportNameSuffix;
55
56 private final boolean redirectTestOutputToFile;
57
58 private final boolean disableXmlReport;
59
60 private final File reportsDirectory;
61
62 private final boolean trimStackTrace;
63
64 private final Properties testVmSystemProperties = new Properties( );
65
66 public static final String BRIEF_REPORT_FORMAT = "brief";
67
68 public static final String PLAIN_REPORT_FORMAT = "plain";
69
70 public StartupReportConfiguration( boolean useFile, boolean printSummary, String reportFormat,
71 boolean redirectTestOutputToFile, boolean disableXmlReport,
72 File reportsDirectory, boolean trimStackTrace )
73 {
74 this( useFile, printSummary, reportFormat, redirectTestOutputToFile,
75 disableXmlReport, reportsDirectory, trimStackTrace, null );
76 }
77
78 public StartupReportConfiguration( boolean useFile, boolean printSummary, String reportFormat,
79 boolean redirectTestOutputToFile, boolean disableXmlReport,
80 File reportsDirectory, boolean trimStackTrace,
81 String reportNameSuffix )
82 {
83 this.useFile = useFile;
84 this.printSummary = printSummary;
85 this.reportFormat = reportFormat;
86 this.redirectTestOutputToFile = redirectTestOutputToFile;
87 this.disableXmlReport = disableXmlReport;
88 this.reportsDirectory = reportsDirectory;
89 this.trimStackTrace = trimStackTrace;
90 this.reportNameSuffix = reportNameSuffix;
91 }
92
93 public static StartupReportConfiguration defaultValue()
94 {
95 File target = new File( "./target" );
96 return new StartupReportConfiguration( true, true, "PLAIN", false, false, target, false );
97 }
98
99 public static StartupReportConfiguration defaultNoXml()
100 {
101 File target = new File( "./target" );
102 return new StartupReportConfiguration( true, true, "PLAIN", false, true, target, false );
103 }
104
105 public boolean isUseFile()
106 {
107 return useFile;
108 }
109
110 public boolean isPrintSummary()
111 {
112 return printSummary;
113 }
114
115 public String getReportFormat()
116 {
117 return reportFormat;
118 }
119
120 public String getReportNameSuffix()
121 {
122 return reportNameSuffix;
123 }
124
125 public boolean isRedirectTestOutputToFile()
126 {
127 return redirectTestOutputToFile;
128 }
129
130 public boolean isDisableXmlReport()
131 {
132 return disableXmlReport;
133 }
134
135 public File getReportsDirectory()
136 {
137 return reportsDirectory;
138 }
139
140 public String getXmlReporterName()
141 {
142 if ( !isDisableXmlReport() )
143 {
144 return XMLReporter.class.getName();
145 }
146 return null;
147 }
148
149 public XMLReporter instantiateXmlReporter()
150 {
151 if ( !isDisableXmlReport() )
152 {
153 return new XMLReporter(trimStackTrace, reportsDirectory, reportNameSuffix);
154 }
155 return null;
156 }
157
158 public String getFileReporter()
159 {
160 if ( isUseFile() )
161 {
162 if ( BRIEF_REPORT_FORMAT.equals( getReportFormat() ) )
163 {
164 return BriefFileReporter.class.getName();
165 }
166 else if ( PLAIN_REPORT_FORMAT.equals( getReportFormat() ) )
167 {
168 return FileReporter.class.getName();
169 }
170 }
171 return null;
172 }
173
174 public AbstractFileReporter instantiateFileReporter()
175 {
176 if ( isUseFile() )
177 {
178 if ( BRIEF_REPORT_FORMAT.equals( getReportFormat() ) )
179 {
180 return new BriefFileReporter(trimStackTrace, reportsDirectory, getReportNameSuffix());
181 }
182 else if ( PLAIN_REPORT_FORMAT.equals( getReportFormat() ) )
183 {
184 return new FileReporter(trimStackTrace, reportsDirectory, getReportNameSuffix());
185 }
186 }
187 return null;
188 }
189
190
191
192
193
194
195
196 public String getConsoleReporter()
197 {
198 if ( isUseFile() )
199 {
200 return isPrintSummary() ? ConsoleReporter.class.getName() : null;
201 }
202 else if ( isRedirectTestOutputToFile() || BRIEF_REPORT_FORMAT.equals( getReportFormat() ) )
203 {
204 return BriefConsoleReporter.class.getName();
205 }
206 else if ( PLAIN_REPORT_FORMAT.equals( getReportFormat() ) )
207 {
208 return DetailedConsoleReporter.class.getName();
209 }
210 return null;
211 }
212
213 public AbstractConsoleReporter instantiateConsoleReporter()
214 {
215 if ( isUseFile() )
216 {
217 return isPrintSummary() ? new ConsoleReporter(trimStackTrace) : null;
218 }
219 else if ( isRedirectTestOutputToFile() || BRIEF_REPORT_FORMAT.equals( getReportFormat() ) )
220 {
221 return new BriefConsoleReporter(trimStackTrace);
222 }
223 else if ( PLAIN_REPORT_FORMAT.equals( getReportFormat() ) )
224 {
225 return new DetailedConsoleReporter(trimStackTrace );
226 }
227 return null;
228 }
229
230 public String getConsoleOutputFileReporterName()
231 {
232 if ( isRedirectTestOutputToFile() )
233 {
234 return ConsoleOutputFileReporter.class.getName();
235 }
236 else
237 {
238 return ConsoleOutputDirectReporter.class.getName();
239 }
240 }
241
242 public Reporter instantiateConsoleOutputFileReporterName(PrintStream originalSystemOut)
243 {
244 if ( isRedirectTestOutputToFile() )
245 {
246 return new ConsoleOutputFileReporter(reportsDirectory, getReportNameSuffix());
247 }
248 else
249 {
250 return new ConsoleOutputDirectReporter(originalSystemOut);
251 }
252 }
253
254
255
256
257
258
259
260
261 public List getReports()
262 {
263 ArrayList reports = new ArrayList();
264 addIfNotNull( reports, getConsoleReporter() );
265 addIfNotNull( reports, getFileReporter() );
266 addIfNotNull( reports, getXmlReporterName() );
267 addIfNotNull( reports, getConsoleOutputFileReporterName() );
268 return reports;
269 }
270
271 private void addIfNotNull( ArrayList reports, String reporter )
272 {
273 if ( reporter != null )
274 {
275 reports.add( reporter );
276 }
277 }
278
279 public Properties getTestVmSystemProperties()
280 {
281 return testVmSystemProperties;
282 }
283
284
285 public boolean isTrimStackTrace()
286 {
287 return trimStackTrace;
288 }
289 }