diff options
| author | Lorenz <lo.scherf@gmail.com> | 2022-09-04 09:10:07 +0200 |
|---|---|---|
| committer | Lorenz <lo.scherf@gmail.com> | 2022-09-04 09:10:07 +0200 |
| commit | 05ac31a02857d1baf94c0db26663e33e388b9165 (patch) | |
| tree | 9858b7c993e1ddd49ed90639735c597cc0b97295 /src/main/java | |
| parent | 2056ee7e6c92c4aff32b55501bc72f4ee9b63861 (diff) | |
| parent | 3ba2db73995fddf6dd1657eefe9f86a815983e27 (diff) | |
| download | NotEnoughUpdates-05ac31a02857d1baf94c0db26663e33e388b9165.tar.gz NotEnoughUpdates-05ac31a02857d1baf94c0db26663e33e388b9165.tar.bz2 NotEnoughUpdates-05ac31a02857d1baf94c0db26663e33e388b9165.zip | |
merges from master
Diffstat (limited to 'src/main/java')
90 files changed, 9014 insertions, 6308 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); + } |
