From 9a33129983b9bf6d33f7bcbbbcbd81a0c827e4df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Wed, 10 Feb 2021 15:34:34 +0100 Subject: [PATCH] add config loading from stdin --- .../org/xbib/content/config/ConfigLoader.java | 20 ++++++++++++++++--- gradle.properties | 4 ++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/content-config/src/main/java/org/xbib/content/config/ConfigLoader.java b/content-config/src/main/java/org/xbib/content/config/ConfigLoader.java index de089f2..478d930 100644 --- a/content-config/src/main/java/org/xbib/content/config/ConfigLoader.java +++ b/content-config/src/main/java/org/xbib/content/config/ConfigLoader.java @@ -38,8 +38,12 @@ public class ConfigLoader { public Settings.Builder loadSettings(ClassLoader classLoader, String applicationName, String... fileNamesWithoutSuffix) throws IOException { + Settings.Builder settings = createSettingsFromStdin(); + if (settings != null) { + return overrideFromProperties(applicationName, settings); + } for (String fileNameWithoutSuffix : fileNamesWithoutSuffix) { - Settings.Builder settings = createSettingsFromFile(createListOfLocations(applicationName, fileNameWithoutSuffix)); + settings = createSettingsFromFile(createListOfLocations(applicationName, fileNameWithoutSuffix)); if (settings != null) { return overrideFromProperties(applicationName, settings); } @@ -59,6 +63,17 @@ public class ConfigLoader { Arrays.asList(fileNamesWithoutSuffix)); } + private Settings.Builder createSettingsFromStdin() throws IOException { + if (System.in != null) { + int numBytesWaiting = System.in.available(); + if (numBytesWaiting > 0) { + String suffix = System.getProperty("config.format", "yaml"); + return createSettingsFromStream(System.in, "." + suffix); + } + } + return null; + } + private Settings.Builder createSettingsFromFile(List settingsFileNames) throws IOException { for (String settingsFileName: settingsFileNames) { int pos = settingsFileName.lastIndexOf('.'); @@ -112,12 +127,11 @@ public class ConfigLoader { return null; } - private Settings.Builder overrideFromProperties(String applicationName, Settings.Builder settings) { + private static Settings.Builder overrideFromProperties(String applicationName, Settings.Builder settings) { for (Map.Entry entry : settings.map().entrySet()) { String key = entry.getKey(); String value = System.getProperty(applicationName + '.' + key); if (value != null) { - logger.warn("overriding " + key + " with " + value); settings.put(key, value); } } diff --git a/gradle.properties b/gradle.properties index f7b7fd2..a07df56 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,11 +1,11 @@ group = org.xbib name = content -version = 2.6.2 +version = 2.6.3 gradle.wrapper.version = 6.6.1 xbib.net.version = 2.1.0 xbib-datastructures-tiny.version = 0.0.3 -jackson.version = 2.11.3 +jackson.version = 2.11.4 woodstox.version = 6.2.1 snakeyaml.version = 1.27 mockito.version = 3.5.13