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