Creates a {@link ClassLoader} which accesses the given collection of
plugins.

@param source The plugins.
@param parent The parent ClassLoader.
@return The created ClassLoader.
344774
protected final DelegateClassLoader createClassLoader(PluginSource source,
            ClassLoader parent) {
        final Stream<URL> urls = Require.nonNullResult(source.getPluginURLs(),
                "pluginSource.getPluginURLs");
        return DelegateClassLoader.forPlugins(urls, parent);
    }
663055
public static void load(Class<?> parent, ClassLoader cl) {
    char[] buf = new char[0x4000];
    try {
      String fullName = RESOURCE_PREFIX + parent.getName();
      Enumeration<URL> configfiles = cl.getResources(fullName);
      while(configfiles.hasMoreElements()) {
        URL nextElement = configfiles.nextElement();
        URLConnection conn = nextElement.openConnection();
        conn.setUseCaches(false);
        try (
            InputStreamReader is = new InputStreamReader(conn.getInputStream(), "UTF-8");) {
          int start = 0, cur = 0, valid = is.read(buf, 0, buf.length);
          char c;
          while(cur < valid) {
            // Find newline or end
            while(cur < valid && (c = buf[cur]) != '\n' && c != '\r') {
              cur++;
            }
            if(cur == valid && is.ready()) {
              // Move consumed buffer contents:
              if(start > 0) {
                System.arraycopy(buf, start, buf, 0, valid - start);
                valid -= start;
                cur -= start;
                start = 0;
              }
              else if(valid == buf.length) {
                throw new IOException("Buffer size exceeded. Maximum line length in service files is: " + buf.length + " in file: " + fullName);
              }
              valid = is.read(buf, valid, buf.length - valid);
              continue;
            }
            parseLine(parent, buf, start, cur);
            while(cur < valid && ((c = buf[cur]) == '\n' || c == '\r')) {
              cur++;
            }
            start = cur;
          }
        }
        catch(IOException x) {
          throw new AbortException("Error reading configuration file", x);
        }
      }
    }
    catch(IOException x) {
      throw new AbortException("Could not load service configuration files.", x);
    }
  }
873638
private Class<?> loadClass(final String classname) throws PluginException {
        if (null == classname) {
            throw new IllegalArgumentException("A null java class name was specified.");
        }
        if (null != classCache.get(classname)) {
            return classCache.get(classname);
        }
        CachedJar cachedJar1 = getCachedJar();

        debug("loadClass! " + classname + ": " + cachedJar1.getCachedJar());
        final Class<?> cls;
        final URLClassLoader urlClassLoader = cachedJar1.getClassLoader();
        try {
            cls = Class.forName(classname, true, urlClassLoader);
            classCache.put(classname, cls);
        } catch (ClassNotFoundException e) {
            throw new PluginException("Class not found: " + classname, e);
        } catch (Throwable t) {
            throw new PluginException("Error loading class: " + classname, t);
        }
        return cls;
    }
77344
public static DynamicClassLoader create(ClassLoader parent,
                                          PathImpl path)
  {
    DynamicClassLoader loader = new DynamicClassLoader(parent, false, false);

    loader.addLoader(new SimpleLoader(loader, path));

    loader.init();
    
    return loader;
  }
615806
protected PluginClassLoader createPluginClassLoader(final File pluginFile) throws IOException {
        return new PluginClassLoader(pluginFile, Thread.currentThread().getContextClassLoader()) {
            @Override
            protected File createWorkDir(File pluginArtifactFile) throws IOException {
                File workDir = new File(pluginFile.getParentFile(), ".work"); //$NON-NLS-1$
                workDir.mkdirs();
                return workDir;
            }
        };
    }
384404
Class loadAccessClass (String name) {
		// No need to check the parent class loader if the access class hasn't been defined yet.
		if (localClassNames.contains(name)) {
			try {
				return loadClass(name, false);
			} catch (ClassNotFoundException ex) {
				throw new RuntimeException(ex); // Should not happen, since we know the class has been defined.
			}
		}
		return null;
	}
