@Override public Enumeration<URL> getResources(String name) throws IOException { return this.enclosingClassLoader.getResources(name); }
/** * Returns the URL of the index page jelly script. */ public URL getIndexPage() { // In the current impl dependencies are checked first, so the plugin itself // will add the last entry in the getResources result. URL idx = null; try { Enumeration<URL> en = classLoader.getResources("index.jelly"); while (en.hasMoreElements()) idx = en.nextElement(); } catch (IOException ignore) { } // In case plugin has dependencies but is missing its own index.jelly, // check that result has this plugin's artifactId in it: return idx != null && idx.toString().contains(shortName) ? idx : null; }
/** * {@inheritDoc} */ public Enumeration<URL> getResources(String name) throws IOException { List<Enumeration<URL>> enumerations = new ArrayList<Enumeration<URL>>(parents.size() + 1); for (ClassLoader parent : parents) { enumerations.add(parent.getResources(name)); } enumerations.add(super.getResources(name)); return new CompoundEnumeration(enumerations); }
public static String getVersion() { try { ClassLoader classLoader = Jadx.class.getClassLoader(); if (classLoader != null) { Enumeration<URL> resources = classLoader.getResources("META-INF/MANIFEST.MF"); while (resources.hasMoreElements()) { Manifest manifest = new Manifest(resources.nextElement().openStream()); String ver = manifest.getMainAttributes().getValue("jadx-version"); if (ver != null) { return ver; } } } } catch (Exception e) { LOG.error("Can't get manifest file", e); } return "dev"; } }
public static List<URL> findResources(String name) { try { Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources(name); List<URL> ret = new ArrayList<URL>(); while (resources.hasMoreElements()) { ret.add(resources.nextElement()); } return ret; } catch (IOException e) { throw new RuntimeException(e); } }
@Override protected Enumeration<URL> findResources(String name) throws IOException { List<URL> resources = new ArrayList<URL>(); if (FAST_LOOKUP) { for (PluginWrapper p : activePlugins) { resources.addAll(Collections.list(ClassLoaderReflectionToolkit._findResources(p.classLoader, name))); } } else { for (PluginWrapper p : activePlugins) { resources.addAll(Collections.list(p.classLoader.getResources(name))); } } return Collections.enumeration(resources); }
private static void loadFilterConfig(Properties filterProperties, ClassLoader classLoader) throws IOException { if (classLoader == null) { return; } for (Enumeration<URL> e = classLoader.getResources("META-INF/druid-filter.properties"); e.hasMoreElements();) { URL url = e.nextElement(); Properties property = new Properties(); InputStream is = null; try { is = url.openStream(); property.load(is); } finally { JdbcUtils.close(is); } filterProperties.putAll(property); } }
@Override public Enumeration<URL> getResources(String name) throws IOException { if (CandidateComponentsIndexLoader.COMPONENTS_RESOURCE_LOCATION.equals(name)) { if (this.resourceUrls != null) { return this.resourceUrls; } throw this.cause; } return super.getResources(name); }
@Nullable private static CandidateComponentsIndex doLoadIndex(ClassLoader classLoader) { if (shouldIgnoreIndex) { return null; } try { Enumeration<URL> urls = classLoader.getResources(COMPONENTS_RESOURCE_LOCATION); if (!urls.hasMoreElements()) { return null; } List<Properties> result = new ArrayList<>(); while (urls.hasMoreElements()) { URL url = urls.nextElement(); Properties properties = PropertiesLoaderUtils.loadProperties(new UrlResource(url)); result.add(properties); } if (logger.isDebugEnabled()) { logger.debug("Loaded " + result.size() + "] index(es)"); } int totalCount = result.stream().mapToInt(Properties::size).sum(); return (totalCount > 0 ? new CandidateComponentsIndex(result) : null); } catch (IOException ex) { throw new IllegalStateException("Unable to load indexes from location [" + COMPONENTS_RESOURCE_LOCATION + "]", ex); } }
@Override public Enumeration<URL> getResources( String name ) throws IOException { return name.startsWith( "META-INF/services" ) ? super.getResources( "test/" + name ) : super.getResources( name ); }
/** * Find all class location resources with the given path via the ClassLoader. * Called by {@link #findAllClassPathResources(String)}. * @param path the absolute path within the classpath (never a leading slash) * @return a mutable Set of matching Resource instances * @since 4.1.1 */ protected Set<Resource> doFindAllClassPathResources(String path) throws IOException { Set<Resource> result = new LinkedHashSet<>(16); ClassLoader cl = getClassLoader(); Enumeration<URL> resourceUrls = (cl != null ? cl.getResources(path) : ClassLoader.getSystemResources(path)); while (resourceUrls.hasMoreElements()) { URL url = resourceUrls.nextElement(); result.add(convertClassLoaderURL(url)); } if ("".equals(path)) { // The above result is likely to be incomplete, i.e. only containing file system references. // We need to have pointers to each of the jar files on the classpath as well... addAllClassLoaderJarRoots(cl, result); } return result; }
public static void checkDuplicate(String path, boolean failOnError) { try { // search in caller's classloader Enumeration<URL> urls = ClassHelper.getCallerClassLoader(Version.class).getResources(path); Set<String> files = new HashSet<String>(); while (urls.hasMoreElements()) { URL url = urls.nextElement(); if (url != null) { String file = url.getFile(); if (file != null && file.length() > 0) { files.add(file); } } } // duplicated jar is found if (files.size() > 1) { String error = "Duplicate class " + path + " in " + files.size() + " jar " + files; if (failOnError) { throw new IllegalStateException(error); } else { logger.error(error); } } } catch (Throwable e) { logger.error(e.getMessage(), e); } }
@Override public Enumeration<URL> getResources(String name) throws IOException { if (isMasked(name)) return Collections.emptyEnumeration(); return super.getResources(name); }
private void loadDirectory(Map<String, Class<?>> extensionClasses, String dir, String type) { String fileName = dir + type; try { Enumeration<java.net.URL> urls; ClassLoader classLoader = findClassLoader(); if (classLoader != null) { urls = classLoader.getResources(fileName); } else { urls = ClassLoader.getSystemResources(fileName); } if (urls != null) { while (urls.hasMoreElements()) { java.net.URL resourceURL = urls.nextElement(); loadResource(extensionClasses, classLoader, resourceURL); } } } catch (Throwable t) { logger.error("Exception occurred when loading extension class (interface: " + type + ", description file: " + fileName + ").", t); } }
private void loadDirectory(Map<String, Class<?>> extensionClasses, String dir, String type) { String fileName = dir + type; try { Enumeration<java.net.URL> urls; ClassLoader classLoader = findClassLoader(); if (classLoader != null) { urls = classLoader.getResources(fileName); } else { urls = ClassLoader.getSystemResources(fileName); } if (urls != null) { while (urls.hasMoreElements()) { java.net.URL resourceURL = urls.nextElement(); loadResource(extensionClasses, classLoader, resourceURL); } } } catch (Throwable t) { logger.error("Exception occurred when loading extension class (interface: " + type + ", description file: " + fileName + ").", t); } }
@Override public Enumeration<URL> getResources(String name) throws IOException { // If this is an SPI resource, use SPI resources if (isSpiClass(name)) { return spiClassLoader.getResources(name); } // Use local resources return super.getResources(name); }
@Override public Enumeration<URL> getResources( String name ) throws IOException { return name.startsWith( "META-INF/services" ) ? Collections.enumeration( Collections.<URL>emptySet() ) : super.getResources( name ); }
@Override public Enumeration<URL> getResources(final String name) throws IOException { final List<URL> urls = new ArrayList<>(); Iterators.addAll(urls, Iterators.forEnumeration(super.getResources(name))); Iterators.addAll(urls, Iterators.forEnumeration(druidLoader.getResources(name))); return Iterators.asEnumeration(urls.iterator()); } }
@Test public void testDoesNotFindExistingResourceWithGetResourcesAndNullOverride() throws IOException { assertNotNull(thisClassLoader.getResources(EXISTING_RESOURCE)); overridingLoader.override(EXISTING_RESOURCE, null); assertEquals(0, countElements(overridingLoader.getResources(EXISTING_RESOURCE))); }
@Test public void testFindsExistingResourceWithGetResourcesAndNoOverrides() throws IOException { assertNotNull(thisClassLoader.getResources(EXISTING_RESOURCE)); assertNotNull(overridingLoader.getResources(EXISTING_RESOURCE)); assertEquals(1, countElements(overridingLoader.getResources(EXISTING_RESOURCE))); }