mirror of https://github.com/apache/cloudstack.git
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>
This commit is contained in:
parent
564013bec0
commit
c88d8fb3a2
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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()) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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("-"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue