Package groovy.lang
Class GroovyClassLoader.InnerLoader
java.lang.Object
java.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
groovy.lang.GroovyClassLoader
groovy.lang.GroovyClassLoader.InnerLoader
- All Implemented Interfaces:
Closeable,AutoCloseable
- Enclosing class:
- GroovyClassLoader
Loader used while defining classes during a compilation round.
-
Nested Class Summary
Nested classes/interfaces inherited from class groovy.lang.GroovyClassLoader
GroovyClassLoader.ClassCollector, GroovyClassLoader.InnerLoader -
Field Summary
Fields inherited from class groovy.lang.GroovyClassLoader
classCache, sourceCache -
Constructor Summary
ConstructorsConstructorDescriptionInnerLoader(GroovyClassLoader delegate) Creates an inner loader delegating to the supplied outer Groovy class loader. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddClasspath(String path) adds a classpath to this classloader.voidadds a URL to the classloader.voidvoidRemoves all classes from the class cache.voidclose()Closes this GroovyClassLoader and clears any caches it maintains.defineClass(String name, byte[] b) Converts an array of bytes into an instance ofClass.defineClass(ClassNode classNode, String file, String newCodeBase) Compiles the givenClassNodereturning the resultingClass.findResource(String name) findResources(String name) Generates a unique script name for unnamed parsed sources.Class[]Returns all Groovy classes loaded by this class loader.getResource(String name) getResourceAsStream(String name) Returns the resource loader used to resolve Groovy source by script name.getResources(String name) longReturns the creation timestamp of this inner loader.URL[]getURLs()gets the currently set recompilation mode.Class<?>Loads a class from a file or a parent loader.Loads a class from a file or a parent loader.parseClass(GroovyCodeSource codeSource) Parses Groovy source described by aGroovyCodeSource.parseClass(GroovyCodeSource codeSource, boolean shouldCache) Parses the given code source into a Java class.parseClass(File file) Parses the given file into a Java class capable of being runparseClass(Reader reader, String fileName) Parses Groovy source read from aReader.parseClass(String text) Parses the given text into a Java class capable of being runparseClass(String text, String fileName) Parses the given text into a Java class capable of being runvoidsetClassAssertionStatus(String className, boolean enabled) voidsetDefaultAssertionStatus(boolean enabled) voidsetPackageAssertionStatus(String packageName, boolean enabled) voidsetResourceLoader(GroovyResourceLoader resourceLoader) Sets the resource loader used to resolve Groovy source by script name.voidsetShouldRecompile(Boolean mode) sets if the recompilation should be enabled.Methods inherited from class groovy.lang.GroovyClassLoader
createCollector, createCompilationUnit, genEncodingString, getClassCacheEntry, getClassPath, getPermissions, getTimeStamp, hasCompatibleConfiguration, isRecompilable, isSourceNewer, loadClass, recompile, removeClassCacheEntry, setClassCacheEntryMethods inherited from class java.net.URLClassLoader
definePackage, findClass, newInstance, newInstanceMethods inherited from class java.security.SecureClassLoader
defineClass, defineClassMethods inherited from class java.lang.ClassLoader
defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, registerAsParallelCapable, resolveClass, resources, setSigners
-
Constructor Details
-
InnerLoader
Creates an inner loader delegating to the supplied outer Groovy class loader.- Parameters:
delegate- the outer loader that owns caches and resources
-
-
Method Details
-
addClasspath
adds a classpath to this classloader.- Overrides:
addClasspathin classGroovyClassLoader- Parameters:
path- is a jar file or a directory.- See Also:
-
addURL
adds a URL to the classloader.- Overrides:
addURLin classGroovyClassLoader- Parameters:
url- the new classpath element
-
clearAssertionStatus
public void clearAssertionStatus()- Overrides:
clearAssertionStatusin classClassLoader
-
clearCache
public void clearCache()Removes 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.
-
close
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.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classGroovyClassLoader- Throws:
IOException- See Also:
-
defineClass
Compiles the givenClassNodereturning the resultingClass.WARNING: compilation is not synchronized
- Overrides:
defineClassin classGroovyClassLoader
-
defineClass
Converts an array of bytes into an instance ofClass. Before the class can be used it must be resolved.- Overrides:
defineClassin classGroovyClassLoader
-
findResource
- Overrides:
findResourcein classURLClassLoader
-
findResources
- Overrides:
findResourcesin classURLClassLoader- Throws:
IOException
-
generateScriptName
Generates a unique script name for unnamed parsed sources.- Overrides:
generateScriptNamein classGroovyClassLoader- Returns:
- a unique script name ending in
.groovy
-
getLoadedClasses
Returns all Groovy classes loaded by this class loader.
- Overrides:
getLoadedClassesin classGroovyClassLoader- Returns:
- all classes loaded by this class loader
-
getResource
- Overrides:
getResourcein classClassLoader
-
getResourceAsStream
- Overrides:
getResourceAsStreamin classURLClassLoader
-
getResourceLoader
Returns the resource loader used to resolve Groovy source by script name.- Overrides:
getResourceLoaderin classGroovyClassLoader- Returns:
- the current resource loader
-
getResources
- Overrides:
getResourcesin classClassLoader- Throws:
IOException
-
getTimeStamp
public long getTimeStamp()Returns the creation timestamp of this inner loader.- Returns:
- the timestamp captured when the loader was created
-
getURLs
- Overrides:
getURLsin classURLClassLoader
-
isShouldRecompile
gets 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.- Overrides:
isShouldRecompilein classGroovyClassLoader- Returns:
- the recompilation mode
-
loadClass
- Overrides:
loadClassin classGroovyClassLoader- Throws:
ClassNotFoundException- See Also:
-
loadClass
public Class loadClass(String name, boolean lookupScriptFiles, boolean preferClassOverScript) throws ClassNotFoundException, CompilationFailedException Loads a class from a file or a parent loader. This method delegates to:loadClass(name, lookupScriptFiles, preferClassOverScript, false);
- Overrides:
loadClassin classGroovyClassLoader- Throws:
ClassNotFoundException- if class could not be foundCompilationFailedException- if compilation of script failed
-
loadClass
public Class loadClass(String name, boolean lookupScriptFiles, boolean preferClassOverScript, boolean resolve) throws ClassNotFoundException, CompilationFailedException Loads a class from a file or a parent loader.- Overrides:
loadClassin classGroovyClassLoader- Parameters:
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- seeClassLoader.loadClass(java.lang.String, boolean)- Returns:
- the class found or the class created from a file lookup
- Throws:
ClassNotFoundException- if class could not be foundCompilationFailedException- if compilation of script failed
-
parseClass
Parses the given file into a Java class capable of being run- Overrides:
parseClassin classGroovyClassLoader- Parameters:
file- the file name to parse- Returns:
- the main class defined in the given script
- Throws:
CompilationFailedExceptionIOException
-
parseClass
Parses Groovy source described by aGroovyCodeSource.- Overrides:
parseClassin classGroovyClassLoader- Parameters:
codeSource- the code source to compile- Returns:
- the main class defined by the source
- Throws:
CompilationFailedException- if compilation fails
-
parseClass
public Class parseClass(GroovyCodeSource codeSource, boolean shouldCache) throws CompilationFailedException Parses 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.- Overrides:
parseClassin classGroovyClassLoadershouldCache- if true then the generated class will be stored in the source cache- Returns:
- the main class defined in the given script
- Throws:
CompilationFailedException
-
parseClass
Parses Groovy source read from aReader.- Overrides:
parseClassin classGroovyClassLoader- Parameters:
reader- the reader supplying source textfileName- the logical script name- Returns:
- the main class defined by the source
- Throws:
CompilationFailedException- if compilation fails
-
parseClass
Parses the given text into a Java class capable of being run- Overrides:
parseClassin classGroovyClassLoader- Parameters:
text- the text of the script/class to parse- Returns:
- the main class defined in the given script
- Throws:
CompilationFailedException
-
parseClass
Parses the given text into a Java class capable of being run- Overrides:
parseClassin classGroovyClassLoader- Parameters:
text- the text of the script/class to parsefileName- the file name to use as the name of the class- Returns:
- the main class defined in the given script
- Throws:
CompilationFailedException
-
setClassAssertionStatus
- Overrides:
setClassAssertionStatusin classClassLoader
-
setDefaultAssertionStatus
public void setDefaultAssertionStatus(boolean enabled) - Overrides:
setDefaultAssertionStatusin classClassLoader
-
setPackageAssertionStatus
- Overrides:
setPackageAssertionStatusin classClassLoader
-
setResourceLoader
Sets the resource loader used to resolve Groovy source by script name.- Overrides:
setResourceLoaderin classGroovyClassLoader- Parameters:
resourceLoader- the resource loader to use
-
setShouldRecompile
sets if the recompilation should be enabled. There are 3 possible values for this. Any value different from null overrides the value from the compiler configuration. true means to recompile if needed false means to never recompile.- Overrides:
setShouldRecompilein classGroovyClassLoader- Parameters:
mode- the recompilation mode- See Also:
-