1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.basepom.mojo.propertyhelper;
16
17 import static com.google.common.base.Preconditions.checkNotNull;
18
19 import java.util.Locale;
20 import java.util.function.Supplier;
21
22 import com.google.common.flogger.FluentLogger;
23
24 public enum IgnoreWarnFail {
25 IGNORE, WARN, FAIL;
26
27 private static final FluentLogger LOG = FluentLogger.forEnclosingClass();
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.getDefault()));
32 }
33
34
35
36
37
38
39
40
41
42
43
44
45
46 public static boolean checkIgnoreWarnFailState(final boolean check, final IgnoreWarnFail iwf,
47 final Supplier<String> checkMessage, final Supplier<String> errorMessage) {
48
49 if (check) {
50 LOG.atFine().log(checkMessage.get());
51 return true;
52 }
53
54 switch (iwf) {
55 case IGNORE:
56 LOG.atFine().log(errorMessage.get());
57 break;
58 case WARN:
59 LOG.atWarning().log(errorMessage.get());
60 break;
61 case FAIL:
62 throw new IllegalStateException(errorMessage.get());
63 default:
64 throw new IllegalStateException("Unknown state: " + iwf);
65 }
66
67 return false;
68 }
69 }