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 private final RunStatistics globalStats = new RunStatistics();
45
46 private final StartupReportConfiguration reportConfiguration;
47
48 private final StatisticsReporter statisticsReporter;
49
50 private final List<TestSetRunListener> listeners =
51 Collections.synchronizedList( new ArrayList<TestSetRunListener>() );
52
53 public DefaultReporterFactory( StartupReportConfiguration reportConfiguration )
54 {
55 this.reportConfiguration = reportConfiguration;
56 this.statisticsReporter = reportConfiguration.instantiateStatisticsReporter();
57 runStarting();
58 }
59
60 public RunListener createReporter()
61 {
62 return createTestSetRunListener();
63 }
64
65 public RunListener createTestSetRunListener()
66 {
67 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 listeners.add( testSetRunListener );
76 return testSetRunListener;
77 }
78
79 public RunResult close()
80 {
81 runCompleted();
82 for ( TestSetRunListener listener : listeners )
83 {
84 listener.close();
85 }
86 return globalStats.getRunResult();
87 }
88
89 private DefaultDirectConsoleReporter createConsoleLogger()
90 {
91 return new DefaultDirectConsoleReporter( reportConfiguration.getOriginalSystemOut() );
92 }
93
94 public void runStarting()
95 {
96 final DefaultDirectConsoleReporter consoleReporter = createConsoleLogger();
97 consoleReporter.info( "" );
98 consoleReporter.info( "-------------------------------------------------------" );
99 consoleReporter.info( " T E S T S" );
100 consoleReporter.info( "-------------------------------------------------------" );
101 }
102
103 private void runCompleted()
104 {
105 final DefaultDirectConsoleReporter logger = createConsoleLogger();
106 if ( reportConfiguration.isPrintSummary() )
107 {
108 logger.info( "" );
109 logger.info( "Results :" );
110 logger.info( "" );
111 }
112 if ( globalStats.hadFailures() )
113 {
114 logger.info( "Failed tests: " );
115 for ( Object o : this.globalStats.getFailureSources() )
116 {
117 logger.info( " " + o );
118 }
119 logger.info( "" );
120 }
121 if ( globalStats.hadErrors() )
122 {
123 logger.info( "Tests in error: " );
124 for ( Object o : this.globalStats.getErrorSources() )
125 {
126 logger.info( " " + o );
127 }
128 logger.info( "" );
129 }
130 logger.info( globalStats.getSummary() );
131 logger.info( "" );
132 }
133
134 public RunStatistics getGlobalRunStatistics()
135 {
136 return globalStats;
137 }
138
139 public static DefaultReporterFactory defaultNoXml()
140 {
141 return new DefaultReporterFactory( StartupReportConfiguration.defaultNoXml() );
142 }
143 }