1 | |
package org.apache.maven.plugin.surefire; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import org.apache.maven.plugin.MojoExecutionException; |
23 | |
import org.apache.maven.plugin.MojoFailureException; |
24 | |
import org.apache.maven.plugin.logging.Log; |
25 | |
import org.apache.maven.surefire.suite.RunResult; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
public final class SurefireHelper |
31 | |
{ |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
private SurefireHelper() |
37 | 0 | { |
38 | 0 | throw new IllegalAccessError( "Utility class" ); |
39 | |
} |
40 | |
|
41 | |
public static void reportExecution( SurefireReportParameters reportParameters, RunResult result, Log log ) |
42 | |
throws MojoFailureException, MojoExecutionException |
43 | |
{ |
44 | |
|
45 | 0 | boolean timeoutOrOtherFailure = result.isFailureOrTimeout(); |
46 | |
|
47 | 0 | if ( !timeoutOrOtherFailure ) |
48 | |
{ |
49 | 0 | if ( result.getCompletedCount() == 0 ) |
50 | |
{ |
51 | 0 | if ( ( reportParameters.getFailIfNoTests() == null ) || !reportParameters.getFailIfNoTests() ) |
52 | |
{ |
53 | 0 | return; |
54 | |
} |
55 | 0 | throw new MojoFailureException( |
56 | |
"No tests were executed! (Set -DfailIfNoTests=false to ignore this error.)" ); |
57 | |
} |
58 | |
|
59 | 0 | if ( result.isErrorFree() ) |
60 | |
{ |
61 | 0 | return; |
62 | |
} |
63 | |
} |
64 | |
|
65 | 0 | String msg = timeoutOrOtherFailure |
66 | |
? "There was a timeout or other error in the fork" |
67 | |
: "There are test failures.\n\nPlease refer to " + reportParameters.getReportsDirectory() |
68 | |
+ " for the individual test results."; |
69 | |
|
70 | 0 | if ( reportParameters.isTestFailureIgnore() ) |
71 | |
{ |
72 | 0 | log.error( msg ); |
73 | |
} |
74 | |
else |
75 | |
{ |
76 | 0 | if ( result.isFailure() ) |
77 | |
{ |
78 | 0 | throw new MojoExecutionException( msg ); |
79 | |
} |
80 | |
else |
81 | |
{ |
82 | 0 | throw new MojoFailureException( msg ); |
83 | |
} |
84 | |
} |
85 | 0 | } |
86 | |
|
87 | |
} |