This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-configuration.git
commit fbb20a27f508b8a98c93a9ea953949211bf218bb Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sat Mar 25 16:50:49 2023 -0400 Better internal method names --- .../io/ClasspathLocationStrategy.java | 2 +- .../configuration2/io/FileLocatorUtils.java | 58 +++++++++++----------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/apache/commons/configuration2/io/ClasspathLocationStrategy.java b/src/main/java/org/apache/commons/configuration2/io/ClasspathLocationStrategy.java index 76883c2f..a0e80716 100644 --- a/src/main/java/org/apache/commons/configuration2/io/ClasspathLocationStrategy.java +++ b/src/main/java/org/apache/commons/configuration2/io/ClasspathLocationStrategy.java @@ -37,6 +37,6 @@ public class ClasspathLocationStrategy implements FileLocationStrategy { */ @Override public URL locate(final FileSystem fileSystem, final FileLocator locator) { - return StringUtils.isEmpty(locator.getFileName()) ? null : FileLocatorUtils.locateFromClasspath(locator.getFileName()); + return StringUtils.isEmpty(locator.getFileName()) ? null : FileLocatorUtils.getClasspathResource(locator.getFileName()); } } diff --git a/src/main/java/org/apache/commons/configuration2/io/FileLocatorUtils.java b/src/main/java/org/apache/commons/configuration2/io/FileLocatorUtils.java index 23183557..68d25c64 100644 --- a/src/main/java/org/apache/commons/configuration2/io/FileLocatorUtils.java +++ b/src/main/java/org/apache/commons/configuration2/io/FileLocatorUtils.java @@ -307,6 +307,35 @@ public final class FileLocatorUtils { return s.substring(0, s.lastIndexOf("/") + 1); } + /** + * Tries to find a resource with the given name in the classpath. + * + * @param resourceName the name of the resource + * @return the URL to the found resource or <b>null</b> if the resource cannot be found + */ + static URL getClasspathResource(final String resourceName) { + URL url = null; + // attempt to load from the context classpath + final ClassLoader loader = Thread.currentThread().getContextClassLoader(); + if (loader != null) { + url = loader.getResource(resourceName); + + if (url != null) { + LOG.debug("Loading configuration from the context classpath (" + resourceName + ")"); + } + } + + // attempt to load from the system classpath + if (url == null) { + url = ClassLoader.getSystemResource(resourceName); + + if (url != null) { + LOG.debug("Loading configuration from the system classpath (" + resourceName + ")"); + } + } + return url; + } + /** * Tries to convert the specified base path and file name into a file object. This method is called e.g. by the save() * methods of file based configurations. The parameter strings can be relative files, absolute files and URLs as well. @@ -459,35 +488,6 @@ public final class FileLocatorUtils { return getLocationStrategy(locator).locate(getFileSystem(locator), locator); } - /** - * Tries to find a resource with the given name in the classpath. - * - * @param resourceName the name of the resource - * @return the URL to the found resource or <b>null</b> if the resource cannot be found - */ - static URL locateFromClasspath(final String resourceName) { - URL url = null; - // attempt to load from the context classpath - final ClassLoader loader = Thread.currentThread().getContextClassLoader(); - if (loader != null) { - url = loader.getResource(resourceName); - - if (url != null) { - LOG.debug("Loading configuration from the context classpath (" + resourceName + ")"); - } - } - - // attempt to load from the system classpath - if (url == null) { - url = ClassLoader.getSystemResource(resourceName); - - if (url != null) { - LOG.debug("Loading configuration from the system classpath (" + resourceName + ")"); - } - } - return url; - } - /** * Tries to locate the file referenced by the passed in {@code FileLocator}. If this fails, an exception is thrown. This * method works like {@link #locate(FileLocator)}; however, in case of a failed location attempt an exception is thrown.