/** * 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 expanded 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 finds the jar files * using the {@link #contextClassLoader()} and {@link #staticClassLoader()}, before * searching for any additional manifest classpaths. * * @return the collection of URLs, not null */ public static Collection<URL> forManifest() { return forManifest(forClassLoader()); }
/** * 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 expanded 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 finds the jar files * using the {@link #contextClassLoader()} and {@link #staticClassLoader()}, before * searching for any additional manifest classpaths. * * @return the collection of URLs, not null */ public static Collection<URL> forManifest() { return forManifest(forClassLoader()); }
private static Collection<URL> effectiveClassPathUrls(ClassLoader... classLoaders) { return ClasspathHelper.forManifest(ClasspathHelper.forClassLoader(classLoaders)); }
@BeforeClass public static void overrideClassLoader() { loader = Thread.currentThread().getContextClassLoader(); Collection<URL> urls = ClasspathHelper.forClassLoader(); ClassLoader cl = URLClassLoader.newInstance(urls.toArray(new URL[urls.size()]), null/*no delegation*/); Thread.currentThread().setContextClassLoader(cl); }
s.addAll(ClasspathHelper.forClassLoader()); s.addAll(ClasspathHelper.forJavaClassPath()); final Iterator<URL> iterator = s.iterator();
/** * Scan the classpath for {@link #classpathRootName} and return all resources under it. * {@inheritDoc} * @see org.apache.gobblin.config.store.deploy.DeployableConfigSource#getDeployableConfigPaths() */ private Set<String> getDeployableConfigPaths() { ConfigurationBuilder cb = new ConfigurationBuilder().setUrls(ClasspathHelper.forClassLoader()).setScanners(new ResourcesScanner()) .filterInputsBy(new FilterBuilder().include(String.format(".*%s.*", this.classpathRootName))); Reflections reflections = new Reflections(cb); Pattern pattern = Pattern.compile(".*"); return reflections.getResources(pattern); }
builder.addUrls(ClasspathHelper.forClassLoader(classLoaders)); //default urls getResources("") } else { builder.addUrls(ClasspathHelper.forClassLoader()); //default urls getResources("")
builder.addUrls(ClasspathHelper.forClassLoader(classLoaders)); //default urls getResources("") } else { builder.addUrls(ClasspathHelper.forClassLoader()); //default urls getResources("")
/** * To handle the situation where classpath is specified in the manifest of the jar, we have to augment the URLs. * This happens as part of the surefire plugin as well as elsewhere in the wild (especially in maven when running tests. ;). * @param classLoaders * @return A collection of URLs representing the effective classpath URLs */ private static Collection<URL> effectiveClassPathUrls(ClassLoader... classLoaders) { return ClasspathHelper.forManifest(ClasspathHelper.forClassLoader(classLoaders)); }
private void findExtensionsInClasspath() { final Collection<URL> mulePluginsUrls = forClassLoader(classLoader).stream() .filter(url -> url.getPath().contains(MULE_PLUGIN_CLASSIFIER)) .collect(toList()); Set<Class<?>> annotated = getExtensionTypes(mulePluginsUrls); annotated.forEach(type -> getAnnotation(type, Extension.class) .ifPresent(extension -> extensionsByName.put(extension.name(), type))); }
public static Collection<URL> forClassLoader() { // return forClassLoader(classLoaders(), ClasspathHelper.class.getClassLoader()); return forClassLoader(ClasspathHelper.class.getClassLoader()); }
private void findExtensionsInClasspath() { final Collection<URL> mulePluginsUrls = forClassLoader(classLoader).stream() .filter(url -> url.getPath().contains(MULE_PLUGIN_CLASSIFIER)) .collect(toList()); Set<Class<?>> annotated = getExtensionTypes(mulePluginsUrls); annotated.forEach(type -> getAnnotation(type, Extension.class) .ifPresent(extension -> extensionsByName.put(extension.name(), type))); }
private static Collection<URL> getUrls(List<ClassLoader> classLoadersList) { classLoadersList.add(ClasspathHelper.contextClassLoader()); classLoadersList.add(ClasspathHelper.staticClassLoader()); Collection<URL> urls = ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0])); CLASS_LOADER = new URLClassLoader(urls.toArray(new URL[0])); return urls; }
public TorchCompilerModule(TorchCompilerEntrypoint entrypoint, RoundEnvironment roundEnvironment) { this.entrypoint = entrypoint; this.roundEnvironment = roundEnvironment; ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setUrls(ClasspathHelper.forClassLoader()); configurationBuilder.addUrls(TorchCompilerModule.class.getProtectionDomain().getCodeSource().getLocation()); reflections = new Reflections(configurationBuilder); }
private Collection<ModuleInfo> extractModulesInfo( ServletContext servletContext ) throws IOException, URISyntaxException { if ( servletContext.getServerInfo() != null && servletContext.getServerInfo().contains( "WebLogic" ) ) { LOG.debug( "Running on weblogic. Not extracting module info from classpath, but from WEB-INF/lib." ); return ModuleInfo.extractModulesInfo( forWebInfLib( servletContext ) ); } return ModuleInfo.extractModulesInfo( forClassLoader() ); }
@Override public Builder defaults() { List<URL> filteredClasspathResources = ClasspathHelper.forClassLoader().stream() .filter(url -> url != null && url.toExternalForm().endsWith("/target/test-classes/")) .collect(toList()); return super.defaults().withClasspathLocations(filteredClasspathResources); } }
/** * Scan the classpath for {@link #classpathRootName} and return all resources under it. * {@inheritDoc} * @see org.apache.gobblin.config.store.deploy.DeployableConfigSource#getDeployableConfigPaths() */ private Set<String> getDeployableConfigPaths() { ConfigurationBuilder cb = new ConfigurationBuilder().setUrls(ClasspathHelper.forClassLoader()).setScanners(new ResourcesScanner()) .filterInputsBy(new FilterBuilder().include(String.format(".*%s.*", this.classpathRootName))); Reflections reflections = new Reflections(cb); Pattern pattern = Pattern.compile(".*"); return reflections.getResources(pattern); }
private static Reflections createReflections() { List<ClassLoader> classLoadersList = new LinkedList<>(); classLoadersList.add(ClasspathHelper.contextClassLoader()); classLoadersList.add(ClasspathHelper.staticClassLoader()); return new Reflections(new ConfigurationBuilder() .setScanners(new SubTypesScanner(false /* don't exclude Object.class */), new ResourcesScanner()) .setUrls(ClasspathHelper.forManifest(ClasspathHelper.forClassLoader( classLoadersList.toArray(new ClassLoader[classLoadersList.size()])))) .filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("com.kakao.hbase.manager.command")))); }