Class WekaPackageLibIsolatingClassLoader
- All Implemented Interfaces:
Closeable
,AutoCloseable
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
ConstructorDescriptionWekaPackageLibIsolatingClassLoader
(WekaPackageClassLoaderManager repo, File packageDir) Constructor -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
checkForMissingFiles
(Package toLoad, File packageRoot, PrintStream... progress) Checks to see if there are any missing files/directories for a given package.Gets a list of class loaders for the packages that this one depends onGet a Set of the names of all classes contained within top-level jar files in this packageReturn the name of the package that this classloader loads classes forgetResource
(String name) Find a named resource.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 classtoString()
String representation of this classloaderMethods 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
-
Constructor Details
-
WekaPackageLibIsolatingClassLoader
public WekaPackageLibIsolatingClassLoader(WekaPackageClassLoaderManager repo, File packageDir) throws Exception Constructor- Parameters:
repo
- a reference to the classloader managerpackageDir
- the package directory for the package covered by this classloader- Throws:
Exception
- if a problem occurs
-
-
Method Details
-
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
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 classClassLoader
- 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
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 classClassLoader
- Parameters:
name
- the name to look for- Returns:
- an enumeration of URLs
- Throws:
IOException
- if a problem occurs
-
hasThirdPartyClass
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
String representation of this classloader -
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
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 checkpackageRoot
- the root directory of the packageprogress
- for printing progress/error info- Returns:
- true if good to go
-