mneethiraj commented on code in PR #442: URL: https://github.com/apache/ranger/pull/442#discussion_r1880845360
########## agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerConfiguration.java: ########## @@ -17,88 +17,79 @@ * under the License. */ - package org.apache.ranger.authorization.hadoop.config; -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Properties; - import org.apache.commons.lang.StringUtils; import org.apache.hadoop.conf.Configuration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Properties; public class RangerConfiguration extends Configuration { - private static final Logger LOG = LoggerFactory.getLogger(RangerConfiguration.class); - - protected RangerConfiguration() { - super(false); - } - - public boolean addResourceIfReadable(String aResourceName) { - boolean ret = false; - - if(LOG.isDebugEnabled()) { - LOG.debug("==> addResourceIfReadable(" + aResourceName + ")"); - } - - URL fUrl = getFileLocation(aResourceName); - if (fUrl != null) { - if(LOG.isDebugEnabled()) { - LOG.debug("addResourceIfReadable(" + aResourceName + "): resource file is " + fUrl); - } - try { - addResource(fUrl); - ret = true; - } catch (Exception e) { - LOG.error("Unable to load the resource name [" + aResourceName + "]. Ignoring the resource:" + fUrl); - if (LOG.isDebugEnabled()) { - LOG.debug("Resource loading failed for " + fUrl, e); - } - } - } else { - if(LOG.isDebugEnabled()) { - LOG.debug("addResourceIfReadable(" + aResourceName + "): couldn't find resource file location"); - } - } - - if(LOG.isDebugEnabled()) { - LOG.debug("<== addResourceIfReadable(" + aResourceName + "), result=" + ret); - } - return ret; - } - - public Properties getProperties() { - return getProps(); - } - - private URL getFileLocation(String fileName) { - URL lurl = null; - if (!StringUtils.isEmpty(fileName)) { - lurl = RangerConfiguration.class.getClassLoader().getResource(fileName); - - if (lurl == null ) { - lurl = RangerConfiguration.class.getClassLoader().getResource("/" + fileName); - } - - if (lurl == null ) { - File f = new File(fileName); - if (f.exists()) { - try { - lurl=f.toURI().toURL(); - } catch (MalformedURLException e) { - LOG.error("Unable to load the resource name [" + fileName + "]. Ignoring the resource:" + f.getPath()); - } - } else { - if(LOG.isDebugEnabled()) { - LOG.debug("Conf file path " + fileName + " does not exists"); - } - } - } - } - return lurl; - } + private static final Logger LOG = LoggerFactory.getLogger(RangerConfiguration.class); + + protected RangerConfiguration() { + super(false); + } + + public boolean addResourceIfReadable(String aResourceName) { + LOG.debug("==> addResourceIfReadable({})", aResourceName); + + boolean ret = false; + URL fUrl = getFileLocation(aResourceName); + + if (fUrl != null) { + LOG.debug("addResourceIfReadable({}): resource file is {}", aResourceName, fUrl); + + try { + addResource(fUrl); + + ret = true; + } catch (Exception e) { + LOG.error("Unable to load the resource name [{}]. Ignoring the resource:{}", aResourceName, fUrl); + + LOG.debug("Resource loading failed for {}", fUrl, e); + } + } else { + LOG.debug("addResourceIfReadable({}): couldn't find resource file location", aResourceName); + } + + LOG.debug("<== addResourceIfReadable({}), result={}", aResourceName, ret); + + return ret; + } + + public Properties getProperties() { + return getProps(); + } + + private URL getFileLocation(String fileName) { Review Comment: Current implementation is to keep a single return statement in the method. I suggest retaining this. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@ranger.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org