1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.maven.surefire.api.booter;
20
21 /**
22 * Specifies the way how the forked jvm should be terminated after
23 * class AbstractCommandStream is closed and CTRL+C.
24 *
25 * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
26 * @since 2.19
27 */
28 public enum Shutdown {
29 DEFAULT("testset"),
30 EXIT("exit"),
31 KILL("kill");
32
33 private final String param;
34
35 Shutdown(String param) {
36 this.param = param;
37 }
38
39 public String getParam() {
40 return param;
41 }
42
43 public boolean isKill() {
44 return this == KILL;
45 }
46
47 public boolean isExit() {
48 return this == EXIT;
49 }
50
51 public boolean isDefaultShutdown() {
52 return this == DEFAULT;
53 }
54
55 public static boolean isKnown(String param) {
56 for (Shutdown shutdown : values()) {
57 if (shutdown.param.equals(param)) {
58 return true;
59 }
60 }
61 return false;
62 }
63
64 public static String listParameters() {
65 StringBuilder values = new StringBuilder();
66 for (Shutdown shutdown : values()) {
67 if (values.length() != 0) {
68 values.append(", ");
69 }
70 values.append(shutdown.getParam());
71 }
72 return values.toString();
73 }
74
75 public static Shutdown parameterOf(String parameter) {
76 for (Shutdown shutdown : values()) {
77 if (shutdown.param.equals(parameter)) {
78 return shutdown;
79 }
80 }
81 return DEFAULT;
82 }
83 }