cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ko...@apache.org
Subject [02/11] git commit: updated refs/heads/master to 31db58f
Date Sun, 23 Nov 2014 19:49:10 GMT
Simplification on Properties handling

- Added method to create properties and load contents from file

Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/b2023d04
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/b2023d04
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/b2023d04

Branch: refs/heads/master
Commit: b2023d04ba22f6703c1853f8e5ad4df7dbc9c858
Parents: ca9dd45
Author: Laszlo Hornyak <laszlo.hornyak@gmail.com>
Authored: Wed Feb 26 22:20:18 2014 +0100
Committer: Laszlo Hornyak <laszlo.hornyak@gmail.com>
Committed: Sun Nov 23 19:48:56 2014 +0100

----------------------------------------------------------------------
 .../kvm/resource/LibvirtComputingResource.java         |  3 +--
 .../xenserver/resource/CitrixResourceBase.java         |  5 ++---
 .../xenserver/resource/XenServerConnectionPool.java    |  7 +------
 .../test/com/cloud/network/nicira/NiciraNvpApiIT.java  |  3 +--
 utils/src/com/cloud/utils/ProcessUtil.java             |  3 +--
 utils/src/com/cloud/utils/PropertiesUtil.java          | 13 +++++++++++++
 utils/src/com/cloud/utils/script/Script.java           |  5 +----
 utils/test/com/cloud/utils/PropertiesUtilsTest.java    |  8 ++++++++
 8 files changed, 28 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b2023d04/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
index fc6504f..d22487a 100755
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
@@ -509,9 +509,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements
Serv
         }
 
         s_logger.info("developer.properties found at " + file.getAbsolutePath());
