1 package org.apache.maven.surefire.booter;
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 /**
23 * Specifies the way how the forked jvm should be terminated after
24 * class AbstractCommandStream is closed and CTRL+C.
25 *
26 * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
27 * @since 2.19
28 */
29 public enum Shutdown
30 {
31 DEFAULT( "testset" ),
32 EXIT( "exit" ),
33 KILL( "kill" );
34
35 private final String param;
36
37 Shutdown( String param )
38 {
39 this.param = param;
40 }
41
42 public String getParam()
43 {
44 return param;
45 }
46
47 public boolean isKill()
48 {
49 return this == KILL;
50 }
51
52 public boolean isExit()
53 {
54 return this == EXIT;
55 }
56
57 public boolean isDefaultShutdown()
58 {
59 return this == DEFAULT;
60 }
61
62 public static boolean isKnown( String param )
63 {
64 for ( Shutdown shutdown : values() )
65 {
66 if ( shutdown.param.equals( param ) )
67 {
68 return true;
69 }
70 }
71 return false;
72 }
73
74 public static String listParameters()
75 {
76 StringBuilder values = new StringBuilder();
77 for ( Shutdown shutdown : values() )
78 {
79 if ( values.length() != 0 )
80 {
81 values.append( ", " );
82 }
83 values.append( shutdown.getParam() );
84 }
85 return values.toString();
86 }
87
88 public static Shutdown parameterOf( String parameter )
89 {
90 for ( Shutdown shutdown : values() )
91 {
92 if ( shutdown.param.equals( parameter ) )
93 {
94 return shutdown;
95 }
96 }
97 return DEFAULT;
98 }
99 }