groovy.lang
Class GroovyClassLoader

java.lang.Object
  extended byjava.lang.ClassLoader
      extended byjava.security.SecureClassLoader
          extended bygroovy.lang.GroovyClassLoader

public class GroovyClassLoader
extends java.security.SecureClassLoader

A ClassLoader which can load Groovy classes

Version:
$Revision: 1.33 $
Author:
James Strachan , Guillaume Laforge, Steve Goetze, Bing Ran, Scott Stirling

Nested Class Summary
static class GroovyClassLoader.ClassCollector
           
private  class GroovyClassLoader.NOT_RESOLVED
           
private  class GroovyClassLoader.PARSING
           
 
Nested classes inherited from class java.lang.ClassLoader
 
Field Summary
private  java.util.Map cache
           
private  CompilerConfiguration config
           
private  java.lang.String[] searchPaths
           
 
Fields inherited from class java.security.SecureClassLoader
 
Fields inherited from class java.lang.ClassLoader
 
Constructor Summary
GroovyClassLoader()
           
GroovyClassLoader(java.lang.ClassLoader loader)
           
GroovyClassLoader(java.lang.ClassLoader loader, CompilerConfiguration config)
           
GroovyClassLoader(GroovyClassLoader parent)
           
 
Method Summary
protected  GroovyClassLoader.ClassCollector createCollector(CompilationUnit unit)
           
 java.lang.Class defineClass(ClassNode classNode, java.lang.String file)
          Loads the given class node returning the implementation Class
 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)
          A helper method to allow bytecode to be loaded.
protected  void expandClassPath(java.util.List pathList, java.lang.String base, java.lang.String classpath)
           
private  byte[] extractBytes(java.util.jar.JarFile jarFile, java.util.jar.JarEntry entry)
           
protected  java.lang.Class findClass(java.lang.String name)
          Using this classloader you can load groovy classes from the system classpath as though they were already compiled.
protected  java.lang.Class findGroovyClass(java.lang.String name)
           
protected  java.lang.String[] getClassPath()
           
private  java.io.File getSourceFile(java.lang.String name)
           
private  long getTimeStamp(java.lang.Class cls)
           
private  boolean isSourceNewer(java.io.File source, java.lang.Class cls)
           
protected  java.lang.Class loadClass(java.lang.String name, boolean resolve)
           
 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 shouldCache)
          Parses the given code source into a Java class capable of being run
 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
 void removeFromCache(java.lang.Class aClass)
           
 
Methods inherited from class java.security.SecureClassLoader
defineClass, getPermissions
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findResource, findResources, 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

cache

private java.util.Map cache

config

private CompilerConfiguration config

searchPaths

private java.lang.String[] searchPaths
Constructor Detail

GroovyClassLoader

public GroovyClassLoader()

GroovyClassLoader

public GroovyClassLoader(java.lang.ClassLoader loader)

GroovyClassLoader

public GroovyClassLoader(GroovyClassLoader parent)

GroovyClassLoader

public GroovyClassLoader(java.lang.ClassLoader loader,
                         CompilerConfiguration config)
Method Detail

removeFromCache

public void removeFromCache(java.lang.Class aClass)

defineClass

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

Parameters:
classNode -
Returns:

defineClass

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

Parameters:
classNode -
Returns:

parseClass

public java.lang.Class parseClass(java.io.File file)
                           throws CompilationFailedException,
                                  java.io.IOException
Parses the given file into a Java class capable of being run

Parameters:
file - the file name to parse
Returns:
the main class defined in the given script
Throws:
CompilationFailedException
java.io.IOException

parseClass

public java.lang.Class parseClass(java.lang.String text,
                                  java.lang.String fileName)
                           throws CompilationFailedException
Parses the given text into a Java class capable of being run

Parameters:
text - the text of the script/class to parse
fileName - the file name to use as the name of the class
Returns:
the main class defined in the given script
Throws:
CompilationFailedException

parseClass

public java.lang.Class parseClass(java.lang.String text)
                           throws CompilationFailedException
Parses the given text into a Java class capable of being run

Parameters:
text - the text of the script/class to parse
Returns:
the main class defined in the given script
Throws:
CompilationFailedException

parseClass

public java.lang.Class parseClass(java.io.InputStream in)
                           throws CompilationFailedException
Parses the given character stream into a Java class capable of being run

Parameters:
in - an InputStream
Returns:
the main class defined in the given script
Throws:
CompilationFailedException

parseClass

public java.lang.Class parseClass(java.io.InputStream in,
                                  java.lang.String fileName)
                           throws CompilationFailedException
Throws:
CompilationFailedException

parseClass

public java.lang.Class parseClass(GroovyCodeSource codeSource)
                           throws CompilationFailedException
Throws:
CompilationFailedException

parseClass

public java.lang.Class parseClass(GroovyCodeSource codeSource,
                                  boolean shouldCache)
                           throws CompilationFailedException
Parses the given code source into a Java class capable of being run

Returns:
the main class defined in the given script
Throws:
CompilationFailedException

findClass

protected java.lang.Class findClass(java.lang.String name)
                             throws java.lang.ClassNotFoundException
Using this classloader you can load groovy classes from the system classpath as though they were already compiled. Note that .groovy classes found with this mechanism need to conform to the standard java naming convention - i.e. the public class inside the file must match the filename and the file must be located in a directory structure that matches the package structure.

Throws:
java.lang.ClassNotFoundException

findGroovyClass

protected java.lang.Class findGroovyClass(java.lang.String name)
                                   throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException

extractBytes

private byte[] extractBytes(java.util.jar.JarFile jarFile,
                            java.util.jar.JarEntry entry)

getClassPath

protected java.lang.String[] getClassPath()
Returns:

expandClassPath

protected void expandClassPath(java.util.List pathList,
                               java.lang.String base,
                               java.lang.String classpath)
Parameters:
pathList -
classpath -

defineClass

protected java.lang.Class defineClass(java.lang.String name,
                                      byte[] bytecode,
                                      java.security.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


createCollector

protected GroovyClassLoader.ClassCollector createCollector(CompilationUnit unit)

defineClass

public java.lang.Class defineClass(java.lang.String name,
                                   byte[] b)
open up the super class define that takes raw bytes


loadClass

protected java.lang.Class loadClass(java.lang.String name,
                                    boolean resolve)
                             throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException

getTimeStamp

private long getTimeStamp(java.lang.Class cls)

getSourceFile

private java.io.File getSourceFile(java.lang.String name)

isSourceNewer

private boolean isSourceNewer(java.io.File source,
                              java.lang.Class cls)


Copyright © 2003-2005 The Codehaus. All Rights Reserved.