Search in sources :

Example 1 with PackageFilterClassLoader

use of co.cask.cdap.common.lang.PackageFilterClassLoader in project cdap by caskdata.

the class PluginClassLoader method createParent.

static ClassLoader createParent(ClassLoader templateClassLoader) {
    // Find the ProgramClassLoader from the template ClassLoader
    ClassLoader programClassLoader = templateClassLoader;
    while (programClassLoader != null && !(programClassLoader instanceof ProgramClassLoader)) {
        programClassLoader = programClassLoader.getParent();
    }
    // This shouldn't happen
    Preconditions.checkArgument(programClassLoader != null, "Cannot find ProgramClassLoader");
    // Package filtered classloader of the template classloader, which only classes in "Export-Packages" are loadable.
    Manifest manifest = ((ProgramClassLoader) programClassLoader).getManifest();
    Set<String> exportPackages = ManifestFields.getExportPackages(manifest);
    ClassLoader filteredTemplateClassLoader = new PackageFilterClassLoader(templateClassLoader, Predicates.in(exportPackages));
    // followed by template export-packages, then by a plugin lib jars.
    return new CombineClassLoader(programClassLoader.getParent(), ImmutableList.of(filteredTemplateClassLoader));
}
Also used : CombineClassLoader(co.cask.cdap.common.lang.CombineClassLoader) ProgramClassLoader(co.cask.cdap.internal.app.runtime.ProgramClassLoader) ProgramClassLoader(co.cask.cdap.internal.app.runtime.ProgramClassLoader) DirectoryClassLoader(co.cask.cdap.common.lang.DirectoryClassLoader) PackageFilterClassLoader(co.cask.cdap.common.lang.PackageFilterClassLoader) CombineClassLoader(co.cask.cdap.common.lang.CombineClassLoader) Manifest(java.util.jar.Manifest) PackageFilterClassLoader(co.cask.cdap.common.lang.PackageFilterClassLoader)

Aggregations

CombineClassLoader (co.cask.cdap.common.lang.CombineClassLoader)1 DirectoryClassLoader (co.cask.cdap.common.lang.DirectoryClassLoader)1 PackageFilterClassLoader (co.cask.cdap.common.lang.PackageFilterClassLoader)1 ProgramClassLoader (co.cask.cdap.internal.app.runtime.ProgramClassLoader)1 Manifest (java.util.jar.Manifest)1