blob: 2091496dee3dc781e9367ba60fb0b1386da2599e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
/*
* Copyright (C) 2022 NotEnoughUpdates contributors
*
* This file is part of NotEnoughUpdates.
*
* NotEnoughUpdates is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* NotEnoughUpdates is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
*/
package io.github.moulberry.notenoughupdates;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
/**
* For storage of compile-time configuration flags
*/
public class BuildFlags {
private static final Properties properties = new Properties();
static {
try {
properties.load(BuildFlags.class.getResourceAsStream("/buildflags.properties"));
} catch (IOException | NullPointerException e) {
System.out.println("Failed to load build properties: " + e);
}
}
private static boolean getBuildFlag(String flag) {
return Boolean.parseBoolean(properties.getProperty("neu.buildflags." + flag));
}
public static Map<String, Boolean> getAllFlags() {
return Holder.ALL_FLAGS;
}
public static final boolean ENABLE_PRONOUNS_IN_PV_BY_DEFAULT = getBuildFlag("pronouns");
public static final boolean ENABLE_ONECONFIG_COMPAT_LAYER = getBuildFlag("oneconfig");
private static class Holder {
static Map<String, Boolean> ALL_FLAGS = new HashMap<>();
static {
for (Field declaredField : BuildFlags.class.getDeclaredFields()) {
if (Boolean.TYPE.equals(declaredField.getType())
&& (declaredField.getModifiers() & Modifier.STATIC) != 0) {
try {
declaredField.setAccessible(true);
ALL_FLAGS.put(declaredField.getName(), (Boolean) declaredField.get(null));
} catch (IllegalAccessException | ClassCastException | SecurityException e) {
System.err.println("Failed to access BuildFlag: " + e);
}
}
}
}
}
}
|