public InputStream getResourceAsStream(final String name) { return ClassLoaderUtils.getResourceAsStream(name, getClass()); } }
public URL getResource(final String name) { return ClassLoaderUtils.getResource(name, getClass()); }
public <T> Class<T> loadClass(final String clazz, final Class<?> callingClass) throws ClassNotFoundException { return ClassLoaderUtils.loadClass(clazz, callingClass); }
/** * Prints the classloader hierarchy from a given classloader - useful for debugging. */ public static void printClassLoader(final ClassLoader cl) { System.out.println("ClassLoaderUtils.printClassLoader(cl = " + cl + ")"); if (cl != null) { printClassLoader(cl.getParent()); } } }
if (contextClassLoader != null) { try { return coerce(contextClassLoader.loadClass(className)); } catch (final ClassNotFoundException e) { return coerce(Class.forName(className)); } catch (final ClassNotFoundException ex) { try { return coerce(ClassLoaderUtils.class.getClassLoader().loadClass(className)); } catch (final ClassNotFoundException exc) { if ((callingClass != null) && (callingClass.getClassLoader() != null)) { return coerce(callingClass.getClassLoader().loadClass(className)); } else { throw exc;
private void loadClassPathPlugins(final ModuleDescriptorFactory moduleDescriptorFactory) throws PluginParseException { final Enumeration<URL> pluginDescriptorFiles; try { pluginDescriptorFiles = ClassLoaderUtils.getResources(fileNameToLoad, this.getClass()); } catch (final IOException e) { log.error("Could not load classpath plugins: " + e, e); return; } pluginLoaderMap = new LinkedHashMap<>(); while (pluginDescriptorFiles.hasMoreElements()) { final URL url = pluginDescriptorFiles.nextElement(); final SinglePluginLoader singlePluginLoader = new SinglePluginLoader(url); for (final Plugin plugin : singlePluginLoader.loadAllPlugins(moduleDescriptorFactory)) { pluginLoaderMap.put(plugin, singlePluginLoader); } } }
/** * Prints the current classloader hierarchy - useful for debugging. */ public static void printClassLoader() { System.out.println("ClassLoaderUtils.printClassLoader"); printClassLoader(Thread.currentThread().getContextClassLoader()); }
InputStream getLegacyPropertiesStream() { return ClassLoaderUtils.getResourceAsStream(LEGACY_PROPERTIES_FILE, this.getClass()); }
public <M> Class<M> loadClass(final String clazz, final Class<?> callingClass) throws ClassNotFoundException { return ClassLoaderUtils.loadClass(clazz, callingClass); }
public URL getResource(final String name) { return ClassLoaderUtils.getResource(name, getClass()); }
public InputStream getResourceAsStream(final String name) { return ClassLoaderUtils.getResourceAsStream(name, getClass()); }
private <D extends ModuleDescriptor<?>> Class<D> getClassFromEntry(final Map.Entry<String, String> entry) { if (shouldSkipModuleOfType(entry.getKey())) { return null; } try { final Class<D> descriptorClass = ClassLoaderUtils.loadClass(entry.getValue(), getClass()); if (!ModuleDescriptor.class.isAssignableFrom(descriptorClass)) { log.error("Configured plugin module descriptor class " + entry.getValue() + " does not inherit from ModuleDescriptor"); return null; } return descriptorClass; } catch (final ClassNotFoundException e) { log.error("Unable to add configured plugin module descriptor " + entry.getKey() + ". Class not found: " + entry.getValue()); return null; } }
/** * This is a convenience method to load a resource as a stream. * * The algorithm used to find the resource is given in getResource() * * @param resourceName The name of the resource to load * @param callingClass The Class object of the calling object */ public static InputStream getResourceAsStream(final String resourceName, final Class<?> callingClass) { final URL url = getResource(resourceName, callingClass); try { return url != null ? url.openStream() : null; } catch (final IOException e) { return null; } }
/** * {@link ClassLoaderUtils} throws {@link IllegalArgumentException} in the case of malformed resource URIs, so let's * use the plugins2 class defensively (FISH-352) * @param resource resource to load * @param clazz reference class * @return an InputStream from the resource, or null if the resource could not be found or there was a problem * reading from the resource */ public static InputStream getResourceAsStream(String resource, Class clazz) { try { return ClassLoaderUtils.getResourceAsStream(resource, clazz); } catch (Exception e) { log.debug("Failed to retrieve resource '" + resource + "'", e); return null; } }
Class spr; try { spr = ClassLoaderUtils.loadClass(cls, this.getClass());
URL url = ClassLoaderUtils.getResource(getPropertiesFile(), DefaultHomeLocator.class); if (url != null)
static Document readPlatformVersionDocument() throws RuntimeException { InputStream in = ClassLoaderUtils.getResourceAsStream(PLATFORM_VERSION_PATH, PlatformVersionSpecReader.class); try { SAXReader reader = new SAXReader(); return reader.read(in); } catch (DocumentException e) { throw new RuntimeException("Cannot read the platform version definition", e); } finally { IOUtils.closeQuietly(in); } }
cls = ClassLoaderUtils.loadClass(className, getClass()); } catch (ClassNotFoundException e) {
protected InputStream getSource() { if (resource != null) { return ClassLoaderUtils.getResourceAsStream(resource, this.getClass()); } if (url != null) { try { return url.openConnection().getInputStream(); } catch (IOException e) { throw new PluginParseException(e); } } throw new IllegalStateException("No defined method for getting an input stream."); } }
private static String getPluginFrameworkVersionInternal() { Properties props = new Properties(); InputStream in = null; try { in = ClassLoaderUtils.getResourceAsStream(BUILD_PROPERTY_PATH, PluginFrameworkUtils.class); if (in != null) { // this should automatically get rid of comment lines. props.load(in); return props.getProperty("version"); } else { // probably ran via IDEA where pom.properties won't exist return "2.7.0"; } } catch (IOException e) { LOG.error("cannot determine the plugin framework version", e); throw new IllegalStateException("cannot determine the plugin framework version", e); } finally { IOUtils.closeQuietly(in); } } }