aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/BuildFlags.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/BuildFlags.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/BuildFlags.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/BuildFlags.java b/src/main/java/io/github/moulberry/notenoughupdates/BuildFlags.java
new file mode 100644
index 00000000..d997d980
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/BuildFlags.java
@@ -0,0 +1,72 @@
+/*
+ * 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");
+
+ 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);
+ }
+ }
+ }
+ }
+ }
+
+}