1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.surefire.booter;
20
21 import org.apache.maven.surefire.api.suite.RunResult;
22
23 import static org.apache.maven.surefire.shared.utils.StringUtils.isNotBlank;
24
25
26
27
28 public class SurefireBooterForkException extends Exception {
29 public SurefireBooterForkException(String message, RunResult runResult) {
30 this(message, null, null, runResult);
31 }
32
33 public SurefireBooterForkException(
34 String message, String rethrownMessage, Throwable rethrownCause, RunResult runResult) {
35 super(toString(message, rethrownMessage, rethrownCause, runResult), rethrownCause);
36 }
37
38 public SurefireBooterForkException(String message, Throwable cause) {
39 super(message, cause);
40 }
41
42 public SurefireBooterForkException(String msg) {
43 super(msg);
44 }
45
46 private static String toString(
47 String message, String rethrownMessage, Throwable rethrownCause, RunResult runResult) {
48 return toNewLines(
49 message,
50 rethrownMessage,
51 rethrownCause == null ? null : rethrownCause.getLocalizedMessage(),
52 runResult == null ? null : runResult.getFailure(),
53 runResult == null ? null : toString(runResult));
54 }
55
56 private static String toString(RunResult runResult) {
57 return "Fatal Tests run: " + runResult.getCompletedCount()
58 + ", Failures: " + runResult.getFailures()
59 + ", Errors: " + runResult.getErrors()
60 + ", Skipped: " + runResult.getSkipped()
61 + ", Flakes: " + runResult.getFlakes()
62 + ", Elapsed timeout: " + runResult.isTimeout();
63 }
64
65 private static String toNewLines(String... messages) {
66 StringBuilder result = new StringBuilder();
67 for (String message : messages) {
68 if (isNotBlank(message)) {
69 if (result.length() == 0) {
70 result.append('\n');
71 }
72 result.append(message);
73 }
74 }
75 return result.toString();
76 }
77 }