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.
| Modifier and Type | Field and Description |
|---|---|
protected WekaPackageClassLoaderManager |
m_classloaderRepo
A reference to the classloader manager
|
protected boolean |
m_debug
True to output debugging info
|
protected java.util.Set<java.lang.String> |
m_libJarEntries
Classes in the lib jar file(s)
|
protected java.util.Set<java.lang.String> |
m_packageDependencies
Which packages this one depends on
|
protected java.util.Set<java.lang.String> |
m_packageJarEntries
Classes in the top-level jar file(s)
|
protected java.util.Set<java.lang.String> |
m_packageJarResources
Resources in the top-level jar file(s)
|
protected java.lang.String |
m_packageName
The name of the package that this classloader loads classes from
|
| Constructor and Description |
|---|
WekaPackageLibIsolatingClassLoader(WekaPackageClassLoaderManager repo,
java.io.File packageDir)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addPackageDependency(java.lang.String packageName)
Add a package dependency to this classloader
|
protected boolean |
checkForMissingClasses(Package toCheck,
java.io.PrintStream... progress)
Checks to see if there are any classes that we should try to instantiate
before allowing this package to be loaded.
|
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.
|
protected java.util.List<java.lang.String> |
checkForNativeLibs(Package toLoad,
java.io.File packageDir)
Checks for native libraries and any native library loader classes, as
specified by the presence of "NativeLibs" and "InjectLoader" entries in the
package's Description.props file respectively.
|
protected static boolean |
checkForUnsetEnvVar(Package toLoad)
Checks to see if there are any environment variables or properties that
should be set at startup before allowing this package to be loaded.
|
protected void |
closeClassLoader()
Try to clear classloader file locks under Windows
|
protected java.lang.Class<?> |
findClass(java.lang.String name)
Find a class using this package classloader.
|
protected java.lang.Class<?> |
findGloballyVisiblePackageClass(java.lang.String name)
Returns a Class object if this classloader covers the named globally
visible class (i.e. its top-level jar(s) contain the class), or null
otherwise.
|
protected java.net.URL |
findGloballyVisiblePackageResource(java.lang.String name)
Returns a URL a resource if this classloader covers the named globally
visible resource (i.e. its top-level jar(s) contain the resource), or null
otherwise
|
protected java.util.Enumeration<java.net.URL> |
findGloballyVisiblePackageResources(java.lang.String name)
return an enumeration of URLS if this classloader covers the named globally
visible resource, or null otherwise.
|
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
|
protected void |
init(java.io.File packageDir)
Initializes the classloader from the package directory.
|
protected void |
installNativeLibs(java.io.File packageDir,
java.lang.String libJar,
java.util.List<java.lang.String> libJarPaths)
Installs any native libraries in the specified jar to $WEKA_HOME/native, if
not already present therein.
|
protected boolean |
integrityCheck()
Check the integrity of this classloader (typically done for each
classloader after all packages have been loaded by the package manager).
|
protected boolean |
nativeLibInstalled(java.lang.String libName)
Returns true if a named native library is already present in
$WEKA_HOME/native
|
protected void |
processDir(java.io.File dir,
java.util.List<java.lang.String> jarsToIgnore,
boolean topLevel)
Process jar files in a directory of this package.
|
protected void |
setSystemProperties(Package toLoad,
java.io.PrintStream... progress)
Set any system properties specified in the metadata for this package
|
protected void |
storeJarContents(java.io.File jarFile,
java.util.Set<java.lang.String> repo,
boolean isTopLevelPackageJar)
Stores all the names of all classes in the supplied jar file in the
supplied set.
|
java.lang.String |
toString()
String representation of this classloader
|
addURL, close, definePackage, findResource, findResources, getPermissions, getResourceAsStream, getURLs, newInstance, newInstanceclearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSignersprotected java.lang.String m_packageName
protected WekaPackageClassLoaderManager m_classloaderRepo
protected java.util.Set<java.lang.String> m_packageJarEntries
protected java.util.Set<java.lang.String> m_packageJarResources
protected java.util.Set<java.lang.String> m_libJarEntries
protected boolean m_debug
protected java.util.Set<java.lang.String> m_packageDependencies
public WekaPackageLibIsolatingClassLoader(WekaPackageClassLoaderManager repo, java.io.File packageDir) throws java.lang.Exception
repo - a reference to the classloader managerpackageDir - the package directory for the package covered by this
classloaderjava.lang.Exception - if a problem occursprotected void init(java.io.File packageDir)
throws java.lang.Exception
packageDir - the home directory for the packagejava.lang.Exception - if a problem occursprotected void addPackageDependency(java.lang.String packageName)
packageName - the name of the package to add as a dependencypublic java.util.List<WekaPackageLibIsolatingClassLoader> getPackageClassLoadersForDependencies()
protected java.util.List<java.lang.String> checkForNativeLibs(Package toLoad, java.io.File packageDir)
toLoad - the package object for the this packagepackageDir - the home directory of the packageprotected void installNativeLibs(java.io.File packageDir,
java.lang.String libJar,
java.util.List<java.lang.String> libJarPaths)
throws java.io.IOException
packageDir - the home directory of this packagelibJar - the path to the jar that contains the libs (relative to the
package home directory)libJarPaths - paths to libraries to install within the jarjava.io.IOException - if a problem occursprotected boolean nativeLibInstalled(java.lang.String libName)
libName - the name of the library to checkprotected void processDir(java.io.File dir,
java.util.List<java.lang.String> jarsToIgnore,
boolean topLevel)
throws java.net.MalformedURLException
dir - the directory to processjarsToIgnore - a list of jar files to ignoretopLevel - true if this is the top-level (home) directory of the
packagejava.net.MalformedURLException - if a problem occursprotected void storeJarContents(java.io.File jarFile,
java.util.Set<java.lang.String> repo,
boolean isTopLevelPackageJar)
jarFile - jar file to processrepo - a set to store class names inisTopLevelPackageJar - true if this jar file is at the top-level of
the package.protected java.lang.Class<?> findClass(java.lang.String name)
throws java.lang.ClassNotFoundException
findClass in class java.net.URLClassLoadername - the name of the class to findjava.lang.ClassNotFoundException - if the class cannot be foundpublic java.net.URL getResource(java.lang.String name)
getResource in class java.lang.ClassLoadername - the name of the resource to look forpublic java.util.Enumeration<java.net.URL> getResources(java.lang.String name)
throws java.io.IOException
getResources in class java.lang.ClassLoadername - the name to look forjava.io.IOException - if a problem occurspublic boolean hasThirdPartyClass(java.lang.String className)
className - the third-party classname to check forprotected java.lang.Class<?> findGloballyVisiblePackageClass(java.lang.String name)
name - the name of the class to check forprotected java.net.URL findGloballyVisiblePackageResource(java.lang.String name)
name - the path to the resourceprotected java.util.Enumeration<java.net.URL> findGloballyVisiblePackageResources(java.lang.String name)
throws java.io.IOException
name - the path of the resource to check forjava.io.IOException - if a problem occursprotected void closeClassLoader()
public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String getPackageName()
public java.util.Set<java.lang.String> getPackageJarEntries()
protected boolean integrityCheck()
throws java.lang.Exception
java.lang.Exceptionprotected void setSystemProperties(Package toLoad, java.io.PrintStream... progress)
toLoad - the package in questionprogress - for printing progress/debug infoprotected boolean checkForMissingClasses(Package toCheck, java.io.PrintStream... progress) throws java.lang.Exception
toCheck - the package in questionprogress - for printing progress/error infojava.lang.Exception - if there is a problempublic static boolean checkForMissingFiles(Package toLoad, java.io.File packageRoot, java.io.PrintStream... progress)
toLoad - the package to checkpackageRoot - the root directory of the packageprogress - for printing progress/error infoprotected static boolean checkForUnsetEnvVar(Package toLoad)
toLoad - the package to check