840909
public static DelegateClassLoader forPlugins(Stream<URL> urls,
            ClassLoader appClassLoader) {
        Require.nonNull(urls, "urls");
        Require.nonNull(appClassLoader, "parent");

        final Collection<DependencyResolver> plugins = new ArrayList<>();
        final Collection<PluginInformation> information = new ArrayList<>();
        final DependencyResolver delegator = new DelegateDependencyResolver(plugins);
        final Iterator<URL> it = urls.iterator();
        while (it.hasNext()) {
            final URL pluginURL = it.next();
            // Plugin classloaders must be created with the application
            // classloader as parent. This is mandatory for establishing a sound
            // locking strategy during class lookup.
            final PluginClassLoader pluginCl = PluginClassLoader.create(pluginURL,
                    appClassLoader, delegator);
            plugins.add(pluginCl);
            information.add(pluginCl.getPluginInformation());
        }
        return AccessController.doPrivileged(new PrivilegedAction<DelegateClassLoader>() {

            @Override
            public DelegateClassLoader run() {
                return new DelegateClassLoader(appClassLoader, delegator, information);
            }
        });
    }
489472
public static JsonNode readJson(Reader source, ClassLoader classLoader) {
        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
        if (classLoader != null) {
            Thread.currentThread().setContextClassLoader(classLoader);
        }
        try {
            if (source == null) {
                return NullNode.instance;
            }
            ObjectMapper mapper = poolMapper.borrowObject();
            if (mapper != null) {
                try {
                    return mapper.readTree(source);
                } finally {
                    poolMapper.returnObject(mapper);
                }
            }
            throw new SerializationException("No ObjectMapper instance avaialble!");
        } catch (Exception e) {
            throw e instanceof SerializationException ? (SerializationException) e
                    : new SerializationException(e);
        } finally {
            Thread.currentThread().setContextClassLoader(oldClassLoader);
        }
    }
38504
public static Class getGenericClassFromParent(Object parent) {
		return (Class) ((ParameterizedType) parent.getClass().getGenericSuperclass()).getActualTypeArguments()[0];
	}
1330338
public void delegateTo(final ClassLoader classLoader, final boolean isParent) {
        if (classLoader == null) {
            return;
        }
        // Check if this is a parent before checking if the classloader is already in the delegatedTo set,
        // so that if the classloader is a context classloader but also a parent, it still gets marked as
        // a parent classloader.
        if (isParent) {
            allParentClassLoaders.add(classLoader);
        }
        if (delegatedTo.add(classLoader)) {
            // Find ClassLoaderHandlerRegistryEntry for this classloader
            final ClassLoaderHandlerRegistryEntry entry = getRegistryEntry(classLoader);
            // Delegate to this classloader, by recursing to that classloader to get its classloader order
            entry.findClassLoaderOrder(classLoader, this);
        }
    }
1264393
public static void findClassLoaderOrder(final ClassLoader classLoader,
            final ClassLoaderOrder classLoaderOrder) {
        // The Restart classloader is a parent-last classloader, so need to delegate to the context
        // classloader(s) before the parent.
        classLoaderOrder.delegateTo(Thread.currentThread().getContextClassLoader(), /* isParent = */ false);
        classLoaderOrder.delegateTo(ClassGraph.class.getClassLoader(), /* isParent = */ false);
        // Also delegate to system classloader, in case the above two are actually the same as `classLoader`
        classLoaderOrder.delegateTo(ClassLoader.getSystemClassLoader(), /* isParent = */ true);
        // Finally delegate to the parent of the RestartClassLoader, in case that is different from
        // SystemClassLoader
        classLoaderOrder.delegateTo(classLoader.getParent(), /* isParent = */ true);
    }
897749
public static void findClassLoaderOrder(final ClassLoader classLoader,
            final ClassLoaderOrder classLoaderOrder) {
        classLoaderOrder.delegateTo(classLoader.getParent(), /* isParent = */ true);
        classLoaderOrder.add(classLoader);
    }
