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