From 816820c4279033dd044e102db065e24e50dae790 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Thu, 21 Apr 2016 00:26:39 -0500 Subject: [PATCH] Use java system properties to find the user's home directory before looking to ENV properties. --- .../wdiwtlt/cli/CommandLineInterface.groovy | 12 ++++++++++-- .../com/jdbernard/wdiwtlt/ConfigWrapper.groovy | 13 +++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/cli/src/main/groovy/com/jdbernard/wdiwtlt/cli/CommandLineInterface.groovy b/cli/src/main/groovy/com/jdbernard/wdiwtlt/cli/CommandLineInterface.groovy index 781ec13..2ab3856 100644 --- a/cli/src/main/groovy/com/jdbernard/wdiwtlt/cli/CommandLineInterface.groovy +++ b/cli/src/main/groovy/com/jdbernard/wdiwtlt/cli/CommandLineInterface.groovy @@ -151,8 +151,13 @@ Configuration: if (!cfgFile || !cfgFile.exists() || !cfgFile.isFile()) cfgFile = new File("wdiwtlt.cli.properties") - if (!cfgFile || !cfgFile.exists() || !cfgFile.isFile()) - cfgFile = new File(System.getenv().HOME, ".wdiwtlt.cli.properties") + if (!cfgFile || !cfgFile.exists() || !cfgFile.isFile()) { + String userHome = System.getenv().HOME + if (userHome) cfgFile = new File(userHome, ".wdiwtlt.cli.properties") + + if (!cfgFile || !cfgFile.exists() || !cfgFile.isFile()) { + userHome = System.getProperty('user.home') + if (userHome) cfgFile = new File(userHome, 'wdiwtlt.cli.properties') } } if (cfgFile.exists() && cfgFile.isFile()) { try { cfgFile.withInputStream { givenCfg.load(it) } } @@ -273,6 +278,9 @@ Configuration: // Try to discover the VLC native libraries def vlcj try { + + String vlcLibDir = opts['--vlc-lib-dir'] || givenCfg['vlc.lib.dir'] + //if (vlcLibDir) NativeLibrary.addSearchPath('libvlc', vlcLibDir) new NativeDiscovery().discover() vlcj = new AudioMediaListPlayerComponent() } catch (Exception e) { diff --git a/core/src/main/groovy/com/jdbernard/wdiwtlt/ConfigWrapper.groovy b/core/src/main/groovy/com/jdbernard/wdiwtlt/ConfigWrapper.groovy index 1059f6f..4f0dcb2 100644 --- a/core/src/main/groovy/com/jdbernard/wdiwtlt/ConfigWrapper.groovy +++ b/core/src/main/groovy/com/jdbernard/wdiwtlt/ConfigWrapper.groovy @@ -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