/** * Returns a distinct collection of URLs based on a package name. * <p> * This searches for the package name as a resource, using {@link ClassLoader#getResources(String)}. * For example, {@code forPackage(org.reflections)} effectively returns URLs from the * classpath containing packages starting with {@code org.reflections}. * <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 retainsthe order of the given {@code classLoaders}. * * @return the collection of URLs, not null */ public static Collection<URL> forPackage(String name, ClassLoader... classLoaders) { return forResource(resourceName(name), classLoaders); }
/** * Returns a distinct collection of URLs based on a package name. * <p> * This searches for the package name as a resource, using {@link ClassLoader#getResources(String)}. * For example, {@code forPackage(org.reflections)} effectively returns URLs from the * classpath containing packages starting with {@code org.reflections}. * <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 retainsthe order of the given {@code classLoaders}. * * @return the collection of URLs, not null */ public static Collection<URL> forPackage(String name, ClassLoader... classLoaders) { return forResource(resourceName(name), classLoaders); }
public static Collection<URL> forPackage(String name , ClassLoader... classLoaders) { return forResource(resourceName(name) , classLoaders); }
/** * Returns a distinct collection of URLs based on a package name. * <p> * This searches for the package name as a resource, using {@link ClassLoader#getResources(String)}. * For example, {@code forPackage(org.reflections)} effectively returns URLs from the * classpath containing packages starting with {@code org.reflections}. * <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 retainsthe order of the given {@code classLoaders}. * * @return the collection of URLs, not null */ public static Collection<URL> forPackage(String name, ClassLoader... classLoaders) { return forResource(resourceName(name), classLoaders); }
/** * Returns a distinct collection of URLs based on a package name. * <p> * This searches for the package name as a resource, using {@link ClassLoader#getResources(String)}. * For example, {@code forPackage(org.reflections)} effectively returns URLs from the * classpath containing packages starting with {@code org.reflections}. * <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 retainsthe order of the given {@code classLoaders}. * * @return the collection of URLs, not null */ public static Collection<URL> forPackage(String name, ClassLoader... classLoaders) { return forResource(resourceName(name), classLoaders); }
if (searchInSources) { Set<URL> urls = ClasspathHelper.forResource(resourceName); for (URL url : urls) { if (url.getProtocol().equals("file")) {
if (searchInSources) { Set<URL> urls = ClasspathHelper.forResource(resourceName); for (URL url : urls) { if (url.getProtocol().equals("file")) {
private void addClasspathResourceSets(WebResourceRoot resources) { String webAppMount = "/"; String archivePath = null; String internalPath = "/META-INF/resources"; for (URL url : ClasspathHelper.forResource("META-INF/resources/", this.getClass().getClassLoader())) { resources.createWebResourceSet(WebResourceRoot.ResourceSetType.POST, webAppMount, base(url), archivePath, internalPath); } } }
private Collection<URL> getJARs() { Set<URL> urls = new HashSet<>(); // ClasspathHelper.forClassLoader() get even the JARs that are made not reachable by the application server // So the trick is to get all resources in which we can access a META-INF folder urls.addAll(ClasspathHelper.forPackage("META-INF")); // It's possible in a (bad JAR) to declare the entry META-INF/MANIFEST.MF without the entry META-INF/ urls.addAll(ClasspathHelper.forResource("META-INF/MANIFEST.MF")); // Workaround javax.inject 1 JAR which is incredibly hacky and does not even contain any META-INF folder so we // have to do // something special for it urls.addAll(ClasspathHelper.forPackage("javax")); Collection<URL> jarURLs = new ArrayList<>(urls.size()); for (URL url : urls) { try { jarURLs.add(PathUtils.getExtensionURL(url)); } catch (IOException e) { this.logger.error("Failed to convert to extension URL", e); } } return jarURLs; }
/** * Compute urls to scan for annotations. * @return collection of urls */ public Collection<URL> getURLs() { if (this.urls == null) { // stores collections of urls to be scanned Collection<URL> result = new ArrayList<URL>(); Collection<String> strings = new HashSet<String>(); // get only urls of libraries that contains jsf types add(result, strings, ClasspathHelper.forResource("META-INF/faces-config.xml", this.getClass().getClassLoader())); // add jsf library with anotherFacesConfig String anotherFacesConfig = this.jsfAnnotatedClassFactoryConfiguration.getAnotherConfig(); if (anotherFacesConfig != null) { add(result, strings, ClasspathHelper.forResource(anotherFacesConfig, this.getClass().getClassLoader())); } // add project classes folder for (URL url : ClasspathHelper.forManifest()) { String file = url.getFile(); // check if adding classes folder if (isClassesFolder(file)) { add(result, strings, url); } } this.urls = result; } return this.urls; }
Collection<URL> urls = new HashSet<>(ClasspathHelper.forResource("META-INF/faces-config.xml", this.getClass().getClassLoader())); urls.addAll(ClasspathHelper.forResource(anotherFacesConfig, this.getClass().getClassLoader()));