/** * Finds a system resource (which should be loaded from the parent * classloader). * * @param name The name of the system resource to load. * Must not be <code>null</code>. * * @return a stream to the named resource, or <code>null</code> if * the resource cannot be found. */ private InputStream loadBaseResource(String name) { return parent == null ? super.getResourceAsStream(name) : parent.getResourceAsStream(name); }
@Override protected synchronized Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException { return super.loadClass(name, resolve); }
@Override public URL getResource(String name) { return this.enclosingClassLoader.getResource(name); }
/** * Resolves a URL for the underlying class path resource. * @return the resolved URL, or {@code null} if not resolvable */ @Nullable protected URL resolveURL() { if (this.clazz != null) { return this.clazz.getResource(this.path); } else if (this.classLoader != null) { return this.classLoader.getResource(this.path); } else { return ClassLoader.getSystemResource(this.path); } }
/** * Returns an unsafe class injector for the platform class loader. For VMs of version 8 or older, * the extension class loader is represented instead. * * @return A class injector for the platform class loader. */ public static ClassInjector ofPlatformLoader() { return new UsingUnsafe(ClassLoader.getSystemClassLoader().getParent()); }
@Override public Enumeration<URL> getResources(String name) throws IOException { return this.enclosingClassLoader.getResources(name); }
private static void load(LangLocale locale) { ResourceBundle bundle; ClassLoader classLoader = ClassLoader.getSystemClassLoader(); String resName = String.format("i18n/Messages_%s.properties", locale.get()); URL bundleUrl = classLoader.getResource(resName); if (bundleUrl == null) { throw new JadxRuntimeException("Locale resource not found: " + resName); } try (Reader reader = new InputStreamReader(bundleUrl.openStream(), StandardCharsets.UTF_8)) { bundle = new PropertyResourceBundle(reader); } catch (IOException e) { throw new JadxRuntimeException("Failed to load " + resName, e); } i18nMessagesMap.put(locale, bundle); }
static ClassLoader getSystemClassLoader() { if (System.getSecurityManager() == null) { return ClassLoader.getSystemClassLoader(); } else { return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { @Override public ClassLoader run() { return ClassLoader.getSystemClassLoader(); } }); } }
/** * 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; }
/** * {@inheritDoc} */ public boolean matches(T target) { ClassLoader current = classLoader; while (current != null) { if (current == target) { return true; } current = current.getParent(); } return target == null; }
/** * 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; }
private static ImmutableList<URL> getClassLoaderUrls(ClassLoader classloader) { if (classloader instanceof URLClassLoader) { return ImmutableList.copyOf(((URLClassLoader) classloader).getURLs()); } if (classloader.equals(ClassLoader.getSystemClassLoader())) { return parseJavaClassPath(); } return ImmutableList.of(); }
/** * Returns a type pool that attempts type descriptions by loadings types from the platform class loader. * If the current VM is Java 8 or older, the extension class loader is represented instead. * * @return An class loading type pool for the system class loader. */ public static TypePool ofPlatformLoader() { return of(ClassLoader.getSystemClassLoader().getParent()); }
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 @Nullable public InputStream getResourceAsStream(String name) { return this.enclosingClassLoader.getResourceAsStream(name); }
@Override protected synchronized Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException { return super.loadClass(name, resolve); }
private static boolean hasResource(String path) { try { return Version.class.getClassLoader().getResource(path) != null; } catch (Throwable t) { return false; } }
/** * {@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 Properties loadFilterConfig() throws IOException { Properties filterProperties = new Properties(); loadFilterConfig(filterProperties, ClassLoader.getSystemClassLoader()); loadFilterConfig(filterProperties, FilterManager.class.getClassLoader()); loadFilterConfig(filterProperties, Thread.currentThread().getContextClassLoader()); loadFilterConfig(filterProperties, FilterManager.class.getClassLoader()); return filterProperties; }