/** * Returns a distinct collection of URLs based on URLs derived from class loaders. * <p> * This finds the URLs using {@link URLClassLoader#getURLs()} using both * {@link #contextClassLoader()} and {@link #staticClassLoader()}. * <p> * The returned URLs retains the order of the given {@code classLoaders}. * * @return the collection of URLs, not null */ public static Collection<URL> forClassLoader() { return forClassLoader(classLoaders()); }
/** * Returns a distinct collection of URLs based on URLs derived from class loaders. * <p> * This finds the URLs using {@link URLClassLoader#getURLs()} using both * {@link #contextClassLoader()} and {@link #staticClassLoader()}. * <p> * The returned URLs retains the order of the given {@code classLoaders}. * * @return the collection of URLs, not null */ public static Collection<URL> forClassLoader() { return forClassLoader(classLoaders()); }
/** * Returns the URL that contains a {@code Class}. * <p> * This searches for the class using {@link ClassLoader#getResource(String)}. * <p> * If the optional {@link ClassLoader}s are not specified, then both {@link #contextClassLoader()} * and {@link #staticClassLoader()} are used for {@link ClassLoader#getResources(String)}. * * @return the URL containing the class, null if not found */ public static URL forClass(Class<?> aClass, ClassLoader... classLoaders) { final ClassLoader[] loaders = classLoaders(classLoaders); final String resourceName = aClass.getName().replace(".", "/") + ".class"; for (ClassLoader classLoader : loaders) { try { final URL url = classLoader.getResource(resourceName); if (url != null) { final String normalizedUrl = url.toExternalForm().substring(0, url.toExternalForm().lastIndexOf(aClass.getPackage().getName().replace(".", "/"))); return new URL(normalizedUrl); } } catch (MalformedURLException e) { if (Reflections.log != null) { Reflections.log.warn("Could not get URL", e); } } } return null; }
/** * Returns the URL that contains a {@code Class}. * <p> * This searches for the class using {@link ClassLoader#getResource(String)}. * <p> * If the optional {@link ClassLoader}s are not specified, then both {@link #contextClassLoader()} * and {@link #staticClassLoader()} are used for {@link ClassLoader#getResources(String)}. * * @return the URL containing the class, null if not found */ public static URL forClass(Class<?> aClass, ClassLoader... classLoaders) { final ClassLoader[] loaders = classLoaders(classLoaders); final String resourceName = aClass.getName().replace(".", "/") + ".class"; for (ClassLoader classLoader : loaders) { try { final URL url = classLoader.getResource(resourceName); if (url != null) { final String normalizedUrl = url.toExternalForm().substring(0, url.toExternalForm().lastIndexOf(aClass.getPackage().getName().replace(".", "/"))); return new URL(normalizedUrl); } } catch (MalformedURLException e) { if (Reflections.log != null) { Reflections.log.warn("Could not get URL", e); } } } return null; }
/** * Returns a distinct collection of URLs based on URLs derived from class loaders. * <p> * This finds the URLs using {@link URLClassLoader#getURLs()} using the specified * class loader, searching up the parent hierarchy. * <p> * If the optional {@link ClassLoader}s are not specified, then both {@link #contextClassLoader()} * and {@link #staticClassLoader()} are used for {@link ClassLoader#getResources(String)}. * <p> * The returned URLs retains the order of the given {@code classLoaders}. * * @return the collection of URLs, not null */ public static Collection<URL> forClassLoader(ClassLoader... classLoaders) { final Collection<URL> result = new ArrayList<URL>(); final ClassLoader[] loaders = classLoaders(classLoaders); for (ClassLoader classLoader : loaders) { while (classLoader != null) { if (classLoader instanceof URLClassLoader) { URL[] urls = ((URLClassLoader) classLoader).getURLs(); if (urls != null) { result.addAll(Arrays.asList(urls)); } } classLoader = classLoader.getParent(); } } return distinctUrls(result); }
/** * Returns a distinct collection of URLs based on URLs derived from class loaders. * <p> * This finds the URLs using {@link URLClassLoader#getURLs()} using the specified * class loader, searching up the parent hierarchy. * <p> * If the optional {@link ClassLoader}s are not specified, then both {@link #contextClassLoader()} * and {@link #staticClassLoader()} are used for {@link ClassLoader#getResources(String)}. * <p> * The returned URLs retains the order of the given {@code classLoaders}. * * @return the collection of URLs, not null */ public static Collection<URL> forClassLoader(ClassLoader... classLoaders) { final Collection<URL> result = new ArrayList<URL>(); final ClassLoader[] loaders = classLoaders(classLoaders); for (ClassLoader classLoader : loaders) { while (classLoader != null) { if (classLoader instanceof URLClassLoader) { URL[] urls = ((URLClassLoader) classLoader).getURLs(); if (urls != null) { result.addAll(Arrays.asList(urls)); } } classLoader = classLoader.getParent(); } } return distinctUrls(result); }
final ClassLoader[] loaders = classLoaders(classLoaders); for (ClassLoader classLoader : loaders) { try {
final ClassLoader[] loaders = classLoaders(classLoaders); for (ClassLoader classLoader : loaders) { try {
for (ClassLoader classLoader : ClasspathHelper.classLoaders(classLoaders)) { if (type.contains("[")) { try { return Class.forName(type, false, classLoader); }
for (ClassLoader classLoader : ClasspathHelper.classLoaders(classLoaders)) { if (type.contains("[")) { try { return Class.forName(type, false, classLoader); }
final ClassLoader[] classLoaders = ClasspathHelper.classLoaders(); for (ClassLoader classLoader : classLoaders) { final URL url =
private ClassPool getClassPool() { if (classPool == null) { synchronized (this) { classPool = new ClassPool(); ClassLoader[] classLoaders = getConfiguration().getClassLoaders(); if (classLoaders == null) { classLoaders = ClasspathHelper.classLoaders(); } for (ClassLoader classLoader : classLoaders) { classPool.appendClassPath(new LoaderClassPath(classLoader)); } } } return classPool; } }
private ClassPool getClassPool() { if (classPool == null) { synchronized (this) { classPool = new ClassPool(); ClassLoader[] classLoaders = getConfiguration().getClassLoaders(); if (classLoaders == null) { classLoaders = ClasspathHelper.classLoaders(); } for (ClassLoader classLoader : classLoaders) { classPool.appendClassPath(new LoaderClassPath(classLoader)); } } } return classPool; } }
/** * Returns a distinct collection of URLs based on URLs derived from class loaders. * <p> * This finds the URLs using {@link URLClassLoader#getURLs()} using both * {@link #contextClassLoader()} and {@link #staticClassLoader()}. * <p> * The returned URLs retains the order of the given {@code classLoaders}. * * @return the collection of URLs, not null */ public static Collection<URL> forClassLoader() { return forClassLoader(classLoaders()); }
/** * Returns a distinct collection of URLs based on URLs derived from class loaders. * <p> * This finds the URLs using {@link URLClassLoader#getURLs()} using both * {@link #contextClassLoader()} and {@link #staticClassLoader()}. * <p> * The returned URLs retains the order of the given {@code classLoaders}. * * @return the collection of URLs, not null */ public static Collection<URL> forClassLoader() { return forClassLoader(classLoaders()); }
private static Collection<URL> forSinglePackage(String name) { final List<URL> result = Lists.newArrayList(); String resourceName = name.replace(".", "/").replace("\\", "/"); for (ClassLoader classLoader : ClasspathHelper.classLoaders()) { try { final Enumeration<URL> urls = classLoader.getResources(resourceName); while (urls.hasMoreElements()) { result.add(urls.nextElement()); } } catch (IOException e) { throw new RuntimeException("Error getting resources for " + name, e); } } return result; } }
/** * Add ClasspathUrls from MANIFEST Class-Path directive into builder. * * @param builder Reflection ConfigurationBuilder */ private static void addNestedClasspathUrls(final ConfigurationBuilder builder) { final ClassLoader[] cls = ClasspathHelper.classLoaders(builder.getClassLoaders()); builder.addUrls(ClassLoaderUtil.getAlsoNestedClasspathUrls(Arrays.asList(cls))); }
private ClassPool getClassPool() { if (classPool == null) { synchronized (this) { classPool = new ClassPool(); ClassLoader[] classLoaders = getConfiguration().getClassLoaders(); if (classLoaders == null) { classLoaders = ClasspathHelper.classLoaders(); } for (ClassLoader classLoader : classLoaders) { classPool.appendClassPath(new LoaderClassPath(classLoader)); } } } return classPool; } }
private ClassPool getClassPool() { if (classPool == null) { synchronized (this) { classPool = new ClassPool(); ClassLoader[] classLoaders = getConfiguration().getClassLoaders(); if (classLoaders == null) { classLoaders = ClasspathHelper.classLoaders(); } for (ClassLoader classLoader : classLoaders) { classPool.appendClassPath(new LoaderClassPath(classLoader)); } } } return classPool; }
private ClassPool getClassPool() { if (classPool == null) { synchronized (this) { classPool = new ClassPool(); ClassLoader[] classLoaders = getConfiguration().getClassLoaders(); if (classLoaders == null) { classLoaders = ClasspathHelper.classLoaders(); } for (ClassLoader classLoader : classLoaders) { classPool.appendClassPath(new LoaderClassPath(classLoader)); } } } return classPool; } }