1 | |
package org.apache.maven.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.Iterator; |
25 | |
import java.util.List; |
26 | |
import org.apache.maven.plugin.surefire.runorder.StatisticsReporter; |
27 | |
import org.apache.maven.surefire.util.internal.ByteBuffer; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
public class TestSetRunListener |
34 | |
implements RunListener, Reporter, ConsoleOutputReceiver, |
35 | |
ConsoleLogger |
36 | |
{ |
37 | |
private final TestSetStatistics testSetStatistics; |
38 | |
|
39 | |
private final RunStatistics globalStatistics; |
40 | |
|
41 | |
private final MulticastingReporter multicastingReporter; |
42 | |
|
43 | 0 | private final List testStdOut = Collections.synchronizedList( new ArrayList() ); |
44 | |
|
45 | 0 | private final List testStdErr = Collections.synchronizedList( new ArrayList() ); |
46 | |
|
47 | |
|
48 | |
public TestSetRunListener( AbstractConsoleReporter consoleReporter, AbstractFileReporter fileReporter, |
49 | |
XMLReporter xmlReporter, Reporter reporter, StatisticsReporter statisticsReporter, |
50 | |
RunStatistics globalStats ) |
51 | 0 | { |
52 | |
|
53 | 0 | ArrayList reportes = new ArrayList(); |
54 | 0 | if ( consoleReporter != null ) |
55 | |
{ |
56 | 0 | reportes.add( consoleReporter ); |
57 | |
} |
58 | 0 | if ( fileReporter != null ) |
59 | |
{ |
60 | 0 | reportes.add( fileReporter ); |
61 | |
} |
62 | 0 | if ( xmlReporter != null ) |
63 | |
{ |
64 | 0 | reportes.add( xmlReporter ); |
65 | |
} |
66 | 0 | if ( reporter != null ) |
67 | |
{ |
68 | 0 | reportes.add( reporter ); |
69 | |
} |
70 | 0 | if ( statisticsReporter != null ) |
71 | |
{ |
72 | 0 | reportes.add( statisticsReporter ); |
73 | |
} |
74 | 0 | multicastingReporter = new MulticastingReporter( reportes ); |
75 | 0 | this.testSetStatistics = new TestSetStatistics(); |
76 | 0 | this.globalStatistics = globalStats; |
77 | 0 | } |
78 | |
|
79 | |
public void info( String message ) |
80 | |
{ |
81 | 0 | multicastingReporter.writeMessage( message ); |
82 | 0 | } |
83 | |
|
84 | |
public void writeMessage( String message ) |
85 | |
{ |
86 | 0 | info( message ); |
87 | 0 | } |
88 | |
|
89 | |
public void writeMessage( byte[] b, int off, int len ) |
90 | |
{ |
91 | 0 | multicastingReporter.writeMessage( b, off, len ); |
92 | 0 | } |
93 | |
|
94 | |
public void writeTestOutput( byte[] buf, int off, int len, boolean stdout ) |
95 | |
{ |
96 | 0 | ByteBuffer byteBuffer = new ByteBuffer( buf, off, len ); |
97 | 0 | if ( stdout ) |
98 | |
{ |
99 | 0 | testStdOut.add( byteBuffer ); |
100 | |
} |
101 | |
else |
102 | |
{ |
103 | 0 | testStdErr.add( byteBuffer ); |
104 | |
} |
105 | 0 | multicastingReporter.writeMessage( buf, off, len ); |
106 | 0 | } |
107 | |
|
108 | |
public void testSetStarting( ReportEntry report ) |
109 | |
{ |
110 | 0 | multicastingReporter.testSetStarting( report ); |
111 | 0 | } |
112 | |
|
113 | |
public void clearCapture() |
114 | |
{ |
115 | 0 | testStdErr.clear(); |
116 | 0 | testStdOut.clear(); |
117 | 0 | } |
118 | |
|
119 | |
public void testSetCompleted( ReportEntry report ) |
120 | |
{ |
121 | 0 | multicastingReporter.testSetCompleted( report ); |
122 | 0 | multicastingReporter.reset(); |
123 | 0 | globalStatistics.add( testSetStatistics ); |
124 | 0 | testSetStatistics.reset(); |
125 | 0 | } |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
public void testStarting( ReportEntry report ) |
132 | |
{ |
133 | 0 | multicastingReporter.testStarting( report ); |
134 | 0 | } |
135 | |
|
136 | |
public void testSucceeded( ReportEntry report ) |
137 | |
{ |
138 | 0 | testSetStatistics.incrementCompletedCount(); |
139 | 0 | multicastingReporter.testSucceeded( report ); |
140 | 0 | clearCapture(); |
141 | 0 | } |
142 | |
|
143 | |
public void testError( ReportEntry reportEntry ) |
144 | |
{ |
145 | 0 | multicastingReporter.testError( reportEntry, getAsString( testStdOut ), getAsString( testStdErr ) ); |
146 | 0 | testSetStatistics.incrementErrorsCount(); |
147 | 0 | testSetStatistics.incrementCompletedCount(); |
148 | 0 | globalStatistics.addErrorSource( reportEntry.getName(), reportEntry.getStackTraceWriter() ); |
149 | 0 | clearCapture(); |
150 | 0 | } |
151 | |
|
152 | |
public void testError( ReportEntry reportEntry, String stdOutLog, String stdErrLog ) |
153 | |
{ |
154 | 0 | multicastingReporter.testError( reportEntry, stdOutLog, stdErrLog ); |
155 | 0 | testSetStatistics.incrementErrorsCount(); |
156 | 0 | testSetStatistics.incrementCompletedCount(); |
157 | 0 | globalStatistics.addErrorSource( reportEntry.getName(), reportEntry.getStackTraceWriter() ); |
158 | 0 | clearCapture(); |
159 | 0 | } |
160 | |
|
161 | |
public void testFailed( ReportEntry reportEntry ) |
162 | |
{ |
163 | 0 | multicastingReporter.testFailed( reportEntry, getAsString( testStdOut ), getAsString( testStdErr ) ); |
164 | 0 | testSetStatistics.incrementFailureCount(); |
165 | 0 | testSetStatistics.incrementCompletedCount(); |
166 | 0 | globalStatistics.addFailureSource( reportEntry.getName(), reportEntry.getStackTraceWriter() ); |
167 | 0 | clearCapture(); |
168 | 0 | } |
169 | |
|
170 | |
public void testFailed( ReportEntry reportEntry, String stdOutLog, String stdErrLog ) |
171 | |
{ |
172 | 0 | multicastingReporter.testFailed( reportEntry, stdOutLog, stdErrLog ); |
173 | 0 | testSetStatistics.incrementFailureCount(); |
174 | 0 | testSetStatistics.incrementCompletedCount(); |
175 | 0 | globalStatistics.addFailureSource( reportEntry.getName(), reportEntry.getStackTraceWriter() ); |
176 | 0 | clearCapture(); |
177 | 0 | } |
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
public void testSkipped( ReportEntry report ) |
184 | |
{ |
185 | 0 | clearCapture(); |
186 | 0 | testSetStatistics.incrementSkippedCount(); |
187 | 0 | testSetStatistics.incrementCompletedCount(); |
188 | 0 | multicastingReporter.testSkipped( report ); |
189 | 0 | } |
190 | |
|
191 | |
public void testAssumptionFailure( ReportEntry report ) |
192 | |
{ |
193 | 0 | testSkipped( report ); |
194 | 0 | } |
195 | |
|
196 | |
public void reset() |
197 | |
{ |
198 | 0 | multicastingReporter.reset(); |
199 | 0 | } |
200 | |
|
201 | |
public String getAsString( List byteBufferList ) |
202 | |
{ |
203 | 0 | StringBuffer stringBuffer = new StringBuffer(); |
204 | 0 | for ( Iterator iter = byteBufferList.iterator(); iter.hasNext(); ) |
205 | |
{ |
206 | 0 | ByteBuffer byteBuffer = (ByteBuffer) iter.next(); |
207 | 0 | stringBuffer.append( byteBuffer.toString() ); |
208 | 0 | } |
209 | 0 | return stringBuffer.toString(); |
210 | |
} |
211 | |
} |