119881
public static URLClassLoader getURLClassLoader(final File pluginDir,
      List<String> extLibClassPaths,
      ClassLoader parentLoader) {
    final File libDir = new File(pluginDir, LIBRARY_FOLDER_NAME);
    if (libDir.exists() && libDir.isDirectory()) {
      final File[] files = libDir.listFiles();
      final ArrayList<URL> urls = getUrls(files);

      if (extLibClassPaths != null) {
        for (final String extLibClassPath : extLibClassPaths) {
          try {
            final File extLibFile = new File(pluginDir, extLibClassPath);
            if (extLibFile.exists()) {
              if (extLibFile.isDirectory()) {
                // extLibFile is a directory; load all the files in the
                // directory.
                final File[] extLibFiles = extLibFile.listFiles();
                urls.addAll(getUrls(extLibFiles));
              } else {
                final URL url = extLibFile.toURI().toURL();
                urls.add(url);
              }
            } else {
              logger.error(
                  "External library path not found. path = " + extLibFile.getAbsolutePath()
              );
              continue;
            }
          } catch (final MalformedURLException e) {
            logger.error(
                "Invalid External library path. path = " + extLibClassPath + " dir = " + pluginDir,
                e
            );
          }
        }
      }
      return new URLClassLoader(urls.toArray(new URL[urls.size()]), parentLoader);
    } else {
      logger.error("Library path not found. path = " + libDir);
      return null;
    }
  }
56228
public <T> Collection<T> all(ClassLoader classLoader, Class<T> serviceClass) {
        Validate.notNull(classLoader, "ClassLoader must be provided");
        Validate.notNull(serviceClass, "ServiceClass must be provided");

        return createInstances(
            serviceClass,
            load(serviceClass, classLoader));
    }
1329009
@Override
	public ClassLoader getClassLoader() {
		if (classLoader == null) {
			if (!(super.getClassLoader() instanceof WinletClassLoader))
				classLoader = new WinletClassLoader(getParent()
						.getClassLoader());
		}

		return classLoader;
	}
70294
@VisibleForTesting
  Collection<PluginClassLoaderDef> defineClassloaders(Map<String, PluginInfo> infoByKeys) {
    Map<String, PluginClassLoaderDef> classloadersByBasePlugin = new HashMap<>();

    for (PluginInfo info : infoByKeys.values()) {
      String baseKey = basePluginKey(info, infoByKeys);
      PluginClassLoaderDef def = classloadersByBasePlugin.get(baseKey);
      if (def == null) {
        def = new PluginClassLoaderDef(baseKey);
        classloadersByBasePlugin.put(baseKey, def);
      }
      ExplodedPlugin explodedPlugin = jarExploder.explode(info);
      def.addFiles(asList(explodedPlugin.getMain()));
      def.addFiles(explodedPlugin.getLibs());
      def.addMainClass(info.getKey(), info.getMainClass());

      for (String defaultSharedResource : DEFAULT_SHARED_RESOURCES) {
        def.getExportMask().addInclusion(String.format("%s/%s/api/", defaultSharedResource, info.getKey()));
      }

      // The plugins that extend other plugins can only add some files to classloader.
      // They can't change metadata like ordering strategy or compatibility mode.
      if (Strings.isNullOrEmpty(info.getBasePlugin())) {
        def.setSelfFirstStrategy(info.isUseChildFirstClassLoader());
        Version minSqVersion = info.getMinimalSqVersion();
        boolean compatibilityMode = minSqVersion != null && minSqVersion.compareToIgnoreQualifier(COMPATIBILITY_MODE_MAX_VERSION) < 0;
        if (compatibilityMode) {
          Loggers.get(getClass()).warn("API compatibility mode is no longer supported. In case of error, plugin {} [{}] should package its dependencies.",
            info.getName(), info.getKey());
        }
      }
    }
    return classloadersByBasePlugin.values();

  }
817781
public ConfigurationBuilder addClassLoaders(Collection<ClassLoader> classLoaders) {
        return addClassLoaders(classLoaders.toArray(new ClassLoader[classLoaders.size()]));
    }