cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahu...@apache.org
Subject [35/50] [abbrv] git commit: updated refs/heads/vmsync to e2edae1
Date Tue, 18 Jun 2013 03:07:00 GMT
use commons-lang StringUtils

commons-lang is already a transitive dependency of the utils project, which allows removing
some duplicated functionality.
This patch replaces StringUtils.join(String, Object...) with it's commons-lang counterpart.
It also replaces calls to String join(Iterable<? extends Object>, String) in cases where
an array is already exist and it is only wrapped into a List.

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/c88d8fb3
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/c88d8fb3
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/c88d8fb3

Branch: refs/heads/vmsync
Commit: c88d8fb3a2f6c418c6c7af8ff702a93bcdb2d752
Parents: 564013b
Author: Laszlo Hornyak <laszlo.hornyak@gmail.com>
Authored: Sun Jun 9 21:40:28 2013 +0200
Committer: Chip Childers <chip.childers@gmail.com>
Committed: Mon Jun 17 19:17:22 2013 +0100

----------------------------------------------------------------------
 .../src/com/cloud/storage/s3/S3ManagerImpl.java  | 10 +++-------
 .../resource/NfsSecondaryStorageResource.java    | 19 ++++++-------------
 utils/src/com/cloud/utils/S3Utils.java           |  4 ++--
 utils/src/com/cloud/utils/StringUtils.java       |  6 +-----
 utils/test/com/cloud/utils/StringUtilsTest.java  |  5 +++++
 5 files changed, 17 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c88d8fb3/server/src/com/cloud/storage/s3/S3ManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/s3/S3ManagerImpl.java b/server/src/com/cloud/storage/s3/S3ManagerImpl.java
index 61e5573..91fa9c3 100644
--- a/server/src/com/cloud/storage/s3/S3ManagerImpl.java
+++ b/server/src/com/cloud/storage/s3/S3ManagerImpl.java
@@ -41,7 +41,6 @@ import java.util.Map;
 import java.util.UUID;
 import java.util.concurrent.Callable;
 
-import javax.annotation.PostConstruct;
 import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
@@ -193,13 +192,12 @@ public class S3ManagerImpl extends ManagerBase implements S3Manager
{
 
     }
 
