aboutsummaryrefslogtreecommitdiffstats
path: root/policy-utils/src/main
diff options
context:
space:
mode:
authorLiam Fallon <liam.fallon@est.tech>2019-02-13 13:46:55 +0000
committerGerrit Code Review <gerrit@onap.org>2019-02-13 13:46:55 +0000
commit6683a08e12d119e1ba8fb1070a93660c0c3a3931 (patch)
tree2ecacb2d8c8e932c910528f5f5328802bac3e07d /policy-utils/src/main
parent504970756b35b5f9e5388ee32c53f83d659b4ef1 (diff)
parent897ba35f9c493b297f2a2d2a6d9dea743b7d39f8 (diff)
Merge "Support of environment variables in properties"
Diffstat (limited to 'policy-utils/src/main')
-rw-r--r--policy-utils/src/main/java/org/onap/policy/drools/utils/PropertyUtil.java20
1 files changed, 15 insertions, 5 deletions
diff --git a/policy-utils/src/main/java/org/onap/policy/drools/utils/PropertyUtil.java b/policy-utils/src/main/java/org/onap/policy/drools/utils/PropertyUtil.java
index c0014f4d..3891c858 100644
--- a/policy-utils/src/main/java/org/onap/policy/drools/utils/PropertyUtil.java
+++ b/policy-utils/src/main/java/org/onap/policy/drools/utils/PropertyUtil.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* policy-utils
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@ import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
+import org.apache.commons.configuration2.ConfigurationConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,8 +51,10 @@ public class PropertyUtil {
private static final Logger logger = LoggerFactory.getLogger(PropertyUtil.class.getName());
/**
- * Read in a properties file.
- *
+ * Read in a properties file. Variable interpolation is performed by using
+ * apache commons configuration2 library. This allows for embedding system properties,
+ * constants, and environment variables in property files.
+ *
* @param file the properties file
* @return a Properties object, containing the associated properties
* @throws IOException - subclass 'FileNotFoundException' if the file
@@ -60,14 +63,21 @@ public class PropertyUtil {
*/
public static Properties getProperties(File file) throws IOException {
// create an InputStream (may throw a FileNotFoundException)
+ Properties rval = new Properties();
try (FileInputStream fis = new FileInputStream(file)) {
// create the properties instance
- Properties rval = new Properties();
// load properties (may throw an IOException)
rval.load(fis);
- return rval;
}
+
+ /*
+ * Return properties file with environment variables interpolated.
+ * It is necessary to construct the object in this fashion and avoid
+ * builders since they use the commons-beanutils (optional) library that has been
+ * flagged as insecured.
+ */
+ return ConfigurationConverter.getProperties(ConfigurationConverter.getConfiguration(rval));
}
/**