add config loading from stdin
This commit is contained in:
parent
0e44a91c37
commit
9a33129983
2 changed files with 19 additions and 5 deletions
|
@ -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<String> 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<String, String> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue