Class PluginClassLoader
- All Implemented Interfaces:
Closeable
,AutoCloseable
Each Plugin
has classes loaded from its own DefaultPluginClassLoader
. These should inherit from the
Engine
's class loader, so that the plugins can access the core classes. Plugins can also depend on other
plugins, which allows classes for this plugin to be loaded/linked from another plugin's class loader.
TODO add some integration tests for the plugin mechanism?
-
Constructor Summary
ConstructorDescriptionPluginClassLoader
(ClassLoader engineClassLoader, URL jarUrl, URL... dependencies) Create a new plugin class loader -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDependency
(PluginClassLoader classLoader) Add a plugin dependency to this plugin.protected boolean
boolean
void
freeze()
Prevent further plugins from being added to this one, just in case...getResource
(String name) Get a resource from local resources, engine resources, then falling back to plugin resourcesgetResourceAsStream
(String name) getResources
(String name) int
hashCode()
protected Class<?>
protected Class<?>
loadClassLocally
(String name, boolean resolve) Attempt to load a class directly from this classloader's classpath, without delegating the search anywhere else.static PluginClassLoader
newDummy()
Returns a plugin class loader to use in test situations.void
setPluginDescriptor
(nz.org.riskscape.engine.plugin.PluginDescriptor toSet) Assign thePluginDescriptor
that uses this class loader - this should be a strictly 1-1 relationship.toString()
Methods inherited from class java.net.URLClassLoader
addURL, close, definePackage, findClass, findResource, findResources, getPermissions, getURLs, newInstance, newInstance
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Constructor Details
-
PluginClassLoader
Create a new plugin class loader
- Parameters:
jarUrl
- primary library that constitutes this plugin's codedependencies
- Array of urls to subsidiary dependencies with own libraries and all exported libraries of plugins that are required for this plugin.engineClassLoader
- the parent class loader, expected to be the engine's class loader
-
-
Method Details
-
newDummy
Returns a plugin class loader to use in test situations. Likely to go bang if you try and load classes from it
-
setPluginDescriptor
public void setPluginDescriptor(nz.org.riskscape.engine.plugin.PluginDescriptor toSet) Assign the
PluginDescriptor
that uses this class loader - this should be a strictly 1-1 relationship. -
addDependency
Add a plugin dependency to this plugin. The given class loader will be searched for classes once loading fails from this classloader's resources, the engine's classloader, and finally the system class path.
-
freeze
public void freeze()Prevent further plugins from being added to this one, just in case... who knows what that will do?
-
loadClass
- Overrides:
loadClass
in classClassLoader
- Throws:
ClassNotFoundException
-
loadClassLocally
Attempt to load a class directly from this classloader's classpath, without delegating the search anywhere else. This is used by other PluginClassLoader's to search for their dependencies, and is never called from
this
.NB it does end up searching the engine's classpath as well, which is harmless but wasteful. I'm a little shy of changing this class loader too much, due to general ignorance and inexperience with implementing custom classloaders
- Throws:
ClassNotFoundException
-
getResource
Get a resource from local resources, engine resources, then falling back to plugin resources
- Overrides:
getResource
in classClassLoader
-
getResources
- Overrides:
getResources
in classClassLoader
- Throws:
IOException
-
getResourceAsStream
- Overrides:
getResourceAsStream
in classURLClassLoader
-
toString
-
getI18nResourceLoader
- Returns:
- a lazily-created ResourceClassLoader that is configured to load resources (and not classes) from the i18n directory next to the code plugin code.
-
equals
-
canEqual
-
hashCode
public int hashCode() -
getDependencies
-
getJarUrl
-