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.checkArgument;
18 import static java.lang.String.format;
19
20 import org.basepom.mojo.propertyhelper.util.Log;
21
22 import java.util.Locale;
23 import javax.annotation.Nonnull;
24
25 public enum IgnoreWarnFailCreate {
26 IGNORE, WARN, FAIL, CREATE;
27
28 private static final Log LOG = Log.findLog();
29
30 public static IgnoreWarnFailCreate forString(final String value) {
31 checkArgument(value != null, "the value can not be null");
32 return Enum.valueOf(IgnoreWarnFailCreate.class, value.toUpperCase(Locale.ENGLISH));
33 }
34
35
36
37
38
39
40
41
42
43 public static boolean checkState(@Nonnull final IgnoreWarnFailCreate iwfc, final boolean exists, final String thing) {
44 if (exists) {
45 return false;
46 }
47
48 switch (iwfc) {
49 case IGNORE:
50 return false;
51 case WARN:
52 LOG.warn("'%s' does not exist!", thing);
53 return false;
54 case FAIL:
55 throw new IllegalStateException(format("'%s' does not exist!", thing));
56 case CREATE:
57 LOG.debug("'%s' does not exist, suggesting creation.", thing);
58 return true;
59 default:
60 throw new IllegalStateException("Unknown state: " + iwfc);
61 }
62 }
63 }