1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.basepom.mojo.propertyhelper.beans;
16
17 import static com.google.common.base.Preconditions.checkNotNull;
18 import static java.lang.String.format;
19
20 import org.basepom.mojo.propertyhelper.util.Log;
21
22 import java.util.Locale;
23
24 public enum IgnoreWarnFail {
25 IGNORE, WARN, FAIL;
26
27 private static final Log LOG = Log.findLog();
28
29 public static IgnoreWarnFail forString(final String value) {
30 checkNotNull(value, "the value can not be null");
31 return Enum.valueOf(IgnoreWarnFail.class, value.toUpperCase(Locale.ENGLISH));
32 }
33
34
35
36
37
38
39
40
41
42 public static void checkState(final IgnoreWarnFail iwf, final boolean exists, final String thing) {
43 if (exists) {
44 return;
45 }
46
47 switch (iwf) {
48 case IGNORE:
49 return;
50 case WARN:
51 LOG.warn("'%s' does not exist!", thing);
52 break;
53 case FAIL:
54 throw new IllegalStateException(format("'%s' does not exist!", thing));
55 default:
56 throw new IllegalStateException("Unknown state: " + iwf);
57 }
58 }
59 }