summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSmokowski, Kevin (ks6305) <ks6305@att.com>2018-03-09 21:05:19 +0000
committerKevin Smokowski <ks6305@att.com>2018-03-09 21:39:28 +0000
commit52769e979a907fbd862789c973ba29e644931954 (patch)
treed015bb387e1eb6a6fcf475568e89922bd594eb12
parent6cea464120223c13d7d6e48f422d9964d14c8c8d (diff)
Check system property before environment variable
Allow system property to take precedence over environment variable when searching for the properties file Change-Id: I1c6f7099551d814ca388f4694a0bb24409a7167b Issue-ID: CCSDK-209 Signed-off-by: Smokowski, Kevin (ks6305) <ks6305@att.com>
-rwxr-xr-xutils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/EnvVarFileResolver.java12
1 files changed, 9 insertions, 3 deletions
diff --git a/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/EnvVarFileResolver.java b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/EnvVarFileResolver.java
index 5e87412a..669b3992 100755
--- a/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/EnvVarFileResolver.java
+++ b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/EnvVarFileResolver.java
@@ -28,7 +28,7 @@ import java.util.Optional;
/**
* Resolves properties files relative to the directory identified by the <code>SDNC_CONFIG_DIR</code>
- * environment variable.
+ * environment variable. If a system property with the same name is set it is given precedence.
*/
public abstract class EnvVarFileResolver implements PropertiesFileResolver {
@@ -51,8 +51,14 @@ public abstract class EnvVarFileResolver implements PropertiesFileResolver {
*/
@Override
public Optional<File> resolveFile(final String filename) {
- // attempt to resolve the property directory from the corresponding environment variable
- final String propDirectoryFromEnvVariable = System.getenv(propertyKey);
+ // attempt to read the system property first
+ String propDirectoryFromEnvVariable = System.getProperty(propertyKey);
+
+ if(propDirectoryFromEnvVariable == null) {
+ // attempt to resolve the property directory from the corresponding environment variable
+ propDirectoryFromEnvVariable = System.getenv(propertyKey);
+ }
+
final File fileFromEnvVariable;
if (!Strings.isNullOrEmpty(propDirectoryFromEnvVariable)) {
fileFromEnvVariable = Paths.get(propDirectoryFromEnvVariable).resolve(filename).toFile();