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.MojoFailureException;
23 import org.apache.maven.plugin.logging.Log;
24 import org.apache.maven.surefire.booter.ProviderConfiguration;
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 {
38 throw new IllegalAccessError( "Utility class" );
39 }
40
41
42
43 public static void reportExecution( SurefireReportParameters reportParameters, RunResult result, Log log )
44 throws MojoFailureException
45 {
46
47 String msg;
48
49
50
51
52 if ( result.getCompletedCount() == 0 )
53 {
54 if ( ( reportParameters.getFailIfNoTests() == null )
55 || !reportParameters.getFailIfNoTests().booleanValue() )
56 {
57 return;
58 }
59
60 throw new MojoFailureException(
61 "No tests were executed! (Set -DfailIfNoTests=false to ignore this error.)" );
62 }
63
64 if ( result.isErrrorFree() )
65 {
66 return;
67 }
68
69 if ( result.isFailureOrTimeout() )
70 {
71 msg = "There was a timeout or other error in the fork";
72 }
73 else
74 {
75
76 msg = "There are test failures.\n\nPlease refer to " + reportParameters.getReportsDirectory()
77 + " for the individual test results.";
78
79 }
80
81 if ( reportParameters.isTestFailureIgnore() )
82 {
83 log.error( msg );
84 }
85 else
86 {
87 throw new MojoFailureException( msg );
88 }
89 }
90
91 public static void reportExecution( SurefireReportParameters reportParameters, int result, Log log )
92 throws MojoFailureException
93 {
94 if ( result == 0 )
95 {
96 return;
97 }
98
99 String msg;
100
101 if ( result == ProviderConfiguration.NO_TESTS_EXIT_CODE )
102 {
103 if ( ( reportParameters.getFailIfNoTests() == null )
104 || !reportParameters.getFailIfNoTests().booleanValue() )
105 {
106 return;
107 }
108
109 throw new MojoFailureException(
110 "No tests were executed! (Set -DfailIfNoTests=false to ignore this error.)" );
111 }
112 else
113 {
114
115 msg = "There are test failures.\n\nPlease refer to " + reportParameters.getReportsDirectory()
116 + " for the individual test results.";
117
118 }
119
120 if ( reportParameters.isTestFailureIgnore() )
121 {
122 log.error( msg );
123 }
124 else
125 {
126 throw new MojoFailureException( msg );
127 }
128 }
129
130 }