1 | |
package org.apache.maven.plugin.surefire; |
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.Properties; |
25 | |
import org.apache.maven.plugin.surefire.report.ConsoleOutputFileReporter; |
26 | |
import org.apache.maven.plugin.surefire.report.ConsoleReporter; |
27 | |
import org.apache.maven.plugin.surefire.report.DirectConsoleOutput; |
28 | |
import org.apache.maven.plugin.surefire.report.FileReporter; |
29 | |
import org.apache.maven.plugin.surefire.report.StatelessXmlReporter; |
30 | |
import org.apache.maven.plugin.surefire.report.TestcycleConsoleOutputReceiver; |
31 | |
import org.apache.maven.plugin.surefire.runorder.StatisticsReporter; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
public class StartupReportConfiguration |
40 | |
{ |
41 | |
private final PrintStream originalSystemOut; |
42 | |
|
43 | |
private final PrintStream originalSystemErr; |
44 | |
|
45 | |
private final boolean useFile; |
46 | |
|
47 | |
private final boolean printSummary; |
48 | |
|
49 | |
private final String reportFormat; |
50 | |
|
51 | |
private final String reportNameSuffix; |
52 | |
|
53 | |
private final String configurationHash; |
54 | |
|
55 | |
private final boolean requiresRunHistory; |
56 | |
|
57 | |
private final boolean redirectTestOutputToFile; |
58 | |
|
59 | |
private final boolean disableXmlReport; |
60 | |
|
61 | |
private final File reportsDirectory; |
62 | |
|
63 | |
private final boolean trimStackTrace; |
64 | |
|
65 | 16 | private final Properties testVmSystemProperties = new Properties(); |
66 | |
|
67 | |
public static final String BRIEF_REPORT_FORMAT = ConsoleReporter.BRIEF; |
68 | |
|
69 | |
public static final String PLAIN_REPORT_FORMAT = ConsoleReporter.PLAIN; |
70 | |
|
71 | |
public StartupReportConfiguration( boolean useFile, boolean printSummary, String reportFormat, |
72 | |
boolean redirectTestOutputToFile, boolean disableXmlReport, |
73 | |
File reportsDirectory, boolean trimStackTrace, String reportNameSuffix, |
74 | |
String configurationHash, boolean requiresRunHistory ) |
75 | 16 | { |
76 | 16 | this.useFile = useFile; |
77 | 16 | this.printSummary = printSummary; |
78 | 16 | this.reportFormat = reportFormat; |
79 | 16 | this.redirectTestOutputToFile = redirectTestOutputToFile; |
80 | 16 | this.disableXmlReport = disableXmlReport; |
81 | 16 | this.reportsDirectory = reportsDirectory; |
82 | 16 | this.trimStackTrace = trimStackTrace; |
83 | 16 | this.reportNameSuffix = reportNameSuffix; |
84 | 16 | this.configurationHash = configurationHash; |
85 | 16 | this.requiresRunHistory = requiresRunHistory; |
86 | 16 | this.originalSystemOut = System.out; |
87 | 16 | this.originalSystemErr = System.err; |
88 | 16 | } |
89 | |
|
90 | |
public static StartupReportConfiguration defaultValue() |
91 | |
{ |
92 | 16 | File target = new File( "./target" ); |
93 | 16 | return new StartupReportConfiguration( true, true, "PLAIN", false, false, target, false, null, "TESTHASH", |
94 | |
false ); |
95 | |
} |
96 | |
|
97 | |
public static StartupReportConfiguration defaultNoXml() |
98 | |
{ |
99 | 0 | File target = new File( "./target" ); |
100 | 0 | return new StartupReportConfiguration( true, true, "PLAIN", false, true, target, false, null, "TESTHASHxXML", |
101 | |
false ); |
102 | |
} |
103 | |
|
104 | |
public boolean isUseFile() |
105 | |
{ |
106 | 0 | return useFile; |
107 | |
} |
108 | |
|
109 | |
public boolean isPrintSummary() |
110 | |
{ |
111 | 0 | return printSummary; |
112 | |
} |
113 | |
|
114 | |
public String getReportFormat() |
115 | |
{ |
116 | 0 | return reportFormat; |
117 | |
} |
118 | |
|
119 | |
public String getReportNameSuffix() |
120 | |
{ |
121 | 0 | return reportNameSuffix; |
122 | |
} |
123 | |
|
124 | |
public boolean isRedirectTestOutputToFile() |
125 | |
{ |
126 | 0 | return redirectTestOutputToFile; |
127 | |
} |
128 | |
|
129 | |
public boolean isDisableXmlReport() |
130 | |
{ |
131 | 0 | return disableXmlReport; |
132 | |
} |
133 | |
|
134 | |
public File getReportsDirectory() |
135 | |
{ |
136 | 0 | return reportsDirectory; |
137 | |
} |
138 | |
|
139 | |
public StatelessXmlReporter instantiateStatelessXmlReporter() |
140 | |
{ |
141 | 0 | if ( !isDisableXmlReport() ) |
142 | |
{ |
143 | 0 | return new StatelessXmlReporter( reportsDirectory, reportNameSuffix, trimStackTrace ); |
144 | |
} |
145 | 0 | return null; |
146 | |
} |
147 | |
|
148 | |
public FileReporter instantiateFileReporter() |
149 | |
{ |
150 | 0 | if ( isUseFile() && isBriefOrPlainFormat() ) |
151 | |
{ |
152 | 0 | return new FileReporter( reportsDirectory, getReportNameSuffix() ); |
153 | |
} |
154 | 0 | return null; |
155 | |
} |
156 | |
|
157 | |
public boolean isBriefOrPlainFormat() |
158 | |
{ |
159 | 0 | String fmt = getReportFormat(); |
160 | 0 | return BRIEF_REPORT_FORMAT.equals( fmt ) || PLAIN_REPORT_FORMAT.equals( fmt ); |
161 | |
} |
162 | |
|
163 | |
public ConsoleReporter instantiateConsoleReporter() |
164 | |
{ |
165 | 0 | return shouldReportToConsole() ? new ConsoleReporter( originalSystemOut ) : null; |
166 | |
} |
167 | |
|
168 | |
private boolean shouldReportToConsole() |
169 | |
{ |
170 | 0 | return isUseFile() ? isPrintSummary() : isRedirectTestOutputToFile() || isBriefOrPlainFormat(); |
171 | |
} |
172 | |
|
173 | |
public TestcycleConsoleOutputReceiver instantiateConsoleOutputFileReporter() |
174 | |
{ |
175 | 0 | if ( isRedirectTestOutputToFile() ) |
176 | |
{ |
177 | 0 | return new ConsoleOutputFileReporter( reportsDirectory, getReportNameSuffix() ); |
178 | |
} |
179 | |
else |
180 | |
{ |
181 | 0 | return new DirectConsoleOutput( originalSystemOut, originalSystemErr ); |
182 | |
} |
183 | |
} |
184 | |
|
185 | |
public StatisticsReporter instantiateStatisticsReporter() |
186 | |
{ |
187 | 16 | if ( requiresRunHistory ) |
188 | |
{ |
189 | 0 | final File target = getStatisticsFile(); |
190 | 0 | return new StatisticsReporter( target ); |
191 | |
} |
192 | 16 | return null; |
193 | |
} |
194 | |
|
195 | |
public File getStatisticsFile() |
196 | |
{ |
197 | 0 | return new File( reportsDirectory.getParentFile().getParentFile(), ".surefire-" + this.configurationHash ); |
198 | |
} |
199 | |
|
200 | |
|
201 | |
public Properties getTestVmSystemProperties() |
202 | |
{ |
203 | 0 | return testVmSystemProperties; |
204 | |
} |
205 | |
|
206 | |
|
207 | |
public boolean isTrimStackTrace() |
208 | |
{ |
209 | 0 | return trimStackTrace; |
210 | |
} |
211 | |
|
212 | |
public String getConfigurationHash() |
213 | |
{ |
214 | 0 | return configurationHash; |
215 | |
} |
216 | |
|
217 | |
public boolean isRequiresRunHistory() |
218 | |
{ |
219 | 0 | return requiresRunHistory; |
220 | |
} |
221 | |
|
222 | |
public PrintStream getOriginalSystemOut() |
223 | |
{ |
224 | 16 | return originalSystemOut; |
225 | |
} |
226 | |
|
227 | |
} |