|
Groovy 1.7.9 | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
groovy.lang.GroovyClassLoader
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.
Nested Class Summary | |
---|---|
static class |
GroovyClassLoader.ClassCollector
|
static class |
GroovyClassLoader.InnerLoader
|
Field Summary | |
---|---|
protected Map |
classCache
this cache contains the loaded classes or PARSING, if the class is currently parsed |
protected Map |
sourceCache
This cache contains mappings of file name to class. |
Constructor Summary | |
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. |
Method Summary | |
---|---|
void
|
addClasspath(String path)
adds a classpath to this classloader. |
void
|
addURL(URL url)
adds a URL to the classloader. |
void
|
clearCache()
Removes all classes from the class cache. |
protected GroovyClassLoader.ClassCollector
|
createCollector(CompilationUnit unit, SourceUnit su)
creates a ClassCollector for a new compilation. |
protected CompilationUnit
|
createCompilationUnit(CompilerConfiguration config, CodeSource source)
creates a new CompilationUnit. |
Class
|
defineClass(ClassNode classNode, String file)
Loads the given class node returning the implementation Class |
Class
|
defineClass(ClassNode classNode, String file, String newCodeBase)
Loads the given class node returning the implementation Class. |
protected Class
|
defineClass(String name, byte[] bytecode, ProtectionDomain domain)
A helper method to allow bytecode to be loaded. spg changed name to defineClass to make it more consistent with other ClassLoader methods |
Class
|
defineClass(String name, byte[] b)
open up the super class define that takes raw bytes |
protected void
|
expandClassPath(List pathList, String base, String classpath, boolean isManifestClasspath)
expands the classpath |
String
|
generateScriptName()
|
protected Class
|
getClassCacheEntry(String name)
gets a class from the class cache. |
protected String[]
|
getClassPath()
gets the currently used classpath. |
Class[]
|
getLoadedClasses()
Returns all Groovy classes loaded by this class loader. |
protected PermissionCollection
|
getPermissions(CodeSource codeSource)
|
GroovyResourceLoader
|
getResourceLoader()
|
protected long
|
getTimeStamp(Class cls)
gets the time stamp of a given class. |
protected boolean
|
isRecompilable(Class cls)
Indicates if a class is recompilable. |
Boolean
|
isShouldRecompile()
gets the currently set recompilation mode. null means, the compiler configuration is used. |
protected boolean
|
isSourceNewer(URL source, Class cls)
Decides if the given source is newer than a class. |
Class
|
loadClass(String name, boolean lookupScriptFiles, boolean preferClassOverScript)
loads a class from a file or a parent classloader. |
Class
|
loadClass(String name, boolean lookupScriptFiles, boolean preferClassOverScript, boolean resolve)
loads a class from a file or a parent classloader. |
protected Class
|
loadClass(String name, boolean resolve)
Implemented here to check package access prior to returning an already loaded class. |
Class
|
parseClass(File file)
Parses the given file into a Java class capable of being run |
Class
|
parseClass(String text, String fileName)
Parses the given text into a Java class capable of being run |
Class
|
parseClass(String text)
Parses the given text into a Java class capable of being run |
Class
|
parseClass(InputStream in)
Parses the given character stream into a Java class capable of being run |
Class
|
parseClass(InputStream in, String fileName)
@deprecated Prefer using methods taking a Reader rather than an InputStream to avoid wrong encoding issues. |
Class
|
parseClass(GroovyCodeSource codeSource)
|
Class
|
parseClass(GroovyCodeSource codeSource, boolean shouldCacheSource)
Parses the given code source into a Java class. |
protected Class
|
recompile(URL source, String className, Class oldClass)
(Re)Compiles the given source. |
protected void
|
removeClassCacheEntry(String name)
removes a class from the class cache. |
protected void
|
setClassCacheEntry(Class cls)
sets an entry in the class cache. |
void
|
setResourceLoader(GroovyResourceLoader resourceLoader)
|
void
|
setShouldRecompile(Boolean mode)
sets if the recompilation should be enable. |
Methods inherited from class Object | |
---|---|
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
Field Detail |
---|
protected final Map classCache
protected final Map sourceCache
Constructor Detail |
---|
public GroovyClassLoader()
public GroovyClassLoader(ClassLoader loader)
public GroovyClassLoader(GroovyClassLoader parent)
public GroovyClassLoader(ClassLoader parent, CompilerConfiguration config, boolean useConfigurationClasspath)
parent
- the parent class loaderconfig
- the compiler configurationuseConfigurationClasspath
- determines if the configurations classpath should be added
public GroovyClassLoader(ClassLoader loader, CompilerConfiguration config)
Method Detail |
---|
public void addClasspath(String path)
path
- is a jar file or a directory.
public void addURL(URL url)
url
- the new classpath element
public void clearCache()
protected GroovyClassLoader.ClassCollector createCollector(CompilationUnit unit, SourceUnit su)
unit
- the compilationUnitsu
- the SourceUnit
protected CompilationUnit createCompilationUnit(CompilerConfiguration config, CodeSource source)
config
- the compiler configuration, usually the same as for this class loadersource
- the source containing the initial file to compile, more files may follow during compilation
public Class defineClass(ClassNode classNode, String file)
public Class defineClass(ClassNode classNode, String file, String newCodeBase)
protected Class defineClass(String name, byte[] bytecode, ProtectionDomain domain)
public Class defineClass(String name, byte[] b)
protected void expandClassPath(List pathList, String base, String classpath, boolean isManifestClasspath)
pathList
- an empty list that will contain the elements of the classpathclasspath
- the classpath specified as a single string
public String generateScriptName()
protected Class getClassCacheEntry(String name)
name
- of the class
protected String[] getClassPath()
public Class[] getLoadedClasses()
Returns all Groovy classes loaded by this class loader.
protected PermissionCollection getPermissions(CodeSource codeSource)
public GroovyResourceLoader getResourceLoader()
protected long getTimeStamp(Class cls)
cls
- the class
protected boolean isRecompilable(Class cls)
cls
- the class to be tested. If null the method should return true
public Boolean isShouldRecompile()
protected boolean isSourceNewer(URL source, Class cls)
source
- the source we may want to compilecls
- the former class
public Class loadClass(String name, boolean lookupScriptFiles, boolean preferClassOverScript)
public Class loadClass(String name, boolean lookupScriptFiles, boolean preferClassOverScript, boolean resolve)
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 class
protected Class loadClass(String name, boolean resolve)
public Class parseClass(File file)
file
- the file name to parse
public Class parseClass(String text, String fileName)
text
- the text of the script/class to parsefileName
- the file name to use as the name of the class
public Class parseClass(String text)
text
- the text of the script/class to parse
public Class parseClass(InputStream in)
in
- an InputStream
public Class parseClass(InputStream in, String fileName)
public Class parseClass(GroovyCodeSource codeSource)
public Class parseClass(GroovyCodeSource codeSource, boolean shouldCacheSource)
shouldCacheSource
- if true then the generated class will be stored in the source cache
protected Class recompile(URL source, String className, Class oldClass)
source
- the source pointer for the compilationclassName
- the name of the class to be generatedoldClass
- a possible former class
protected void removeClassCacheEntry(String name)
name
- of the class
protected void setClassCacheEntry(Class cls)
cls
- the class
public void setResourceLoader(GroovyResourceLoader resourceLoader)
public void setShouldRecompile(Boolean mode)
mode
- the recompilation mode
Copyright © 2003-2010 The Codehaus. All rights reserved.