com.caucho.loader
Class CompilingLoader

java.lang.Object
  extended by com.caucho.loader.Loader
      extended by com.caucho.loader.CompilingLoader
All Implemented Interfaces:
Make

public class CompilingLoader
extends Loader
implements Make

A class loader that automatically compiles Java.


Constructor Summary
CompilingLoader()
           
CompilingLoader(java.lang.ClassLoader loader)
           
CompilingLoader(java.lang.ClassLoader loader, Path classDir)
          Creates a new compiling class loader
CompilingLoader(java.lang.ClassLoader loader, Path classDir, Path sourceDir, java.lang.String args, java.lang.String encoding)
          Creates a new compiling class loader
 
Method Summary
 void addArg(java.lang.String arg)
          Adds an argument.
protected  void buildClassPath(java.util.ArrayList<java.lang.String> pathList)
          Adds the classpath we're responsible for to the classpath
static DynamicClassLoader create(java.lang.ClassLoader parent, Path classDir, Path sourceDir, java.lang.String args, java.lang.String encoding)
          Creates a new compiling class loader
static DynamicClassLoader create(Path path)
          Create a class loader based on the compiling loader
protected  ClassEntry getClassEntry(java.lang.String name, java.lang.String pathName)
          Loads the specified class, compiling if necessary.
 java.lang.String getClassPath()
           
protected  java.security.CodeSource getCodeSource(Path path)
          Returns the code source for the directory.
 Path getPath()
          Gets the class path.
 Path getPath(java.lang.String name)
          Returns the path for the given name.
 Path getSource()
          Sets the source path.
 void init()
          Initialize.
 boolean isDirectoryLoader()
           
 void make()
          Compiles all changed files in the class directory.
protected  java.lang.String prefixClassPath(java.lang.String tail)
           
 void setArgs(java.lang.String arg)
          Sets the arguments.
 void setBatch(boolean isBatch)
          Sets true if compilation should batch as many files as possible.
 void setCompiler(java.lang.String compiler)
          Sets the compiler.
 void setEncoding(java.lang.String encoding)
          Sets the encoding.
 void setPath(Path path)
          Sets the class path.
 void setRequireSource(boolean requireSource)
          Sets true if source is required.
 void setSource(Path path)
          Sets the source path.
 void setSourceExtension(java.lang.String ext)
          Sets the source extension.
 java.lang.String toString()
           
 
Methods inherited from class com.caucho.loader.Loader
buildSourcePath, destroy, getClassLoader, getResource, getResourceAsStream, getResources, loadClass, setLoader, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CompilingLoader

public CompilingLoader()

CompilingLoader

public CompilingLoader(java.lang.ClassLoader loader)

CompilingLoader

public CompilingLoader(java.lang.ClassLoader loader,
                       Path classDir)
Creates a new compiling class loader

Parameters:
classDir - generated class directory root

CompilingLoader

public CompilingLoader(java.lang.ClassLoader loader,
                       Path classDir,
                       Path sourceDir,
                       java.lang.String args,
                       java.lang.String encoding)
Creates a new compiling class loader

Parameters:
classDir - generated class directory root
sourceDir - Java source directory root
args - Javac arguments
encoding - javac encoding
Method Detail

create

public static DynamicClassLoader create(Path path)
Create a class loader based on the compiling loader

Parameters:
path - traditional classpath
Returns:
the new ClassLoader

setPath

public void setPath(Path path)
Sets the class path.


getPath

public Path getPath()
Gets the class path.


setSource

public void setSource(Path path)
Sets the source path.


setSourceExtension

public void setSourceExtension(java.lang.String ext)
                        throws ConfigException
Sets the source extension.

Throws:
ConfigException

setCompiler

public void setCompiler(java.lang.String compiler)
                 throws ConfigException
Sets the compiler.

Throws:
ConfigException

getSource

public Path getSource()
Sets the source path.


setArgs

public void setArgs(java.lang.String arg)
Sets the arguments.


addArg

public void addArg(java.lang.String arg)
Adds an argument.


setEncoding

public void setEncoding(java.lang.String encoding)
Sets the encoding.


setRequireSource

public void setRequireSource(boolean requireSource)
Sets true if source is required.


setBatch

public void setBatch(boolean isBatch)
Sets true if compilation should batch as many files as possible.


isDirectoryLoader

public boolean isDirectoryLoader()
Overrides:
isDirectoryLoader in class Loader

init

@PostConstruct
public void init()
          throws ConfigException
Initialize.

Overrides:
init in class Loader
Throws:
ConfigException

create

public static DynamicClassLoader create(java.lang.ClassLoader parent,
                                        Path classDir,
                                        Path sourceDir,
                                        java.lang.String args,
                                        java.lang.String encoding)
Creates a new compiling class loader

Parameters:
classDir - generated class directory root
sourceDir - Java source directory root
args - Javac arguments
encoding - javac encoding

getClassPath

public java.lang.String getClassPath()

make

public void make()
          throws java.io.IOException,
                 java.lang.ClassNotFoundException
Compiles all changed files in the class directory.

Specified by:
make in interface Make
Throws:
java.io.IOException
java.lang.ClassNotFoundException

getClassEntry

protected ClassEntry getClassEntry(java.lang.String name,
                                   java.lang.String pathName)
                            throws java.lang.ClassNotFoundException
Loads the specified class, compiling if necessary.

Overrides:
getClassEntry in class Loader
Parameters:
name - name of the class
Throws:
java.lang.ClassNotFoundException

getCodeSource

protected java.security.CodeSource getCodeSource(Path path)
Returns the code source for the directory.

Overrides:
getCodeSource in class Loader

getPath

public Path getPath(java.lang.String name)
Returns the path for the given name.

Overrides:
getPath in class Loader
Parameters:
name - the name of the class

buildClassPath

protected void buildClassPath(java.util.ArrayList<java.lang.String> pathList)
Adds the classpath we're responsible for to the classpath

Overrides:
buildClassPath in class Loader
Parameters:
head - the overriding classpath

prefixClassPath

protected java.lang.String prefixClassPath(java.lang.String tail)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object