1 | |
package org.apache.maven.plugin.surefire.report; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.util.ArrayList; |
23 | |
import java.util.Collections; |
24 | |
import java.util.List; |
25 | |
import org.apache.maven.plugin.surefire.StartupReportConfiguration; |
26 | |
import org.apache.maven.plugin.surefire.runorder.StatisticsReporter; |
27 | |
import org.apache.maven.surefire.report.DefaultDirectConsoleReporter; |
28 | |
import org.apache.maven.surefire.report.ReporterFactory; |
29 | |
import org.apache.maven.surefire.report.RunListener; |
30 | |
import org.apache.maven.surefire.report.RunStatistics; |
31 | |
import org.apache.maven.surefire.suite.RunResult; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public class DefaultReporterFactory |
41 | |
implements ReporterFactory |
42 | |
{ |
43 | |
|
44 | 16 | private final RunStatistics globalStats = new RunStatistics(); |
45 | |
|
46 | |
private final StartupReportConfiguration reportConfiguration; |
47 | |
|
48 | |
private final StatisticsReporter statisticsReporter; |
49 | |
|
50 | 16 | private final List<TestSetRunListener> listeners = |
51 | |
Collections.synchronizedList( new ArrayList<TestSetRunListener>() ); |
52 | |
|
53 | |
public DefaultReporterFactory( StartupReportConfiguration reportConfiguration ) |
54 | 16 | { |
55 | 16 | this.reportConfiguration = reportConfiguration; |
56 | 16 | this.statisticsReporter = reportConfiguration.instantiateStatisticsReporter(); |
57 | 16 | runStarting(); |
58 | 16 | } |
59 | |
|
60 | |
public RunListener createReporter() |
61 | |
{ |
62 | 0 | return createTestSetRunListener(); |
63 | |
} |
64 | |
|
65 | |
public RunListener createTestSetRunListener() |
66 | |
{ |
67 | 0 | TestSetRunListener testSetRunListener = |
68 | |
new TestSetRunListener( reportConfiguration.instantiateConsoleReporter(), |
69 | |
reportConfiguration.instantiateFileReporter(), |
70 | |
reportConfiguration.instantiateStatelessXmlReporter(), |
71 | |
reportConfiguration.instantiateConsoleOutputFileReporter(), statisticsReporter, |
72 | |
globalStats, reportConfiguration.isTrimStackTrace(), |
73 | |
ConsoleReporter.PLAIN.equals( reportConfiguration.getReportFormat() ), |
74 | |
reportConfiguration.isBriefOrPlainFormat() ); |
75 | 0 | listeners.add( testSetRunListener ); |
76 | 0 | return testSetRunListener; |
77 | |
} |
78 | |
|
79 | |
public RunResult close() |
80 | |
{ |
81 | 0 | runCompleted(); |
82 | 0 | for ( TestSetRunListener listener : listeners ) |
83 | |
{ |
84 | 0 | listener.close(); |
85 | |
} |
86 | 0 | return globalStats.getRunResult(); |
87 | |
} |
88 | |
|
89 | |
private DefaultDirectConsoleReporter createConsoleLogger() |
90 | |
{ |
91 | 16 | return new DefaultDirectConsoleReporter( reportConfiguration.getOriginalSystemOut() ); |
92 | |
} |
93 | |
|
94 | |
public void runStarting() |
95 | |
{ |
96 | 16 | final DefaultDirectConsoleReporter consoleReporter = createConsoleLogger(); |
97 | 16 | consoleReporter.info( "" ); |
98 | 16 | consoleReporter.info( "-------------------------------------------------------" ); |
99 | 16 | consoleReporter.info( " T E S T S" ); |
100 | 16 | consoleReporter.info( "-------------------------------------------------------" ); |
101 | 16 | } |
102 | |
|
103 | |
private void runCompleted() |
104 | |
{ |
105 | 0 | final DefaultDirectConsoleReporter logger = createConsoleLogger(); |
106 | 0 | if ( reportConfiguration.isPrintSummary() ) |
107 | |
{ |
108 | 0 | logger.info( "" ); |
109 | 0 | logger.info( "Results :" ); |
110 | 0 | logger.info( "" ); |
111 | |
} |
112 | 0 | if ( globalStats.hadFailures() ) |
113 | |
{ |
114 | 0 | logger.info( "Failed tests: " ); |
115 | 0 | for ( Object o : this.globalStats.getFailureSources() ) |
116 | |
{ |
117 | 0 | logger.info( " " + o ); |
118 | |
} |
119 | 0 | logger.info( "" ); |
120 | |
} |
121 | 0 | if ( globalStats.hadErrors() ) |
122 | |
{ |
123 | 0 | logger.info( "Tests in error: " ); |
124 | 0 | for ( Object o : this.globalStats.getErrorSources() ) |
125 | |
{ |
126 | 0 | logger.info( " " + o ); |
127 | |
} |
128 | 0 | logger.info( "" ); |
129 | |
} |
130 | 0 | logger.info( globalStats.getSummary() ); |
131 | 0 | logger.info( "" ); |
132 | 0 | } |
133 | |
|
134 | |
public RunStatistics getGlobalRunStatistics() |
135 | |
{ |
136 | 0 | return globalStats; |
137 | |
} |
138 | |
|
139 | |
public static DefaultReporterFactory defaultNoXml() |
140 | |
{ |
141 | 0 | return new DefaultReporterFactory( StartupReportConfiguration.defaultNoXml() ); |
142 | |
} |
143 | |
} |