Attempts to find the URLs of a resource from the classpath, either using
the caller's class loader or the current thread's context classloader.

@param resourcePath
the resource path
@param source
the object
@return the URL or null if not found
331035
public static Enumeration<URL> getResources(String resourcePath, Object source) {

		// Try the current classloader
		Enumeration<URL> urls = null;

		ClassLoader cl = source.getClass().getClassLoader();
		try {
			if (null != cl) {
				urls = cl.getResources(resourcePath);
			}

			// If current classloader failed, try with the Threads context
			// classloader. If that fails ott, the resource is either not on the
			// classpath or inaccessible from the current context.

			if (null == urls) {
				urls = Thread.currentThread().getContextClassLoader().getResources(resourcePath);
			}

			// Last chance, hack in the classloader
			if (null == urls) {
				ClassLoader threadClassLoader = Thread.currentThread().getContextClassLoader();
				try {
					Thread.currentThread().setContextClassLoader(source.getClass().getClassLoader());
					if (Thread.currentThread().getContextClassLoader() != null) {

						urls = Thread.currentThread().getContextClassLoader().getResources(resourcePath);
					}
				} finally {
					Thread.currentThread().setContextClassLoader(threadClassLoader);
				}
			}
		} catch (IOException e) {
			LOGGER.warn("Unable to load " + resourcePath, e);
		}

		return urls;
	}
373739
private static Set<URL> getResourcesFromRoot(final String rootPath) {

        final Set<URL> rets = new LinkedHashSet<URL>();

        String path = rootPath;

        if (path.startsWith("/")) {
            path = path.substring(1);
        }

        try {
            final Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources(path);
            URL url = null;

            while (resources.hasMoreElements()) {
                url = (URL) resources.nextElement();

                rets.add(url);
            }
        } catch (final IOException e) {
            LOGGER.log(Level.ERROR, "get the ROOT Rescources error", e);
        }
        return rets;
    }
374358
public static String getAbsolutePath(String classPath) {
        URL configUrl = Thread.currentThread().getContextClassLoader().getResource(classPath.substring(1));
        if (configUrl == null) {
            configUrl = ResourceUtil.class.getResource(classPath);
        }
        if (configUrl == null) {
            return null;
        }
        try {
            return configUrl.toURI().getPath();
        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        }
    }
1016169
@Override
	public String getFilePath(String resourcePath) {
		return helper.getFilePath(resolver.getResourcePath(resourcePath));
	}
569302
@Override
	public URL getResourceUrl(String fileName) {
		if (fileName == null) {
			return null;
		}
		URL resource = getClass().getResource(fileName);
		if (resource == null) {
			resource = Thread.currentThread().getContextClassLoader().getResource(fileName);
			if (resource == null) {
				resource = ClassLoader.getSystemResource(fileName);
				if (resource == null) {
					File file = new File(fileName);
					if (file.exists()) {
						try {
							resource = file.toURI().toURL();
						} catch (MalformedURLException e) {
							throw new JKException(e);
						}
					}
				}
			}
		}
		return resource;
	}
1252109
public Stream<URL> getResources(String path) {
        Enumeration<URL> all;
        try {
            all = classLoader.getResources(prefixPath(path));
        } catch (IOException e) {
            return Stream.empty();
        }
        Stream.Builder<URL> builder = Stream.builder();
        while (all.hasMoreElements()) {
            URL url = all.nextElement();
            builder.accept(url);
        }
        return builder.build();
    }
1266566
@Override
	public String getResourcePath(String basePath, String relativePath) {

		String result = null;
		if (binaryGeneratorRegistry.isGeneratedBinaryResource(relativePath)) {
			result = relativePath;
		} else if (contextPath != null && relativePath.startsWith(contextPath)) {
			result = relativePath.substring(contextPath.length() - 1);
		} else {
			result = PathNormalizer.concatWebPath(basePath, relativePath);
		}
		return result;
	}
