Search in sources :

Example 1 with PackageFilterClassLoader

use of io.cdap.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, exportPackages::contains);
    // followed by template export-packages, then by a plugin lib jars.
    return new CombineClassLoader(programClassLoader.getParent(), filteredTemplateClassLoader);
}
Also used : CombineClassLoader(io.cdap.cdap.common.lang.CombineClassLoader) ProgramClassLoader(io.cdap.cdap.internal.app.runtime.ProgramClassLoader) ProgramClassLoader(io.cdap.cdap.internal.app.runtime.ProgramClassLoader) DirectoryClassLoader(io.cdap.cdap.common.lang.DirectoryClassLoader) CombineClassLoader(io.cdap.cdap.common.lang.CombineClassLoader) PackageFilterClassLoader(io.cdap.cdap.common.lang.PackageFilterClassLoader) Manifest(java.util.jar.Manifest) PackageFilterClassLoader(io.cdap.cdap.common.lang.PackageFilterClassLoader)

Aggregations

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