-    @SuppressWarnings("unchecked")
-    private String determineLockId(final long accountId, final long templateId) {
+    static String determineLockId(final long accountId, final long templateId) {
 
         // TBD The lock scope may be too coarse grained. Deletes need to lock
         // the template across all zones where upload and download could
         // probably safely scoped to the zone ...
-        return join(asList("S3_TEMPLATE", accountId, templateId), "_");
+        return join("_", "S3_TEMPLATE", accountId, templateId);
 
     }
 
@@ -397,9 +395,7 @@ public class S3ManagerImpl extends ManagerBase implements S3Manager {
                         throw new CloudRuntimeException(errMsg);
                     }
 
-                    final String installPath = join(
-                            asList("template", "tmpl", accountId,
-                                    templateId), File.separator);
+                    final String installPath = join(File.separator, "template", "tmpl", accountId,
templateId);
                     final VMTemplateHostVO tmpltHost = new VMTemplateHostVO(
                             secondaryStorageHost.getId(), templateId,
                             now(), 100, Status.DOWNLOADED, null, null,

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c88d8fb3/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
index e7fa5b2..9ddba83 100755
--- a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
+++ b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
@@ -22,7 +22,6 @@ import static com.cloud.utils.S3Utils.putDirectory;
 import static com.cloud.utils.StringUtils.join;
 import static com.cloud.utils.db.GlobalLock.executeWithNoWaitLock;
 import static java.lang.String.format;
-import static java.util.Arrays.asList;
 import static org.apache.commons.lang.StringUtils.substringAfterLast;
 
 import java.io.BufferedWriter;
@@ -217,19 +216,16 @@ SecondaryStorageResource {
         }
     }
 
-    @SuppressWarnings("unchecked")
-    private String determineS3TemplateDirectory(final Long accountId,
+    static String determineS3TemplateDirectory(final Long accountId,
             final Long templateId) {
-        return join(asList(TEMPLATE_ROOT_DIR, accountId, templateId),
-                S3Utils.SEPARATOR);
+        return join(S3Utils.SEPARATOR, TEMPLATE_ROOT_DIR, accountId, templateId);
     }
 
-    @SuppressWarnings("unchecked")
     private String determineStorageTemplatePath(final String storagePath,
             final Long accountId, final Long templateId) {
-        return join(
-                asList(getRootDir(storagePath), TEMPLATE_ROOT_DIR, accountId,
-                        templateId), File.separator);
+        return join(File.separator, 
+                getRootDir(storagePath), TEMPLATE_ROOT_DIR, accountId,
+                        templateId);
     }
 
     private Answer execute(
@@ -405,10 +401,7 @@ SecondaryStorageResource {
                     s_logger.debug(String
                             .format("Determining key using account id %1$s and template id
%2$s",
                                     accountId, templateId));
-                    return join(
-                            asList(determineS3TemplateDirectory(
-                                    accountId, templateId), file
-                                    .getName()), S3Utils.SEPARATOR);
+                    return join(S3Utils.SEPARATOR, determineS3TemplateDirectory(accountId,
templateId), file.getName());
                 }
             });
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c88d8fb3/utils/src/com/cloud/utils/S3Utils.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/S3Utils.java b/utils/src/com/cloud/utils/S3Utils.java
index b7273a1..33a3ebd 100644
--- a/utils/src/com/cloud/utils/S3Utils.java
+++ b/utils/src/com/cloud/utils/S3Utils.java
@@ -155,8 +155,8 @@ public final class S3Utils {
         try {
 
             tempFile = createTempFile(
-                    join(asList(targetDirectory.getName(), currentTimeMillis(),
-                            "part"), "-"), "tmp", targetDirectory);
+                    join("-", targetDirectory.getName(), currentTimeMillis(),
+                            "part"), "tmp", targetDirectory);
             tempFile.deleteOnExit();
 
             if (LOGGER.isDebugEnabled()) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c88d8fb3/utils/src/com/cloud/utils/StringUtils.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/StringUtils.java b/utils/src/com/cloud/utils/StringUtils.java
index 14ff4b1..359b169 100644
--- a/utils/src/com/cloud/utils/StringUtils.java
+++ b/utils/src/com/cloud/utils/StringUtils.java
@@ -16,8 +16,6 @@
 // under the License.
 package com.cloud.utils;
 
-import static java.util.Arrays.asList;
-
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -25,8 +23,6 @@ import java.util.regex.Pattern;
 
 import org.owasp.esapi.StringUtilities;
 
-// StringUtils exists in Apache Commons Lang, but rather than import the entire JAR to our
system, for now
-// just implement the method needed
 public class StringUtils {
     private static final char[] hexChar = {
         '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
@@ -50,7 +46,7 @@ public class StringUtils {
 
     public static String join(final String delimiter,
             final Object... components) {
-        return join(asList(components), delimiter);
+        return org.apache.commons.lang.StringUtils.join(components, delimiter);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c88d8fb3/utils/test/com/cloud/utils/StringUtilsTest.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/StringUtilsTest.java b/utils/test/com/cloud/utils/StringUtilsTest.java
index 3c162c7..796efba 100644
--- a/utils/test/com/cloud/utils/StringUtilsTest.java
+++ b/utils/test/com/cloud/utils/StringUtilsTest.java
@@ -103,4 +103,9 @@ public class StringUtilsTest {
         assertEquals(result, expected);
     }
 
+    @Test
+    public void testJoin() {
+        assertEquals("a-b-c", StringUtils.join("-", "a", "b", "c"));
+        assertEquals("", StringUtils.join("-"));
+    }
 }


Mime
View raw message