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