1 package org.apache.maven.plugin.surefire;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
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
26 /**
27 * Helper class for surefire plugins
28 */
29 public final class SurefireHelper
30 {
31
32 /**
33 * Do not instantiate.
34 */
35 private SurefireHelper()
36 {
37 throw new IllegalAccessError( "Utility class" );
38 }
39
40 public static void reportExecution( SurefireReportParameters reportParameters, int result, Log log )
41 throws MojoFailureException
42 {
43 if ( result == 0 )
44 {
45 return;
46 }
47
48 String msg;
49
50 if ( result == ProviderConfiguration.NO_TESTS_EXIT_CODE )
51 {
52 if ( ( reportParameters.getFailIfNoTests() == null ) || !reportParameters.getFailIfNoTests().booleanValue() )
53 {
54 return;
55 }
56 // TODO: i18n
57 throw new MojoFailureException(
58 "No tests were executed! (Set -DfailIfNoTests=false to ignore this error.)" );
59 }
60 else
61 {
62 // TODO: i18n
63 msg = "There are test failures.\n\nPlease refer to " + reportParameters.getReportsDirectory()
64 + " for the individual test results.";
65
66 }
67
68 if ( reportParameters.isTestFailureIgnore() )
69 {
70 log.error( msg );
71 }
72 else
73 {
74 throw new MojoFailureException( msg );
75 }
76 }
77 }