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 org.apache.commons.io.output.DeferredFileOutputStream; |
23 | |
import org.apache.maven.surefire.report.ReportEntry; |
24 | |
import org.apache.maven.surefire.report.StackTraceWriter; |
25 | |
|
26 | |
import java.text.NumberFormat; |
27 | |
import java.util.Locale; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
public class WrappedReportEntry |
33 | |
implements ReportEntry |
34 | |
{ |
35 | |
private final ReportEntry original; |
36 | |
|
37 | |
private final ReportEntryType reportEntryType; |
38 | |
|
39 | |
private final Integer elapsed; |
40 | |
|
41 | |
private final DeferredFileOutputStream stdout; |
42 | |
|
43 | |
private final DeferredFileOutputStream stdErr; |
44 | |
|
45 | 9 | private final NumberFormat numberFormat = NumberFormat.getInstance( Locale.ENGLISH ); |
46 | |
|
47 | |
private static final int MS_PER_SEC = 1000; |
48 | |
|
49 | 1 | static final String NL = System.getProperty( "line.separator" ); |
50 | |
|
51 | |
public WrappedReportEntry( ReportEntry original, ReportEntryType reportEntryType, Integer estimatedElapsed, |
52 | |
DeferredFileOutputStream stdout, DeferredFileOutputStream stdErr ) |
53 | 9 | { |
54 | 9 | this.original = original; |
55 | 9 | this.reportEntryType = reportEntryType; |
56 | 9 | this.elapsed = estimatedElapsed; |
57 | 9 | this.stdout = stdout; |
58 | 9 | this.stdErr = stdErr; |
59 | 9 | } |
60 | |
|
61 | |
public Integer getElapsed() |
62 | |
{ |
63 | 12 | return elapsed; |
64 | |
} |
65 | |
|
66 | |
public ReportEntryType getReportEntryType() |
67 | |
{ |
68 | 4 | return reportEntryType; |
69 | |
} |
70 | |
|
71 | |
public DeferredFileOutputStream getStdout() |
72 | |
{ |
73 | 1 | return stdout; |
74 | |
} |
75 | |
|
76 | |
public DeferredFileOutputStream getStdErr() |
77 | |
{ |
78 | 1 | return stdErr; |
79 | |
} |
80 | |
|
81 | |
public String getSourceName() |
82 | |
{ |
83 | 6 | return original.getSourceName(); |
84 | |
} |
85 | |
|
86 | |
public String getName() |
87 | |
{ |
88 | 23 | return original.getName(); |
89 | |
} |
90 | |
|
91 | |
public String getGroup() |
92 | |
{ |
93 | 5 | return original.getGroup(); |
94 | |
} |
95 | |
|
96 | |
public StackTraceWriter getStackTraceWriter() |
97 | |
{ |
98 | 2 | return original.getStackTraceWriter(); |
99 | |
} |
100 | |
|
101 | |
public String getMessage() |
102 | |
{ |
103 | 3 | return original.getMessage(); |
104 | |
} |
105 | |
|
106 | |
public String getStackTrace( boolean trimStackTrace ) |
107 | |
{ |
108 | 1 | StackTraceWriter writer = original.getStackTraceWriter(); |
109 | 1 | if ( writer == null ) |
110 | |
{ |
111 | 0 | return null; |
112 | |
} |
113 | 1 | return trimStackTrace ? writer.writeTrimmedTraceToString() : writer.writeTraceToString(); |
114 | |
} |
115 | |
|
116 | |
public String elapsedTimeAsString() |
117 | |
{ |
118 | 6 | return elapsedTimeAsString( getElapsed() ); |
119 | |
} |
120 | |
|
121 | |
String elapsedTimeAsString( long runTime ) |
122 | |
{ |
123 | 6 | return numberFormat.format( (double) runTime / MS_PER_SEC ); |
124 | |
} |
125 | |
|
126 | |
public String getReportName() |
127 | |
{ |
128 | 8 | final int i = getName().lastIndexOf( "(" ); |
129 | 8 | return i > 0 ? getName().substring( 0, i ) : getName(); |
130 | |
} |
131 | |
|
132 | |
public String getReportName( String suffix ) |
133 | |
{ |
134 | 2 | return suffix != null && suffix.length() > 0 ? getReportName() + "(" + suffix + ")" : getReportName(); |
135 | |
} |
136 | |
|
137 | |
public String getOutput( boolean trimStackTrace ) |
138 | |
{ |
139 | 0 | StringBuilder buf = new StringBuilder(); |
140 | |
|
141 | 0 | buf.append( getElapsedTimeSummary() ); |
142 | |
|
143 | 0 | buf.append( " <<< " ).append( getReportEntryType().toString().toUpperCase() ).append( "!" ).append( NL ); |
144 | |
|
145 | 0 | buf.append( getStackTrace( trimStackTrace ) ); |
146 | |
|
147 | 0 | return buf.toString(); |
148 | |
} |
149 | |
|
150 | |
public String getElapsedTimeSummary() |
151 | |
{ |
152 | 1 | StringBuilder reportContent = new StringBuilder(); |
153 | 1 | reportContent.append( getName() ); |
154 | 1 | reportContent.append( " Time elapsed: " ); |
155 | 1 | reportContent.append( elapsedTimeAsString() ); |
156 | 1 | reportContent.append( " sec" ); |
157 | |
|
158 | 1 | return reportContent.toString(); |
159 | |
} |
160 | |
|
161 | |
public boolean isErrorOrFailure() |
162 | |
{ |
163 | 0 | ReportEntryType thisType = getReportEntryType(); |
164 | 0 | return ReportEntryType.failure == thisType || ReportEntryType.error == thisType; |
165 | |
} |
166 | |
|
167 | |
public boolean isSkipped() |
168 | |
{ |
169 | 0 | return ReportEntryType.skipped == getReportEntryType(); |
170 | |
} |
171 | |
|
172 | |
public boolean isSucceeded() |
173 | |
{ |
174 | 0 | return ReportEntryType.success == getReportEntryType(); |
175 | |
} |
176 | |
|
177 | |
public String getNameWithGroup() |
178 | |
{ |
179 | 2 | return original.getNameWithGroup(); |
180 | |
} |
181 | |
} |