-
Notifications
You must be signed in to change notification settings - Fork 531
/
WrappedReportEntry.java
237 lines (191 loc) · 7.2 KB
/
WrappedReportEntry.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.plugin.surefire.report;
import javax.annotation.Nonnull;
import java.text.MessageFormat;
import java.util.Collections;
import java.util.Locale;
import java.util.Map;
import org.apache.maven.surefire.api.report.ReportEntry;
import org.apache.maven.surefire.api.report.RunMode;
import org.apache.maven.surefire.api.report.StackTraceWriter;
import org.apache.maven.surefire.api.report.TestSetReportEntry;
import static java.util.Collections.unmodifiableMap;
import static org.apache.maven.surefire.api.util.internal.StringUtils.NL;
import static org.apache.maven.surefire.shared.utils.StringUtils.isBlank;
/**
* @author Kristian Rosenvold
*/
public class WrappedReportEntry implements TestSetReportEntry {
private static final float ONE_SECOND = 1000.0f;
private final ReportEntry original;
private final ReportEntryType reportEntryType;
private final Integer elapsed;
private final Utf8RecodingDeferredFileOutputStream stdout;
private final Utf8RecodingDeferredFileOutputStream stdErr;
private final Map<String, String> systemProperties;
/*
* Rationale: The idea is to always display four digits for visually consistent output
* Important: Keep in sync with maven-surefire-report-plugin/src/main/resources/surefire-report.properties
*/
private final MessageFormat elapsedTimeFormat = new MessageFormat(
"{0,choice,0#0|0.0<{0,number,0.000}|10#{0,number,0.00}|100#{0,number,0.0}|1000#{0,number,0}} s",
Locale.ROOT);
public WrappedReportEntry(
ReportEntry original,
ReportEntryType reportEntryType,
Integer estimatedElapsed,
Utf8RecodingDeferredFileOutputStream stdout,
Utf8RecodingDeferredFileOutputStream stdErr,
Map<String, String> systemProperties) {
this.original = original;
this.reportEntryType = reportEntryType;
this.elapsed = estimatedElapsed;
this.stdout = stdout;
this.stdErr = stdErr;
this.systemProperties = unmodifiableMap(systemProperties);
}
public WrappedReportEntry(
ReportEntry original,
ReportEntryType reportEntryType,
Integer estimatedElapsed,
Utf8RecodingDeferredFileOutputStream stdout,
Utf8RecodingDeferredFileOutputStream stdErr) {
this(original, reportEntryType, estimatedElapsed, stdout, stdErr, Collections.<String, String>emptyMap());
}
@Override
public Integer getElapsed() {
return elapsed;
}
@Override
public int getElapsed(int fallback) {
return elapsed == null ? fallback : elapsed;
}
public ReportEntryType getReportEntryType() {
return reportEntryType;
}
public Utf8RecodingDeferredFileOutputStream getStdout() {
return stdout;
}
public Utf8RecodingDeferredFileOutputStream getStdErr() {
return stdErr;
}
@Override
public String getSourceName() {
return original.getSourceName();
}
@Override
public String getSourceText() {
return original.getSourceText();
}
@Override
public String getName() {
return original.getName();
}
@Override
public String getNameText() {
return original.getNameText();
}
public String getClassMethodName() {
return original.getSourceName() + "." + original.getName();
}
@Override
public String getGroup() {
return original.getGroup();
}
@Override
public StackTraceWriter getStackTraceWriter() {
return original.getStackTraceWriter();
}
@Override
public String getMessage() {
return original.getMessage();
}
public String getStackTrace(boolean trimStackTrace) {
StackTraceWriter w = original.getStackTraceWriter();
return w == null ? null : (trimStackTrace ? w.writeTrimmedTraceToString() : w.writeTraceToString());
}
public String elapsedTimeAsString() {
return getElapsed() != null ? elapsedTimeFormat.format(new Object[] {getElapsed() / ONE_SECOND}) : null;
}
String getReportSourceName() {
String sourceName = getSourceName();
String sourceText = getSourceText();
return isBlank(sourceText) ? sourceName : sourceText;
}
String getReportSourceName(String suffix) {
return isBlank(suffix) ? getReportSourceName() : getReportSourceName() + "(" + suffix + ")";
}
String getSourceName(String suffix) {
return isBlank(suffix) ? getSourceName() : getSourceName() + "(" + suffix + ")";
}
String getReportName() {
String name = getName();
String nameText = getNameText();
return isBlank(nameText) ? name : nameText;
}
public String getOutput(boolean trimStackTrace) {
String outputLine =
getElapsedTimeSummary() + " <<< " + getReportEntryType().name() + "!";
String trimmedStackTrace = getStackTrace(trimStackTrace);
return trimmedStackTrace == null ? outputLine : outputLine + NL + trimmedStackTrace;
}
public String getElapsedTimeVerbose() {
return "Time elapsed: " + (getElapsed() != null ? elapsedTimeAsString() : "(unknown)");
}
public String getElapsedTimeSummary() {
String description = getName() == null ? getSourceName() : getClassMethodName();
return description + " -- " + getElapsedTimeVerbose();
}
public boolean isErrorOrFailure() {
ReportEntryType thisType = getReportEntryType();
return ReportEntryType.FAILURE == thisType || ReportEntryType.ERROR == thisType;
}
public boolean isSkipped() {
return ReportEntryType.SKIPPED == getReportEntryType();
}
public boolean isSucceeded() {
return ReportEntryType.SUCCESS == getReportEntryType();
}
@Override
public String getNameWithGroup() {
return original.getNameWithGroup();
}
@Override
public String getReportNameWithGroup() {
String reportNameWithGroup = original.getReportNameWithGroup();
if (isBlank(reportNameWithGroup)) {
return getNameWithGroup();
}
return reportNameWithGroup;
}
@Nonnull
@Override
public RunMode getRunMode() {
return original.getRunMode();
}
@Override
public Long getTestRunId() {
return original.getTestRunId();
}
@Override
public Map<String, String> getSystemProperties() {
return systemProperties;
}
}