1040341
@SuppressWarnings("deprecation")
    @Override
    public final URL[] findResourcesByClasspath()
    {
        List<URL> list = new ArrayList<URL>();
        String classpath = System.getProperty("java.class.path");
        StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator);

        while (tokenizer.hasMoreTokens())
        {
            String path = tokenizer.nextToken();

            File fp = new File(path);
            if (!fp.exists())
                throw new ResourceReadingException("File in java.class.path does not exist: " + fp);
            try
            {
                list.add(fp.toURL());
            }
            catch (MalformedURLException e)
            {
                throw new ResourceReadingException(e);
            }
        }
        return list.toArray(new URL[list.size()]);
    }
1147640
public static InputStream getResourceAsStream(final String resourcePath) {
        File resource = getFileForResource(resourcePath);

        if (!resource.exists() || resource.isDirectory()) {
            logger.error("Cannot read resource, does not exist"
                    + " (or is a directory).");
            return new NullInputStream(0);
        }

        try {
            return new FileInputStream(resource);
        } catch (IOException ioe) {
            logger.error(ioe.getMessage());
            return new NullInputStream(0);
        }
    }
108244
public static @CheckForNull URL _findResource(ClassLoader cl, String name) {
        return (URL) invoke(FIND_RESOURCE, RuntimeException.class, cl, name);
    }
715313
public static URL getSourceUrl(SourceUnit source) {
        URL url = null;
        final String filename = source.getName();
        if(filename==null) {
            return null;
        }

        Resource resource = new FileSystemResource(filename);
        if (resource.exists()) {
            try {
                url = resource.getURL();
            } catch (IOException e) {
                // ignore
            }
        }
        return url;
    }
569230
public static ArchivePath getPathForClassloaderResource(String resourceName) {
        String extractedPath = null;
        if (resourceName.lastIndexOf('/') != -1) {
            extractedPath = resourceName.substring(0, resourceName.lastIndexOf('/'));
        }
        return new BasicPath(extractedPath);
    }
774921
private String getCompletePath(String resourcePath) {
		String path = PathNormalizer.normalizePath(classpathPrefix + resourcePath);
		return path;
	}
665125
public static String getResourceURL(String resource) {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        return cl.getResource(resource).toString();
    }
100267
public static URL getResource(Class<?> loadClass, String name,
								  boolean checkParents) throws ClassNotFoundException {
		URL url = null;
		ClassLoader loader = Thread.currentThread().getContextClassLoader();
		while (url == null && loader != null) {
			url = loader.getResource(name);
			loader = (url == null && checkParents) ? loader.getParent() : null;
		}

		loader = loadClass == null ? null : loadClass.getClassLoader();
		while (url == null && loader != null) {
			url = loader.getResource(name);
			loader = (url == null && checkParents) ? loader.getParent() : null;
		}

		if (url == null) {
			url = ClassLoader.getSystemResource(name);
		}

		return url;
	}
820542
public URL findResource(final String name) {

        if (log.isDebugEnabled())
            log.debug("    findResource(" + name + ")");

        URL url = null;

        ResourceEntry entry = (ResourceEntry) resourceEntries.get(name);
        if (entry == null) {
            entry = findResourceInternal(name, name);
        }
        if (entry != null) {
            url = entry.source;
        }

        if ((url == null) && hasExternalRepositories)
            url = super.findResource(name);

        if (log.isDebugEnabled()) {
            if (url != null)
                log.debug("    --> Returning '" + url.toString() + "'");
            else
                log.debug("    --> Resource not found, returning null");
        }
        return (url);

    }
604914
@Override
	@Pure
	public URL findResource(final String name) {
		/*
		 * The same restriction to finding classes applies to resources
		 */
		final URL url = AccessController.doPrivileged(new PrivilegedAction<URL>() {
				@Override
				public URL run() {
					return DynamicURLClassLoader.this.ucp.findResource(name, true);
				}
			}, this.acc);

		return url != null ? this.ucp.checkURL(url) : null;
	}