Package weka.core

# Class WekaPackageLibIsolatingClassLoader

java.lang.Object
java.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
weka.core.WekaPackageLibIsolatingClassLoader

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`

public class WekaPackageLibIsolatingClassLoader extends URLClassLoader

A ClassLoader that loads/finds classes from one Weka plugin package. This includes the top-level jar file(s) and third-party libraries in the package's lib directory. First checks the parent classloader (typically application classloader) - covers general stuff and weka core classes. Next tries the package jar files and third-party libs covered by this classloader/package. Next tries packages this one depends on and their third-party libs - this is transitive. Finally tries all top-level package jar files over all packages.

The basic assumption for Weka packages is that classes present in top-level jar package jar files contain Weka-related code (schemes, filters, GUI panels, tools, etc.), that is visible to all other packages via Weka's dynamic class discovery mechanism. A top-level jar file should not contain any third-party library code. If package A needs to compile against (and explicitly reference) classes provided by package B (either top-level jar or third-party library), then it should declare a dependency on package B.

Version:
  $Revision: $
Author:
  Mark Hall (mhall{[at]}pentaho{[dot]}com)

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `WekaPackageLibIsolatingClassLoader(WekaPackageClassLoaderManager repo, File packageDir)`
  Constructor

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static boolean`
  `checkForMissingFiles(Package toLoad, File packageRoot, PrintStream... progress)`
  Checks to see if there are any missing files/directories for a given package.
  `List<WekaPackageLibIsolatingClassLoader>`
  `getPackageClassLoadersForDependencies()`
  Gets a list of class loaders for the packages that this one depends on
  `Set<String>`
  `getPackageJarEntries()`
  Get a Set of the names of all classes contained within top-level jar files in this package
  `String`
  `getPackageName()`
  Return the name of the package that this classloader loads classes for
  `URL`
  `getResource(String name)`
  Find a named resource.
  `Enumeration<URL>`
  `getResources(String name)`
  Find an enumeration of resources matching the supplied name.
  `boolean`
  `hasThirdPartyClass(String className)`
  Returns true if this classloader is covering the named third-party class
  `String`
  `toString()`
  String representation of this classloader

  ### Methods inherited from class java.net.URLClassLoader

  `close, findResource, findResources, getResourceAsStream, getURLs, newInstance, newInstance`

  ### Methods inherited from class java.lang.ClassLoader

  `clearAssertionStatus, getDefinedPackage, getDefinedPackages, getName, getParent, getPlatformClassLoader, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus`

  ### Methods inherited from class java.lang.Object

  `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### WekaPackageLibIsolatingClassLoader

    public WekaPackageLibIsolatingClassLoader(WekaPackageClassLoaderManager repo, File packageDir) throws Exception
    Constructor
    Parameters:
      `repo` - a reference to the classloader manager
      `packageDir` - the package directory for the package covered by this classloader
    Throws:
      `Exception` - if a problem occurs

- ## Method Details

  - ### getPackageClassLoadersForDependencies

    public List<WekaPackageLibIsolatingClassLoader> getPackageClassLoadersForDependencies()
    Gets a list of class loaders for the packages that this one depends on
    Returns:
      a list of class loaders for the packages that this one depends on

  - ### getResource

    public URL getResource(String name)
    Find a named resource. First checks parent classloader and stuff covered by this classloader. Next tries packages that this one depends on.
    Overrides:
      `getResource` in class `ClassLoader`
    Parameters:
      `name` - the name of the resource to look for
    Returns:
      the URL of the resource, or null if the resource is not found

  - ### getResources

    public Enumeration<URL> getResources(String name) throws IOException
    Find an enumeration of resources matching the supplied name. First checks parent classloader and stuff covered by this classloader. Next tries packages that this one depends on.
    Overrides:
      `getResources` in class `ClassLoader`
    Parameters:
      `name` - the name to look for
    Returns:
      an enumeration of URLs
    Throws:
      `IOException` - if a problem occurs

  - ### hasThirdPartyClass

    public boolean hasThirdPartyClass(String className)
    Returns true if this classloader is covering the named third-party class
    Parameters:
      `className` - the third-party classname to check for
    Returns:
      true if this classloader is covering the named third-party class

  - ### toString

    public String toString()
    String representation of this classloader
    Overrides:
      `toString` in class `Object`
    Returns:
      the string representation of this classloader

  - ### getPackageName

    public String getPackageName()
    Return the name of the package that this classloader loads classes for
    Returns:
      return the name of the package that this classloader loads classes for

  - ### getPackageJarEntries

    public Set<String> getPackageJarEntries()
    Get a Set of the names of all classes contained within top-level jar files in this package
    Returns:
      a Set of the names of classes contained in top-level jar files in this package

  - ### checkForMissingFiles

    public static boolean checkForMissingFiles(Package toLoad, File packageRoot, PrintStream... progress)
    Checks to see if there are any missing files/directories for a given package. If there are missing files, then the package can't be loaded. An example would be a connector package that, for whatever reason, can't include a necessary third-party jar file in its lib folder, and requires the user to download and install this jar file manually.
    Parameters:
      `toLoad` - the package to check
      `packageRoot` - the root directory of the package
      `progress` - for printing progress/error info
    Returns:
      true if good to go