From cca73d8a690603f7e42634e65136bca8c29f5a9d Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 12 Jan 2013 13:47:07 -0800 Subject: [PATCH] removed function only used once and only accessing a single if branch --- .../org/jclouds/util/ClassLoadingUtils.java | 51 ------------------- .../functionloader/BasicFunctionLoader.java | 18 ++++--- 2 files changed, 10 insertions(+), 59 deletions(-) delete mode 100644 core/src/main/java/org/jclouds/util/ClassLoadingUtils.java diff --git a/core/src/main/java/org/jclouds/util/ClassLoadingUtils.java b/core/src/main/java/org/jclouds/util/ClassLoadingUtils.java deleted file mode 100644 index 2603fd8e17..0000000000 --- a/core/src/main/java/org/jclouds/util/ClassLoadingUtils.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.util; - -import java.net.URL; - -import com.google.common.io.Resources; - -public class ClassLoadingUtils { - - public ClassLoadingUtils() { - //Utility Class - } - - /** - * Returns the url of a resource. - * 1. The context class is being used. - * 2. The thread context class loader is being used. - * If both approach fail, returns null. - * - * @param contextClass - * @param resourceName - * @return - */ - public static URL loadResource(Class contextClass, String resourceName) { - URL url = null; - if (contextClass != null) { - url = Resources.getResource(contextClass, resourceName); - } - if (url == null && Thread.currentThread().getContextClassLoader() != null) { - url = Thread.currentThread().getContextClassLoader().getResource(resourceName); - } - return url; - } -} diff --git a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/functionloader/BasicFunctionLoader.java b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/functionloader/BasicFunctionLoader.java index fdc0c80c02..2c8d652489 100644 --- a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/functionloader/BasicFunctionLoader.java +++ b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/functionloader/BasicFunctionLoader.java @@ -18,14 +18,17 @@ */ package org.jclouds.scriptbuilder.functionloader; -import com.google.common.base.Charsets; -import com.google.common.io.Resources; -import org.jclouds.scriptbuilder.domain.OsFamily; -import org.jclouds.scriptbuilder.domain.ShellToken; -import org.jclouds.util.ClassLoadingUtils; +import static com.google.common.base.Charsets.UTF_8; +import static com.google.common.io.Resources.getResource; +import static java.lang.String.format; +import static org.jclouds.scriptbuilder.domain.ShellToken.SH; import java.io.IOException; +import org.jclouds.scriptbuilder.domain.OsFamily; + +import com.google.common.io.Resources; + /** * A {@link FunctionLoader} implementation which loads the target function from the classpath. */ @@ -45,9 +48,8 @@ public enum BasicFunctionLoader implements FunctionLoader { @Override public String loadFunction(String function, OsFamily family) throws FunctionNotFoundException { try { - return Resources.toString(ClassLoadingUtils.loadResource( - BasicFunctionLoader.class, String.format("/functions/%s.%s", function, ShellToken.SH.to(family))), - Charsets.UTF_8); + return Resources.toString( + getResource(BasicFunctionLoader.class, format("/functions/%s.%s", function, SH.to(family))), UTF_8); } catch (IOException e) { throw new FunctionNotFoundException(function, family, e); }