groovy.lang
Class GroovyClassLoader

:
TODO: multi threaded compiling of the same class but with different roots
for compilation... T1 compiles A, which uses B, T2 compiles B... mark A and B as parsed and then synchronize compilation. Problems: How to synchronize? How to get error messages?

Field Summary
 Map classCache
           
 CompilerConfiguration config
           
 Boolean recompile
           
 GroovyResourceLoader resourceLoader
           
 int scriptNameCounter
           
 Map sourceCache
           
 
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 GroovyClassLaoder.
GroovyClassLoader(ClassLoader loader, CompilerConfiguration config)
            creates a GroovyClassLoader using the given ClassLoader as parent.
 
Method Summary
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.
Class defineClass(String name, def 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
void expandClassPath(List pathList, String base, String classpath, boolean isManifestClasspath)
           expands the classpath
String generateScriptName()
          
def getClassPath()
           gets the currently used classpath.
GroovyResourceLoader getResourceLoader()
          
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)
          
Class parseClass(GroovyCodeSource codeSource)
          
Class parseClass(GroovyCodeSource codeSource, boolean shouldCacheSource)
           Parses the given code source into a Java class.
void setResourceLoader(GroovyResourceLoader resourceLoader)
          
 

Constructor Detail

GroovyClassLoader

public GroovyClassLoader()
creates a GroovyClassLoader using the current Thread's context Class loader as parent.


GroovyClassLoader

public GroovyClassLoader(ClassLoader loader)
creates a GroovyClassLoader using the given ClassLoader as parent


GroovyClassLoader

public GroovyClassLoader(GroovyClassLoader parent)
creates a GroovyClassLoader using the given GroovyClassLoader as parent. This loader will get the parent's CompilerConfiguration


GroovyClassLoader

public GroovyClassLoader(ClassLoader parent, CompilerConfiguration config, boolean useConfigurationClasspath)
creates a GroovyClassLaoder.
param:
parent the parent class loader
param:
config the compiler configuration
param:
useConfigurationClasspath determines if the configurations classpath should be added


GroovyClassLoader

public GroovyClassLoader(ClassLoader loader, CompilerConfiguration config)
creates a GroovyClassLoader using the given ClassLoader as parent.


Method Detail

defineClass

public Class defineClass(ClassNode classNode, String file)
Loads the given class node returning the implementation Class
param:
classNode
return:
a class
deprecated:


defineClass

public Class defineClass(ClassNode classNode, String file, String newCodeBase)
Loads the given class node returning the implementation Class.

WARNING: this compilation is not synchronized

param:
classNode
return:
a class


defineClass

Class defineClass(String name, def 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
deprecated:


expandClassPath

void expandClassPath(List pathList, String base, String classpath, boolean isManifestClasspath)
expands the classpath
param:
pathList an empty list that will contain the elements of the classpath
param:
classpath the classpath specified as a single string
deprecated:


generateScriptName

public String generateScriptName()


getClassPath

def getClassPath()
gets the currently used classpath.
return:
a String[] containing the file information of the urls
see:
#getURLs()


getResourceLoader

public GroovyResourceLoader getResourceLoader()


parseClass

public Class parseClass(File file)
Parses the given file into a Java class capable of being run
param:
file the file name to parse
return:
the main class defined in the given script


parseClass

public Class parseClass(String text, String fileName)
Parses the given text into a Java class capable of being run
param:
text the text of the script/class to parse
param:
fileName the file name to use as the name of the class
return:
the main class defined in the given script


parseClass

public Class parseClass(String text)
Parses the given text into a Java class capable of being run
param:
text the text of the script/class to parse
return:
the main class defined in the given script


parseClass

public Class parseClass(InputStream in)
Parses the given character stream into a Java class capable of being run
param:
in an InputStream
return:
the main class defined in the given script


parseClass

public Class parseClass(InputStream in, String fileName)


parseClass

public Class parseClass(GroovyCodeSource codeSource)


parseClass

public Class parseClass(GroovyCodeSource codeSource, boolean shouldCacheSource)
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.
param:
shouldCacheSource if true then the generated class will be stored in the source cache
return:
the main class defined in the given script


setResourceLoader

public void setResourceLoader(GroovyResourceLoader resourceLoader)