-        Properties properties = new Properties();
         try {
-            PropertiesUtil.loadFromFile(properties, file);
+            Properties properties = PropertiesUtil.loadFromFile(file);
 
             String startMac = (String)properties.get("private.macaddr.start");
             if (startMac == null) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b2023d04/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java
index b275fb4..19919d7 100644
--- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java
@@ -18,7 +18,6 @@ package com.cloud.hypervisor.xenserver.resource;
 
 import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -234,6 +233,7 @@ import com.cloud.template.VirtualMachineTemplate.BootloaderType;
 import com.cloud.utils.ExecutionResult;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.Pair;
+import com.cloud.utils.PropertiesUtil;
 import com.cloud.utils.StringUtils;
 import com.cloud.utils.Ternary;
 import com.cloud.utils.exception.CloudRuntimeException;
@@ -4705,8 +4705,7 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
                 }
                 for (File file : files) {
                     String path = file.getParentFile().getAbsolutePath() + "/";
-                    Properties props = new Properties();
-                    props.load(new FileInputStream(file));
+                    Properties props = PropertiesUtil.loadFromFile(file);
 
                     for (Map.Entry<Object, Object> entry : props.entrySet()) {
                         String k = (String)entry.getKey();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b2023d04/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServerConnectionPool.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServerConnectionPool.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServerConnectionPool.java
index d4360cf..762c6dc 100644
--- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServerConnectionPool.java
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServerConnectionPool.java
@@ -17,7 +17,6 @@
 package com.cloud.hypervisor.xenserver.resource;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.net.URL;
@@ -61,12 +60,8 @@ public class XenServerConnectionPool {
         if (file == null) {
             s_logger.debug("Unable to find environment.properties");
         } else {
-            FileInputStream finputstream;
             try {
-                finputstream = new FileInputStream(file);
-                final Properties props = new Properties();
-                props.load(finputstream);
-                finputstream.close();
+                final Properties props = PropertiesUtil.loadFromFile(file);
                 String search = props.getProperty("sleep.interval.on.error");
                 if (search != null) {
                     s_sleepOnError = NumbersUtil.parseInterval(search, 10) * 1000;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b2023d04/plugins/network-elements/nicira-nvp/test/com/cloud/network/nicira/NiciraNvpApiIT.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/test/com/cloud/network/nicira/NiciraNvpApiIT.java
b/plugins/network-elements/nicira-nvp/test/com/cloud/network/nicira/NiciraNvpApiIT.java
index ec4ce09..3bb4b9d 100644
--- a/plugins/network-elements/nicira-nvp/test/com/cloud/network/nicira/NiciraNvpApiIT.java
+++ b/plugins/network-elements/nicira-nvp/test/com/cloud/network/nicira/NiciraNvpApiIT.java
@@ -41,8 +41,7 @@ public class NiciraNvpApiIT {
 
     @Before
     public void setup() throws IOException {
-        final Properties properties = new Properties();
-        PropertiesUtil.loadFromFile(properties, PropertiesUtil.findConfigFile("config.properties"));
+        final Properties properties = PropertiesUtil.loadFromFile(PropertiesUtil.findConfigFile("config.properties"));
         api = new NiciraNvpApi();
         api.setControllerAddress(properties.getProperty("nvp.host"));
         api.setAdminCredentials(properties.getProperty("nvp.admin.user"),

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b2023d04/utils/src/com/cloud/utils/ProcessUtil.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/ProcessUtil.java b/utils/src/com/cloud/utils/ProcessUtil.java
index f6859d6..53137c4 100644
--- a/utils/src/com/cloud/utils/ProcessUtil.java
+++ b/utils/src/com/cloud/utils/ProcessUtil.java
@@ -45,8 +45,7 @@ public class ProcessUtil {
             if (propsFile == null) {
                 s_logger.debug("environment.properties could not be opened");
             } else {
-                final Properties props = new Properties();
-                PropertiesUtil.loadFromFile(props, propsFile);
+                final Properties props = PropertiesUtil.loadFromFile(propsFile);
                 dir = props.getProperty("paths.pid");
                 if (dir == null) {
                     dir = pidDir == null ? "/var/run" : pidDir;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b2023d04/utils/src/com/cloud/utils/PropertiesUtil.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/PropertiesUtil.java b/utils/src/com/cloud/utils/PropertiesUtil.java
index 608ef09..1375463 100755
--- a/utils/src/com/cloud/utils/PropertiesUtil.java
+++ b/utils/src/com/cloud/utils/PropertiesUtil.java
@@ -175,4 +175,17 @@ public class PropertiesUtil {
         }
     }
 
+    /**
+     * Load the file and return the contents as a Properties object.
+     * @param file  the file to load
+     * @return      A Properties object populated
+     * @throws IOException
+     */
+    public static Properties loadFromFile(final File file)
+            throws IOException {
+        final Properties properties = new Properties();
+        loadFromFile(properties, file);
+        return properties;
+    }
+    
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b2023d04/utils/src/com/cloud/utils/script/Script.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/script/Script.java b/utils/src/com/cloud/utils/script/Script.java
index 49734ae..b8a8668 100755
--- a/utils/src/com/cloud/utils/script/Script.java
+++ b/utils/src/com/cloud/utils/script/Script.java
@@ -414,10 +414,7 @@ public class Script implements Callable<String> {
                     if (propsFile == null) {
                         s_logger.debug("environment.properties could not be opened");
                     } else {
-                        final FileInputStream finputstream = new FileInputStream(propsFile);
-                        final Properties props = new Properties();
-                        props.load(finputstream);
-                        finputstream.close();
+                        final Properties props = PropertiesUtil.loadFromFile(propsFile);
                         search = props.getProperty("paths.script");
                     }
                 } catch (IOException e) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b2023d04/utils/test/com/cloud/utils/PropertiesUtilsTest.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/PropertiesUtilsTest.java b/utils/test/com/cloud/utils/PropertiesUtilsTest.java
index 84ad523a..e20d7bf 100644
--- a/utils/test/com/cloud/utils/PropertiesUtilsTest.java
+++ b/utils/test/com/cloud/utils/PropertiesUtilsTest.java
@@ -45,6 +45,14 @@ public class PropertiesUtilsTest {
     }
 
     @Test
+    public void loadPropertiesFromFile() throws IOException {
+        File file = File.createTempFile("test", ".properties");
+        FileUtils.writeStringToFile(file, "a=b\nc=d\n");
+        Properties properties = PropertiesUtil.loadFromFile(file);
+        Assert.assertEquals("b", properties.get("a"));
+    }
+
+    @Test
     public void processConfigFile() throws IOException {
         File tempFile = File.createTempFile("temp", ".properties");
         FileUtils.writeStringToFile(tempFile, "a=b\nc=d\n");


Mime
View raw message