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