public class GroovyClassLoader extends URLClassLoader
A ClassLoader which can load Groovy classes. The loaded classes are cached, classes from other classloaders should not be cached. To be able to load a script that was asked for earlier but was created later it is essential not to keep anything like a "class not found" information for that class name. This includes possible parent loaders. Classes that are not cached are always reloaded.
Modifiers | Name | Description |
---|---|---|
static class |
GroovyClassLoader.ClassCollector |
|
static class |
GroovyClassLoader.InnerLoader |
Constructor and description |
---|
GroovyClassLoader() creates a GroovyClassLoader using the current Thread's context Class loader as parent. |
GroovyClassLoader(ClassLoader loader) creates a GroovyClassLoader using the given ClassLoader as parent |
GroovyClassLoader(GroovyClassLoader parent) creates a GroovyClassLoader using the given GroovyClassLoader as parent. |
GroovyClassLoader(ClassLoader parent, CompilerConfiguration config, boolean useConfigurationClasspath) creates a GroovyClassLoader. |
GroovyClassLoader(ClassLoader loader, CompilerConfiguration config) creates a GroovyClassLoader using the given ClassLoader as parent. |
Type Params | Return Type | Name and description |
---|---|---|
|
public void |
addClasspath(String path) adds a classpath to this classloader. |
|
public void |
addURL(URL url) adds a URL to the classloader. |
|
public void |
clearCache() Removes all classes from the class cache. |
|
public void |
close() Closes this GroovyClassLoader and clears any caches it maintains. |
|
public Class |
defineClass(ClassNode classNode, String file, String newCodeBase) Loads the given class node returning the implementation Class. |
|
public Class |
defineClass(String name, byte[] bytes) Converts an array of bytes into an instance of Class . |
|
public String |
generateScriptName() |
|
public Class[] |
getLoadedClasses() |
|
public GroovyResourceLoader |
getResourceLoader() |
|
public boolean |
hasCompatibleConfiguration(CompilerConfiguration config) Check if this class loader has compatible CompilerConfiguration with the provided one. |
|
public Boolean |
isShouldRecompile() gets the currently set recompilation mode. null means, the compiler configuration is used. |
|
public Class |
loadClass(String name, boolean lookupScriptFiles, boolean preferClassOverScript) loads a class from a file or a parent classloader. |
|
public Class |
loadClass(String name, boolean lookupScriptFiles, boolean preferClassOverScript, boolean resolve) loads a class from a file or a parent classloader. |
|
public Class<?> |
loadClass(String name) |
|
public URL |
loadGroovySource(String filename) |
|
public Class |
parseClass(File file) Parses the given file into a Java class capable of being run |
|
public Class |
parseClass(String text, String fileName) Parses the given text into a Java class capable of being run |
|
public Class |
parseClass(String text) Parses the given text into a Java class capable of being run |
|
public Class |
parseClass(Reader reader, String fileName) |
|
public Class |
parseClass(GroovyCodeSource codeSource) |
|
public Class |
parseClass(GroovyCodeSource codeSource, boolean shouldCacheSource) Parses the given code source into a Java class. |
|
public ProtectionDomain |
run() |
|
public void |
setResourceLoader(GroovyResourceLoader resourceLoader) |
|
public void |
setShouldRecompile(Boolean mode) sets if the recompilation should be enable. |
Methods inherited from class | Name |
---|---|
class URLClassLoader |
newInstance, newInstance, findResource, getResourceAsStream, findResources, close, getURLs, getName, loadClass, getPlatformClassLoader, getSystemClassLoader, getSystemResourceAsStream, getSystemResource, getResource, getResources, getDefinedPackage, resources, isRegisteredAsParallelCapable, getSystemResources, getParent, getUnnamedModule, getDefinedPackages, setDefaultAssertionStatus, setPackageAssertionStatus, setClassAssertionStatus, clearAssertionStatus, wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
creates a GroovyClassLoader using the current Thread's context Class loader as parent.
creates a GroovyClassLoader using the given ClassLoader as parent
creates a GroovyClassLoader using the given GroovyClassLoader as parent. This loader will get the parent's CompilerConfiguration
creates a GroovyClassLoader.
parent
- the parent class loaderconfig
- the compiler configurationuseConfigurationClasspath
- determines if the configurations classpath should be addedcreates a GroovyClassLoader using the given ClassLoader as parent.
adds a classpath to this classloader.
path
- is a jar file or a directory.adds a URL to the classloader.
url
- the new classpath elementRemoves all classes from the class cache.
In addition to internal caches this method also clears any previously set MetaClass information for the given set of classes being removed.
Closes this GroovyClassLoader and clears any caches it maintains.
No use should be made of this instance after this method is invoked. Any classes that are already loaded are still accessible.
Loads the given class node returning the implementation Class.
WARNING: this compilation is not synchronized
Converts an array of bytes into an instance of Class
.
Returns all Groovy classes loaded by this class loader.
Check if this class loader has compatible CompilerConfiguration with the provided one.
config
- the compiler configuration to test for compatibilitytrue
if the provided config is exactly the same instance
of CompilerConfiguration as this loader hasgets the currently set recompilation mode. null means, the compiler configuration is used. False means no recompilation and true means that recompilation will be done if needed.
loads a class from a file or a parent classloader. This method does call loadClass(String, boolean, boolean, boolean) with the last parameter set to false.
loads a class from a file or a parent classloader.
name
- of the class to be loadedlookupScriptFiles
- if false no lookup at files is done at allpreferClassOverScript
- if true the file lookup is only done if there is no classresolve
- see ClassLoader.loadClassParses the given file into a Java class capable of being run
file
- the file name to parseParses the given text into a Java class capable of being run
text
- the text of the script/class to parsefileName
- the file name to use as the name of the classParses the given text into a Java class capable of being run
text
- the text of the script/class to parseParses the given code source into a Java class. If there is a class file for the given code source, then no parsing is done, instead the cached class is returned.
shouldCacheSource
- if true then the generated class will be stored in the source cachesets if the recompilation should be enable. There are 3 possible values for this. Any value different than null overrides the value from the compiler configuration. true means to recompile if needed false means to never recompile.
mode
- the recompilation modeCopyright © 2003-2022 The Apache Software Foundation. All rights reserved.