private Enumeration<URL> getGlobalHandlerResources() throws IOException { // Classloader may be null if loaded by bootstrap classloader. if (HandlerChainFactory.class.getClassLoader() == null) { return ClassLoader.getSystemResources(GLOBAL_HANDLER_PATH); } return HandlerChainFactory.class.getClassLoader().getResources(GLOBAL_HANDLER_PATH); }
private static Enumeration<URL> getResources(final String name) throws IOException { if (ServiceFinder.class.getClassLoader() != null) { return ServiceFinder.class.getClassLoader().getResources(name); } else { return ClassLoader.getSystemResources(name); } }
private static Enumeration<URL> getResources(final String name) throws IOException { if (ServiceFinder.class.getClassLoader() != null) { return ServiceFinder.class.getClassLoader().getResources(name); } else { return ClassLoader.getSystemResources(name); } }
private static Map<String, List<String>> loadSpringFactories(@Nullable ClassLoader classLoader) { MultiValueMap<String, String> result = cache.get(classLoader); if (result != null) { return result; } try { Enumeration<URL> urls = (classLoader != null ? classLoader.getResources(FACTORIES_RESOURCE_LOCATION) : ClassLoader.getSystemResources(FACTORIES_RESOURCE_LOCATION)); result = new LinkedMultiValueMap<>(); while (urls.hasMoreElements()) { URL url = urls.nextElement(); UrlResource resource = new UrlResource(url); Properties properties = PropertiesLoaderUtils.loadProperties(resource); for (Map.Entry<?, ?> entry : properties.entrySet()) { String factoryClassName = ((String) entry.getKey()).trim(); for (String factoryName : StringUtils.commaDelimitedListToStringArray((String) entry.getValue())) { result.add(factoryClassName, factoryName.trim()); } } } cache.put(classLoader, result); return result; } catch (IOException ex) { throw new IllegalArgumentException("Unable to load factories from location [" + FACTORIES_RESOURCE_LOCATION + "]", ex); } }
ClassLoader.getSystemResources(resourceName)); Properties props = new Properties(); while (urls.hasMoreElements()) {
/** * Find all class location resources with the given path via the ClassLoader. * Called by {@link #findAllClassPathResources(String)}. * @param path the absolute path within the classpath (never a leading slash) * @return a mutable Set of matching Resource instances * @since 4.1.1 */ protected Set<Resource> doFindAllClassPathResources(String path) throws IOException { Set<Resource> result = new LinkedHashSet<>(16); ClassLoader cl = getClassLoader(); Enumeration<URL> resourceUrls = (cl != null ? cl.getResources(path) : ClassLoader.getSystemResources(path)); while (resourceUrls.hasMoreElements()) { URL url = resourceUrls.nextElement(); result.add(convertClassLoaderURL(url)); } if ("".equals(path)) { // The above result is likely to be incomplete, i.e. only containing file system references. // We need to have pointers to each of the jar files on the classpath as well... addAllClassLoaderJarRoots(cl, result); } return result; }
static Set<URL> findPossibleStaticLoggerBinderPathSet() { // use Set instead of list in order to deal with bug #138 // LinkedHashSet appropriate here because it preserves insertion order // during iteration Set<URL> staticLoggerBinderPathSet = new LinkedHashSet<URL>(); try { ClassLoader loggerFactoryClassLoader = LoggerFactory.class.getClassLoader(); Enumeration<URL> paths; if (loggerFactoryClassLoader == null) { paths = ClassLoader.getSystemResources(STATIC_LOGGER_BINDER_PATH); } else { paths = loggerFactoryClassLoader.getResources(STATIC_LOGGER_BINDER_PATH); } while (paths.hasMoreElements()) { URL path = paths.nextElement(); staticLoggerBinderPathSet.add(path); } } catch (IOException ioe) { Util.report("Error getting resources from path", ioe); } return staticLoggerBinderPathSet; }
public Object run() { try { if (loader != null) { return loader.getResources(name); } else { return ClassLoader.getSystemResources(name); } } catch (IOException e) { if (isDiagnosticsEnabled()) { logDiagnostic("Exception while trying to find configuration file " + name + ":" + e.getMessage()); } return null; } catch (NoSuchMethodError e) { // we must be running on a 1.1 JVM which doesn't support // ClassLoader.getSystemResources; just return null in // this case. return null; } } };
private void loadDirectory(Map<String, Class<?>> extensionClasses, String dir, String type) { String fileName = dir + type; try { Enumeration<java.net.URL> urls; ClassLoader classLoader = findClassLoader(); if (classLoader != null) { urls = classLoader.getResources(fileName); } else { urls = ClassLoader.getSystemResources(fileName); } if (urls != null) { while (urls.hasMoreElements()) { java.net.URL resourceURL = urls.nextElement(); loadResource(extensionClasses, classLoader, resourceURL); } } } catch (Throwable t) { logger.error("Exception occurred when loading extension class (interface: " + type + ", description file: " + fileName + ").", t); } }
private void loadDirectory(Map<String, Class<?>> extensionClasses, String dir, String type) { String fileName = dir + type; try { Enumeration<java.net.URL> urls; ClassLoader classLoader = findClassLoader(); if (classLoader != null) { urls = classLoader.getResources(fileName); } else { urls = ClassLoader.getSystemResources(fileName); } if (urls != null) { while (urls.hasMoreElements()) { java.net.URL resourceURL = urls.nextElement(); loadResource(extensionClasses, classLoader, resourceURL); } } } catch (Throwable t) { logger.error("Exception occurred when loading extension class (interface: " + type + ", description file: " + fileName + ").", t); } }
public Object run() { URL[] ret = null; try { List v = new ArrayList(); Enumeration e = ClassLoader.getSystemResources(name); while (e != null && e.hasMoreElements()) { URL url = (URL)e.nextElement(); if (url != null) v.add(url); } if (v.size() > 0) { ret = new URL[v.size()]; ret = (URL[])v.toArray(ret); } } catch (IOException ioex) { } catch (SecurityException ex) { } return ret; } });
static Set<URL> findPossibleStaticLoggerBinderPathSet() { // use Set instead of list in order to deal with bug #138 // LinkedHashSet appropriate here because it preserves insertion order // during iteration Set<URL> staticLoggerBinderPathSet = new LinkedHashSet<URL>(); try { ClassLoader loggerFactoryClassLoader = LoggerFactory.class.getClassLoader(); Enumeration<URL> paths; if (loggerFactoryClassLoader == null) { paths = ClassLoader.getSystemResources(STATIC_LOGGER_BINDER_PATH); } else { paths = loggerFactoryClassLoader.getResources(STATIC_LOGGER_BINDER_PATH); } while (paths.hasMoreElements()) { URL path = paths.nextElement(); staticLoggerBinderPathSet.add(path); } } catch (IOException ioe) { Util.report("Error getting resources from path", ioe); } return staticLoggerBinderPathSet; }
urls = classLoader.getResources(fileName); } else { urls = ClassLoader.getSystemResources(fileName);
private static Map<String, List<String>> loadSpringFactories(@Nullable ClassLoader classLoader) { MultiValueMap<String, String> result = cache.get(classLoader); if (result != null) { return result; } try { Enumeration<URL> urls = (classLoader != null ? classLoader.getResources(FACTORIES_RESOURCE_LOCATION) : ClassLoader.getSystemResources(FACTORIES_RESOURCE_LOCATION)); result = new LinkedMultiValueMap<>(); while (urls.hasMoreElements()) { URL url = urls.nextElement(); UrlResource resource = new UrlResource(url); Properties properties = PropertiesLoaderUtils.loadProperties(resource); for (Map.Entry<?, ?> entry : properties.entrySet()) { String factoryClassName = ((String) entry.getKey()).trim(); for (String factoryName : StringUtils.commaDelimitedListToStringArray((String) entry.getValue())) { result.add(factoryClassName, factoryName.trim()); } } } cache.put(classLoader, result); return result; } catch (IOException ex) { throw new IllegalArgumentException("Unable to load factories from location [" + FACTORIES_RESOURCE_LOCATION + "]", ex); } }
public Object run() { try { if (loader != null) { return loader.getResources(name); } else { return ClassLoader.getSystemResources(name); } } catch(IOException e) { if (isDiagnosticsEnabled()) { logDiagnostic( "Exception while trying to find configuration file " + name + ":" + e.getMessage()); } return null; } catch(NoSuchMethodError e) { // we must be running on a 1.1 JVM which doesn't support // ClassLoader.getSystemResources; just return null in // this case. return null; } } };
ClassLoader.getSystemResources(resourceName)); Properties props = new Properties(); while (urls.hasMoreElements()) {
private ConcurrentMap<String, Class<T>> loadExtensionClasses(String prefix) { String fullName = prefix + type.getName(); List<String> classNames = new ArrayList<String>(); try { Enumeration<URL> urls; if (classLoader == null) { urls = ClassLoader.getSystemResources(fullName); } else { urls = classLoader.getResources(fullName); } if (urls == null || !urls.hasMoreElements()) { return new ConcurrentHashMap<String, Class<T>>(); } while (urls.hasMoreElements()) { URL url = urls.nextElement(); parseUrl(type, url, classNames); } } catch (Exception e) { throw new MotanFrameworkException( "ExtensionLoader loadExtensionClasses error, prefix: " + prefix + " type: " + type.getClass(), e); } return loadClass(classNames); }
/** * Find all class location resources with the given path via the ClassLoader. * Called by {@link #findAllClassPathResources(String)}. * @param path the absolute path within the classpath (never a leading slash) * @return a mutable Set of matching Resource instances * @since 4.1.1 */ protected Set<Resource> doFindAllClassPathResources(String path) throws IOException { Set<Resource> result = new LinkedHashSet<>(16); ClassLoader cl = getClassLoader(); Enumeration<URL> resourceUrls = (cl != null ? cl.getResources(path) : ClassLoader.getSystemResources(path)); while (resourceUrls.hasMoreElements()) { URL url = resourceUrls.nextElement(); result.add(convertClassLoaderURL(url)); } if ("".equals(path)) { // The above result is likely to be incomplete, i.e. only containing file system references. // We need to have pointers to each of the jar files on the classpath as well... addAllClassLoaderJarRoots(cl, result); } return result; }
private static Set<URLDefinition> collectExtensionUrls(String resourceName, ClassLoader classLoader) { try { final Enumeration<URL> configs; if (classLoader != null) { configs = classLoader.getResources(resourceName); } else { configs = ClassLoader.getSystemResources(resourceName); } Set<URLDefinition> urlDefinitions = new HashSet<URLDefinition>(); while (configs.hasMoreElements()) { URL url = configs.nextElement(); final URI uri = url.toURI(); ClassLoader highestClassLoader = findHighestReachableClassLoader(url, classLoader, resourceName); urlDefinitions.add(new URLDefinition(uri, highestClassLoader)); } return urlDefinitions; } catch (Exception e) { LOGGER.error(e.getMessage(), e); } return Collections.emptySet(); }
private static Set<URLDefinition> collectExtensionUrls(String resourceName, ClassLoader classLoader) { try { final Enumeration<URL> configs; if (classLoader != null) { configs = classLoader.getResources(resourceName); } else { configs = ClassLoader.getSystemResources(resourceName); } Set<URLDefinition> urlDefinitions = new HashSet<URLDefinition>(); while (configs.hasMoreElements()) { URL url = configs.nextElement(); final URI uri = url.toURI(); ClassLoader highestClassLoader = findHighestReachableClassLoader(url, classLoader, resourceName); urlDefinitions.add(new URLDefinition(uri, highestClassLoader)); } return urlDefinitions; } catch (Exception e) { LOGGER.error(e.getMessage(), e); } return Collections.emptySet(); }