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.checkArgument;
18
19 import java.util.Locale;
20 import java.util.function.Supplier;
21
22 import com.google.common.flogger.FluentLogger;
23
24 public enum IgnoreWarnFailCreate {
25 IGNORE, WARN, FAIL, CREATE;
26
27 private static final FluentLogger LOG = FluentLogger.forEnclosingClass();
28
29 public static IgnoreWarnFailCreate forString(final String value) {
30 checkArgument(value != null, "the value can not be null");
31 return Enum.valueOf(IgnoreWarnFailCreate.class, value.toUpperCase(Locale.getDefault()));
32 }
33
34 public static boolean checkIgnoreWarnFailCreateState(final boolean check, final IgnoreWarnFailCreate iwfc,
35 final Supplier<String> checkMessage, final Supplier<String> errorMessage) {
36
37 if (check) {
38 LOG.atFine().log(checkMessage.get());
39 return false;
40 }
41
42 switch (iwfc) {
43 case IGNORE:
44 return false;
45 case WARN:
46 LOG.atWarning().log(errorMessage.get());
47 return false;
48 case FAIL:
49 throw new IllegalStateException(errorMessage.get());
50 case CREATE:
51 LOG.atFine().log(errorMessage.get());
52 return true;
53 default:
54 throw new IllegalStateException("Unknown state: " + iwfc);
55 }
56 }
57 }