|
||||||||||
| PREV CLASS NEXT CLASS | 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
A ClassLoader which can load Groovy classes. The loaded classes are cached, classes from other classlaoders 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 chached are always reloaded.
| Nested Class Summary | |
|---|---|
static class |
GroovyClassLoader.ClassCollector
|
static class |
GroovyClassLoader.InnerLoader
|
| Field Summary | |
|---|---|
protected java.util.Map |
classCache
this cache contains the loaded classes or PARSING, if the class is currently parsed |
private CompilerConfiguration |
config
|
private java.lang.Boolean |
recompile
|
private GroovyResourceLoader |
resourceLoader
|
private static int |
scriptNameCounter
|
protected java.util.Map |
sourceCache
|
| Constructor Summary | |
|---|---|
GroovyClassLoader()
creates a GroovyClassLoader using the current Thread's context Class loader as parent. |
|
GroovyClassLoader(java.lang.ClassLoader loader)
creates a GroovyClassLoader using the given ClassLoader as parent |
|
GroovyClassLoader(java.lang.ClassLoader loader,
CompilerConfiguration config)
creates a GroovyClassLoader using the given ClassLoader as parent. |
|
GroovyClassLoader(java.lang.ClassLoader parent,
CompilerConfiguration config,
boolean useConfigurationClasspath)
creates a GroovyClassLaoder. |
|
GroovyClassLoader(GroovyClassLoader parent)
creates a GroovyClassLoader using the given GroovyClassLoader as parent. |
|
| Method Summary | |
|---|---|
void |
addClasspath(java.lang.String path)
adds a classpath to this classloader. |
void |
addURL(java.net.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,
java.security.CodeSource source)
creates a new CompilationUnit. |
private java.lang.String |
decodeFileName(java.lang.String fileName)
|
java.lang.Class |
defineClass(ClassNode classNode,
java.lang.String file)
Deprecated. |
java.lang.Class |
defineClass(ClassNode classNode,
java.lang.String file,
java.lang.String newCodeBase)
Loads the given class node returning the implementation Class. |
java.lang.Class |
defineClass(java.lang.String name,
byte[] b)
open up the super class define that takes raw bytes |
protected java.lang.Class |
defineClass(java.lang.String name,
byte[] bytecode,
java.security.ProtectionDomain domain)
Deprecated. |
protected void |
expandClassPath(java.util.List pathList,
java.lang.String base,
java.lang.String classpath,
boolean isManifestClasspath)
Deprecated. |
java.lang.String |
generateScriptName()
|
protected java.lang.Class |
getClassCacheEntry(java.lang.String name)
gets a class from the class cache. |
protected java.lang.String[] |
getClassPath()
gets the currently used classpath. |
java.lang.Class[] |
getLoadedClasses()
Returns all Groovy classes loaded by this class loader. |
GroovyResourceLoader |
getResourceLoader()
|
private java.net.URL |
getSourceFile(java.lang.String name)
|
protected long |
getTimeStamp(java.lang.Class cls)
gets the time stamp of a given class. |
protected boolean |
isRecompilable(java.lang.Class cls)
Indicates if a class is recompilable. |
java.lang.Boolean |
isShouldRecompile()
gets the currently set recompilation mode. |
protected boolean |
isSourceNewer(java.net.URL source,
java.lang.Class cls)
Decides if the given source is newer than a class. |
protected java.lang.Class |
loadClass(java.lang.String name,
boolean resolve)
Implemented here to check package access prior to returning an already loaded class. |
java.lang.Class |
loadClass(java.lang.String name,
boolean lookupScriptFiles,
boolean preferClassOverScript)
loads a class from a file or a parent classloader. |
java.lang.Class |
loadClass(java.lang.String name,
boolean lookupScriptFiles,
boolean preferClassOverScript,
boolean resolve)
loads a class from a file or a parent classloader. |
java.lang.Class |
parseClass(java.io.File file)
Parses the given file into a Java class capable of being run |
java.lang.Class |
parseClass(GroovyCodeSource codeSource)
|
java.lang.Class |
parseClass(GroovyCodeSource codeSource,
boolean shouldCacheSource)
Parses the given code source into a Java class. |
java.lang.Class |
parseClass(java.io.InputStream in)
Parses the given character stream into a Java class capable of being run |
java.lang.Class |
parseClass(java.io.InputStream in,
java.lang.String fileName)
|
java.lang.Class |
parseClass(java.lang.String text)
Parses the given text into a Java class capable of being run |
java.lang.Class |
parseClass(java.lang.String text,
java.lang.String fileName)
Parses the given text into a Java class capable of being run |
protected java.lang.Class |
recompile(java.net.URL source,
java.lang.String className,
java.lang.Class oldClass)
(Re)Compiles the given source. |
protected void |
removeClassCacheEntry(java.lang.String name)
removes a class from the class cache. |
protected void |
setClassCacheEntry(java.lang.Class cls)
sets an entry in the class cache. |
void |
setResourceLoader(GroovyResourceLoader resourceLoader)
|
void |
setShouldRecompile(java.lang.Boolean mode)
sets if the recompilation should be enable. |
| Methods inherited from class java.net.URLClassLoader |
|---|
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, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final java.util.Map classCache
protected final java.util.Map sourceCache
private final CompilerConfiguration config
private java.lang.Boolean recompile
private static int scriptNameCounter
private GroovyResourceLoader resourceLoader
| Constructor Detail |
|---|
public GroovyClassLoader()
public GroovyClassLoader(java.lang.ClassLoader loader)
public GroovyClassLoader(GroovyClassLoader parent)
public GroovyClassLoader(java.lang.ClassLoader parent,
CompilerConfiguration config,
boolean useConfigurationClasspath)
parent - the parten class loaderconfig - the compiler configurationuseConfigurationClasspath - determines if the configurations classpath should be added
public GroovyClassLoader(java.lang.ClassLoader loader,
CompilerConfiguration config)
| Method Detail |
|---|
public void setResourceLoader(GroovyResourceLoader resourceLoader)
public GroovyResourceLoader getResourceLoader()
public java.lang.Class defineClass(ClassNode classNode,
java.lang.String file)
classNode -
public java.lang.Class defineClass(ClassNode classNode,
java.lang.String file,
java.lang.String newCodeBase)
classNode -
public java.lang.Class parseClass(java.io.File file)
throws CompilationFailedException,
java.io.IOException
file - the file name to parse
CompilationFailedException
java.io.IOException
public java.lang.Class parseClass(java.lang.String text,
java.lang.String fileName)
throws CompilationFailedException
text - the text of the script/class to parsefileName - the file name to use as the name of the class
CompilationFailedException
public java.lang.Class parseClass(java.lang.String text)
throws CompilationFailedException
text - the text of the script/class to parse
CompilationFailedException
public java.lang.Class parseClass(java.io.InputStream in)
throws CompilationFailedException
in - an InputStream
CompilationFailedExceptionpublic java.lang.String generateScriptName()
public java.lang.Class parseClass(java.io.InputStream in,
java.lang.String fileName)
throws CompilationFailedException
CompilationFailedException
public java.lang.Class parseClass(GroovyCodeSource codeSource)
throws CompilationFailedException
CompilationFailedException
public java.lang.Class parseClass(GroovyCodeSource codeSource,
boolean shouldCacheSource)
throws CompilationFailedException
shouldCacheSource - if true then the generated class will be stored in the source cache
CompilationFailedExceptionprotected java.lang.String[] getClassPath()
URLClassLoader.getURLs()
protected void expandClassPath(java.util.List pathList,
java.lang.String base,
java.lang.String classpath,
boolean isManifestClasspath)
pathList - an empty list that will contain the elements of the classpathclasspath - the classpath specified as a single string
protected java.lang.Class defineClass(java.lang.String name,
byte[] bytecode,
java.security.ProtectionDomain domain)
protected CompilationUnit createCompilationUnit(CompilerConfiguration config,
java.security.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
protected GroovyClassLoader.ClassCollector createCollector(CompilationUnit unit,
SourceUnit su)
unit - the compilationUnitsu - the SoruceUnit
public java.lang.Class defineClass(java.lang.String name,
byte[] b)
public java.lang.Class loadClass(java.lang.String name,
boolean lookupScriptFiles,
boolean preferClassOverScript)
throws java.lang.ClassNotFoundException,
CompilationFailedException
CompilationFailedException - if compilation was not successful
java.lang.ClassNotFoundExceptionprotected java.lang.Class getClassCacheEntry(java.lang.String name)
name - of the class
removeClassCacheEntry(String),
setClassCacheEntry(Class),
clearCache()protected void setClassCacheEntry(java.lang.Class cls)
cls - the classremoveClassCacheEntry(String),
getClassCacheEntry(String),
clearCache()protected void removeClassCacheEntry(java.lang.String name)
name - of the classgetClassCacheEntry(String),
setClassCacheEntry(Class),
clearCache()public void addURL(java.net.URL url)
addURL in class java.net.URLClassLoaderurl - the new classpath elementprotected boolean isRecompilable(java.lang.Class cls)
cls - the class to be tested. If null the method should return true
isSourceNewer(URL, Class)public void setShouldRecompile(java.lang.Boolean mode)
mode - the recompilation modeCompilerConfigurationpublic java.lang.Boolean isShouldRecompile()
public java.lang.Class loadClass(java.lang.String name,
boolean lookupScriptFiles,
boolean preferClassOverScript,
boolean resolve)
throws java.lang.ClassNotFoundException,
CompilationFailedException
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#loadClass(java.lang.String, boolean)
java.lang.ClassNotFoundException - if the class could not be found
CompilationFailedException - if the source file could not be compiled
protected java.lang.Class recompile(java.net.URL source,
java.lang.String className,
java.lang.Class oldClass)
throws CompilationFailedException,
java.io.IOException
source - the source pointer for the compilationclassName - the name of the class to be generatedoldClass - a possible former class
CompilationFailedException - if the compilation failed
java.io.IOException - if the source is not readableisSourceNewer(URL, Class)
protected java.lang.Class loadClass(java.lang.String name,
boolean resolve)
throws java.lang.ClassNotFoundException
loadClass in class java.lang.ClassLoaderCompilationFailedException - if the compilation failed
java.lang.ClassNotFoundException - if the class was not foundClassLoader.loadClass(java.lang.String, boolean)protected long getTimeStamp(java.lang.Class cls)
cls - the class
private java.lang.String decodeFileName(java.lang.String fileName)
private java.net.URL getSourceFile(java.lang.String name)
protected boolean isSourceNewer(java.net.URL source,
java.lang.Class cls)
throws java.io.IOException
source - the source we may want to compilecls - the former class
java.io.IOException - if it is not possible to open an
connection for the given sourcegetTimeStamp(Class)public void addClasspath(java.lang.String path)
path - is a jar file or a directory.addURL(URL)public java.lang.Class[] getLoadedClasses()
Returns all Groovy classes loaded by this class loader.
public void clearCache()
getClassCacheEntry(String),
setClassCacheEntry(Class),
removeClassCacheEntry(String)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||