/** * Returns a distinct collection of URLs based on the {@code WEB-INF/lib} folder. * <p> * This finds the URLs using the {@link ServletContext}. * <p> * The returned URLs retains the order of the given {@code classLoaders}. * * @return the collection of URLs, not null */ public static Collection<URL> forWebInfLib(final ServletContext servletContext) { final Collection<URL> urls = new ArrayList<URL>(); Set<?> resourcePaths = servletContext.getResourcePaths("/WEB-INF/lib"); if (resourcePaths == null) { return urls; } for (Object urlString : resourcePaths) { try { urls.add(servletContext.getResource((String) urlString)); } catch (MalformedURLException e) { /*fuck off*/ } } return distinctUrls(urls); }
/** * Returns a distinct collection of URLs based on the {@code WEB-INF/lib} folder. * <p> * This finds the URLs using the {@link ServletContext}. * <p> * The returned URLs retains the order of the given {@code classLoaders}. * * @return the collection of URLs, not null */ public static Collection<URL> forWebInfLib(final ServletContext servletContext) { final Collection<URL> urls = new ArrayList<URL>(); Set<?> resourcePaths = servletContext.getResourcePaths("/WEB-INF/lib"); if (resourcePaths == null) { return urls; } for (Object urlString : resourcePaths) { try { urls.add(servletContext.getResource((String) urlString)); } catch (MalformedURLException e) { /*fuck off*/ } } return distinctUrls(urls); }
/** * Returns a distinct collection of URLs based on the {@code java.class.path} system property. * <p> * This finds the URLs using the {@code java.class.path} system property. * <p> * The returned collection of URLs retains the classpath order. * * @return the collection of URLs, not null */ public static Collection<URL> forJavaClassPath() { Collection<URL> urls = new ArrayList<URL>(); String javaClassPath = System.getProperty("java.class.path"); if (javaClassPath != null) { for (String path : javaClassPath.split(File.pathSeparator)) { try { urls.add(new File(path).toURI().toURL()); } catch (Exception e) { if (Reflections.log != null) { Reflections.log.warn("Could not get URL", e); } } } } return distinctUrls(urls); }
/** * Returns a distinct collection of URLs by expanding the specified URLs with Manifest information. * <p> * The {@code MANIFEST.MF} file can contain a {@code Class-Path} entry that defines additional * jar files to be included on the classpath. This method takes each URL in turn, tries to * resolve it as a jar file, and if so, adds any additional manifest classpaths. * The returned collection of URLs will always contain all the input URLs. * <p> * The returned URLs retains the input order. * * @return the collection of URLs, not null */ public static Collection<URL> forManifest(final Iterable<URL> urls) { Collection<URL> result = new ArrayList<URL>(); // determine if any of the URLs are JARs, and get any dependencies for (URL url : urls) { result.addAll(forManifest(url)); } return distinctUrls(result); }
/** * Returns a distinct collection of URLs based on the {@code java.class.path} system property. * <p> * This finds the URLs using the {@code java.class.path} system property. * <p> * The returned collection of URLs retains the classpath order. * * @return the collection of URLs, not null */ public static Collection<URL> forJavaClassPath() { Collection<URL> urls = new ArrayList<URL>(); String javaClassPath = System.getProperty("java.class.path"); if (javaClassPath != null) { for (String path : javaClassPath.split(File.pathSeparator)) { try { urls.add(new File(path).toURI().toURL()); } catch (Exception e) { if (Reflections.log != null) { Reflections.log.warn("Could not get URL", e); } } } } return distinctUrls(urls); }
/** * Returns a distinct collection of URLs by expanding the specified URLs with Manifest information. * <p> * The {@code MANIFEST.MF} file can contain a {@code Class-Path} entry that defines additional * jar files to be included on the classpath. This method takes each URL in turn, tries to * resolve it as a jar file, and if so, adds any additional manifest classpaths. * The returned collection of URLs will always contain all the input URLs. * <p> * The returned URLs retains the input order. * * @return the collection of URLs, not null */ public static Collection<URL> forManifest(final Iterable<URL> urls) { Collection<URL> result = new ArrayList<URL>(); // determine if any of the URLs are JARs, and get any dependencies for (URL url : urls) { result.addAll(forManifest(url)); } 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); }
/** * 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); }
return distinctUrls(result);
return distinctUrls(result);
return distinctUrls(result);
return distinctUrls(result);
public static Collection<URL> forWebInfLib(final ServletContext servletContext) { final Collection<URL> urls = new ArrayList<>(); Set<?> resourcePaths = servletContext.getResourcePaths("/WEB-INF/lib"); if (resourcePaths == null) { return urls; } for (Object urlString : resourcePaths) { try { urls.add(servletContext.getResource((String) urlString)); } catch (MalformedURLException e) { /*fuck off*/ } } return distinctUrls(urls); }
/** * Returns a distinct collection of URLs based on the {@code WEB-INF/lib} folder. * <p> * This finds the URLs using the {@link ServletContext}. * <p> * The returned URLs retains the order of the given {@code classLoaders}. * * @return the collection of URLs, not null */ public static Collection<URL> forWebInfLib(final ServletContext servletContext) { final Collection<URL> urls = new ArrayList<URL>(); for (Object urlString : servletContext.getResourcePaths("/WEB-INF/lib")) { try { urls.add(servletContext.getResource((String) urlString)); } catch (MalformedURLException e) { /*fuck off*/ } } return distinctUrls(urls); }
public static Collection<URL> forManifest(final Iterable<URL> urls) { Collection<URL> result = new ArrayList<>(); // determine if any of the URLs are JARs, and get any dependencies for (URL url : urls) { result.addAll(forManifest(url)); } return distinctUrls(result); }
/** * Returns a distinct collection of URLs based on the {@code WEB-INF/lib} folder. * <p> * This finds the URLs using the {@link ServletContext}. * <p> * The returned URLs retains the order of the given {@code classLoaders}. * * @return the collection of URLs, not null */ public static Collection<URL> forWebInfLib(final ServletContext servletContext) { final Collection<URL> urls = new ArrayList<URL>(); Set<?> resourcePaths = servletContext.getResourcePaths("/WEB-INF/lib"); if (resourcePaths == null) { return urls; } for (Object urlString : resourcePaths) { try { urls.add(servletContext.getResource((String) urlString)); } catch (MalformedURLException e) { /*fuck off*/ } } return distinctUrls(urls); }
public static Collection<URL> forClassLoader(ClassLoader... classLoaders) { final Collection<URL> result = new ArrayList<>(); 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 by expanding the specified URLs with Manifest information. * <p> * The {@code MANIFEST.MF} file can contain a {@code Class-Path} entry that defines additional * jar files to be included on the classpath. This method takes each URL in turn, tries to * resolve it as a jar file, and if so, adds any additional manifest classpaths. * The returned collection of URLs will always contain all the input URLs. * <p> * The returned URLs retains the input order. * * @return the collection of URLs, not null */ public static Collection<URL> forManifest(final Iterable<URL> urls) { Collection<URL> result = new ArrayList<URL>(); // determine if any of the URLs are JARs, and get any dependencies for (URL url : urls) { result.addAll(forManifest(url)); } return distinctUrls(result); }
/** * Returns a distinct collection of URLs by expanding the specified URLs with Manifest information. * <p> * The {@code MANIFEST.MF} file can contain a {@code Class-Path} entry that defines additional * jar files to be included on the classpath. This method takes each URL in turn, tries to * resolve it as a jar file, and if so, adds any additional manifest classpaths. * The returned collection of URLs will always contain all the input URLs. * <p> * The returned URLs retains the input order. * * @return the collection of URLs, not null */ public static Collection<URL> forManifest(final Iterable<URL> urls) { Collection<URL> result = new ArrayList<URL>(); // determine if any of the URLs are JARs, and get any dependencies for (URL url : urls) { result.addAll(forManifest(url)); } return distinctUrls(result); }
public static Collection<URL> forJavaClassPath() { Collection<URL> urls = new ArrayList<>(); String javaClassPath = System.getProperty("java.class.path"); if (javaClassPath != null) { for (String path : javaClassPath.split(File.pathSeparator)) { try { urls.add(new File(path).toURI().toURL()); } catch (Exception e) { final LoggingService log = Logger.getLogger(Reflections.class); if (log != null) { log.warning("Could not get URL" , e); } } } } return distinctUrls(urls); }