weka.core

## Class WekaPackageLibIsolatingClassLoader

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

- All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

      public class WekaPackageLibIsolatingClassLoader
      extends java.net.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 and Description
    `WekaPackageLibIsolatingClassLoader(WekaPackageClassLoaderManager repo, java.io.File packageDir)` Constructor

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static boolean` | `checkForMissingFiles(Package toLoad, java.io.File packageRoot, java.io.PrintStream... progress)` Checks to see if there are any missing files/directories for a given package.
    `java.util.List<WekaPackageLibIsolatingClassLoader>` | `getPackageClassLoadersForDependencies()` Gets a list of class loaders for the packages that this one depends on
    `java.util.Set<java.lang.String>` | `getPackageJarEntries()` Get a Set of the names of all classes contained within top-level jar files in this package
    `java.lang.String` | `getPackageName()` Return the name of the package that this classloader loads classes for
    `java.net.URL` | `getResource(java.lang.String name)` Find a named resource.
    `java.util.Enumeration<java.net.URL>` | `getResources(java.lang.String name)` Find an enumeration of resources matching the supplied name.
    `boolean` | `hasThirdPartyClass(java.lang.String className)` Returns true if this classloader is covering the named third-party class
    `java.lang.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, getParent, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus`

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

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

- - ### Constructor Detail

    - #### WekaPackageLibIsolatingClassLoader

          public WekaPackageLibIsolatingClassLoader(WekaPackageClassLoaderManager repo,
                                                    java.io.File packageDir)
                                             throws java.lang.Exception

      Constructor
      Parameters:
        `repo` - a reference to the classloader manager
        `packageDir` - the package directory for the package covered by this classloader
      Throws:
        `java.lang.Exception` - if a problem occurs

  - ### Method Detail

    - #### getPackageClassLoadersForDependencies

          public java.util.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 java.net.URL getResource(java.lang.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 `java.lang.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 java.util.Enumeration<java.net.URL> getResources(java.lang.String name)
                                                           throws java.io.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 `java.lang.ClassLoader`
      Parameters:
        `name` - the name to look for
      Returns:
        an enumeration of URLs
      Throws:
        `java.io.IOException` - if a problem occurs

    - #### hasThirdPartyClass

          public boolean hasThirdPartyClass(java.lang.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 java.lang.String toString()

      String representation of this classloader
      Overrides:
        `toString` in class `java.lang.Object`
      Returns:
        the string representation of this classloader

    - #### getPackageName

          public java.lang.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 java.util.Set<java.lang.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,
                                                     java.io.File packageRoot,
                                                     java.io.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