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 org.apache.maven.surefire.util.internal.StringUtils; |
23 | |
|
24 | |
import java.util.ArrayList; |
25 | |
import java.util.Collection; |
26 | |
import java.util.Collections; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | 0 | public class RunStatistics |
32 | |
extends TestSetStatistics |
33 | |
{ |
34 | |
|
35 | |
|
36 | |
|
37 | 0 | private final Sources errorSources = new Sources(); |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | 0 | private final Sources failureSources = new Sources(); |
43 | |
|
44 | |
|
45 | |
|
46 | |
public void addErrorSource( String errorSource ) |
47 | |
{ |
48 | 0 | errorSources.addSource( errorSource ); |
49 | 0 | } |
50 | |
|
51 | |
public void addErrorSource( String errorSource, StackTraceWriter stackTraceWriter ) |
52 | |
{ |
53 | 0 | errorSources.addSource( errorSource, stackTraceWriter ); |
54 | 0 | } |
55 | |
|
56 | |
|
57 | |
public void addFailureSource( String failureSource ) |
58 | |
{ |
59 | 0 | failureSources.addSource( failureSource ); |
60 | 0 | } |
61 | |
|
62 | |
public void addFailureSource( String failureSource, StackTraceWriter stackTraceWriter ) |
63 | |
{ |
64 | 0 | failureSources.addSource( failureSource, stackTraceWriter ); |
65 | 0 | } |
66 | |
|
67 | |
public Collection getErrorSources() |
68 | |
{ |
69 | 0 | return errorSources.getListOfSources(); |
70 | |
} |
71 | |
|
72 | |
public Collection getFailureSources() |
73 | |
{ |
74 | 0 | return failureSources.getListOfSources(); |
75 | |
} |
76 | |
|
77 | 0 | private static class Sources |
78 | |
{ |
79 | 0 | private final Collection listOfSources = new ArrayList(); |
80 | |
|
81 | |
void addSource( String source ) |
82 | |
{ |
83 | 0 | synchronized ( listOfSources ) |
84 | |
{ |
85 | 0 | listOfSources.add( source ); |
86 | 0 | } |
87 | 0 | } |
88 | |
|
89 | |
void addSource( String source, StackTraceWriter stackTraceWriter ) |
90 | |
{ |
91 | 0 | String message = getMessageOfThrowable( stackTraceWriter ); |
92 | 0 | String extendedSource = StringUtils.isBlank( message ) ? source : source + ": " + trimToSingleLine(message); |
93 | 0 | addSource( extendedSource ); |
94 | 0 | } |
95 | |
|
96 | |
private String trimToSingleLine(String str){ |
97 | 0 | int i = str.indexOf( "\n" ); |
98 | 0 | return i >= 0 ? str.substring( 0, i ) : str; |
99 | |
} |
100 | |
|
101 | |
Collection getListOfSources() |
102 | |
{ |
103 | 0 | synchronized ( listOfSources ) |
104 | |
{ |
105 | 0 | return Collections.unmodifiableCollection( listOfSources ); |
106 | 0 | } |
107 | |
} |
108 | |
|
109 | |
private String getMessageOfThrowable( StackTraceWriter stackTraceWriter ) |
110 | |
{ |
111 | |
|
112 | 0 | return stackTraceWriter != null ? getMessageOfThrowable( stackTraceWriter.getThrowable() ) : ""; |
113 | |
} |
114 | |
|
115 | |
private String getMessageOfThrowable( Throwable throwable ) |
116 | |
{ |
117 | 0 | return throwable != null ? throwable.getLocalizedMessage() : ""; |
118 | |
} |
119 | |
} |
120 | |
} |