-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
ConfigLoader.java
33 lines (26 loc) · 987 Bytes
/
ConfigLoader.java
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
package nu.marginalia.service;
import nu.marginalia.WmsaHome;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
public class ConfigLoader {
private static final Logger logger = LoggerFactory.getLogger(ConfigLoader.class);
static Path getConfigPath(String configName) {
return WmsaHome.getHomePath().resolve("conf/properties/" + configName + ".properties");
}
static void loadConfig(Path configPath) {
if (!Files.exists(configPath)) {
logger.info("No config file found at {}", configPath);
return;
}
logger.info("Loading config from {}", configPath);
try (var is = Files.newInputStream(configPath)) {
logger.info("Config:\n{}", Files.readString(configPath));
System.getProperties().load(is);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}