Use java system properties to find the user's home directory before looking to ENV properties.

This commit is contained in:
Jonathan Bernard
2016-04-21 00:26:39 -05:00
parent 7bd9c64c44
commit 816820c427
2 changed files with 21 additions and 4 deletions

View File

@ -12,10 +12,15 @@ public class ConfigWrapper {
public ConfigWrapper() {
if (env.WDIWTLT_CONFIG_FILE) {
if (tryLoadConfigFile(new File(env.WDIWTLT_CONFIG_FILE))) {
if (tryLoadConfigFile(env.WDIWTLT_CONFIG_FILE)) {
return } }
if (tryLoadConfigFile(new File(env.HOME, ".wdiwtlt.properties"))) return
if (env.HOME &&
tryLoadConfigFile(new File(env.HOME, ".wdiwtlt.properties"))) return
String userHome = System.getProperty('user.home')
if (userHome &&
tryLoadConfigFile(new File(userHome, '.wdiwtlt.properties'))) return
try {
ConfigWrapper.getResourceAsStream("/com/jdbernard/wdiwtlt/db/default.properties")
@ -68,6 +73,10 @@ public class ConfigWrapper {
if (props) return new HikariConfig(props)
else return null }
private boolean tryLoadConfigFile(String configFilePath) {
if (!configFilePath) return false
return tryLoadConfigFile(new File(configFilePath)) }
private boolean tryLoadConfigFile(File configFile) {
if (!configFile.exists() || !configFile.isFile()) return false