com.go.tea.util
Class FileCompiler

java.lang.Object
  |
  +--com.go.tea.compiler.Compiler
        |
        +--com.go.tea.util.AbstractFileCompiler
              |
              +--com.go.tea.util.FileCompiler
Direct Known Subclasses:
TestCompiler

public class FileCompiler
extends AbstractFileCompiler

FileCompiler compiles tea source files by reading them from a file or a directory. The compiled code can be written as class files to a given destination directory, they can be passed to a ClassInjector, or they can be sent to both.

When given a directory, FileCompiler compiles all files with the extension ".tea". If a destination directory is used, tea files that have a matching class file that is more up-to-date will not be compiled, unless they are forced to be re-compiled.

Version:
42 21 01/02/06
Author:
Brian S O'Neill
See Also:
ClassInjector

Inner Class Summary
 class FileCompiler.Unit
           
 
Constructor Summary
FileCompiler(java.io.File[] rootSourceDirs, java.lang.String rootPackage, java.io.File rootDestDir, ClassInjector injector)
           
FileCompiler(java.io.File[] rootSourceDirs, java.lang.String rootPackage, java.io.File rootDestDir, ClassInjector injector, java.lang.String encoding)
           
FileCompiler(java.io.File[] rootSourceDirs, java.lang.String rootPackage, java.io.File rootDestDir, ClassInjector injector, java.lang.String encoding, java.util.Map parseTreeMap)
           
FileCompiler(java.io.File rootSourceDir, java.lang.String rootPackage, java.io.File rootDestDir, ClassInjector injector)
           
FileCompiler(java.io.File rootSourceDir, java.lang.String rootPackage, java.io.File rootDestDir, ClassInjector injector, java.lang.String encoding)
           
 
Method Summary
 java.lang.String[] compileAll(boolean recurse)
          Compiles all files in the source directory.
protected  CompilationUnit createCompilationUnit(java.lang.String name)
          Always returns an instance of FileCompiler.Unit.
 java.lang.String[] getAllTemplateNames()
          Returns all sources (template names) available from the source directory and in all sub-directories.
static void main(java.lang.String[] args)
          Entry point for a command-line tool suitable for compiling Tea templates to be bundled with a product.
 void setForceCompile(boolean force)
           
 boolean sourceExists(java.lang.String name)
           
 
Methods inherited from class com.go.tea.util.AbstractFileCompiler
compileAll
 
Methods inherited from class com.go.tea.compiler.Compiler
addErrorListener, addStatusListener, compile, compile, createCodeGenerator, createParser, createScanner, createSourceReader, createTypeChecker, getClassLoader, getCompilationUnit, getErrorCount, getImportedPackages, getRuntimeContext, getRuntimeContextMethods, getRuntimeReceiver, getRuntimeStringConverter, getStringConverterMethods, isCodeGenerationEnabled, isExceptionGuardianEnabled, loadClass, preserveParseTree, removeErrorListener, removeStatusListener, setClassLoader, setCodeGenerationEnabled, setExceptionGuardianEnabled, setRuntimeContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileCompiler

public FileCompiler(java.io.File rootSourceDir,
                    java.lang.String rootPackage,
                    java.io.File rootDestDir,
                    ClassInjector injector)
Parameters:
rootSourceDir - Required root source directory
rootPackage - Optional root package to compile source to
rootDestDir - Optional directory to place generated class files
injector - Optional ClassInjector to feed generated classes into

FileCompiler

public FileCompiler(java.io.File rootSourceDir,
                    java.lang.String rootPackage,
                    java.io.File rootDestDir,
                    ClassInjector injector,
                    java.lang.String encoding)
Parameters:
rootSourceDir - Required root source directory
rootPackage - Optional root package to compile source to
rootDestDir - Optional directory to place generated class files
injector - Optional ClassInjector to feed generated classes into
encoding - Optional character encoding used by source files

FileCompiler

public FileCompiler(java.io.File[] rootSourceDirs,
                    java.lang.String rootPackage,
                    java.io.File rootDestDir,
                    ClassInjector injector)
Parameters:
rootSourceDirs - Required root source directories
rootPackage - Optional root package to compile source to
rootDestDir - Optional directory to place generated class files
injector - Optional ClassInjector to feed generated classes into

FileCompiler

public FileCompiler(java.io.File[] rootSourceDirs,
                    java.lang.String rootPackage,
                    java.io.File rootDestDir,
                    ClassInjector injector,
                    java.lang.String encoding)
Parameters:
rootSourceDirs - Required root source directories
rootPackage - Optional root package to compile source to
rootDestDir - Optional directory to place generated class files
injector - Optional ClassInjector to feed generated classes into
encoding - Optional character encoding used by source files

FileCompiler

public FileCompiler(java.io.File[] rootSourceDirs,
                    java.lang.String rootPackage,
                    java.io.File rootDestDir,
                    ClassInjector injector,
                    java.lang.String encoding,
                    java.util.Map parseTreeMap)
Parameters:
rootSourceDirs - Required root source directories
rootPackage - Optional root package to compile source to
rootDestDir - Optional directory to place generated class files
injector - Optional ClassInjector to feed generated classes into
encoding - Optional character encoding used by source files
parseTreeMap - Optional map should be thread-safe. See Compiler for details.
Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Entry point for a command-line tool suitable for compiling Tea templates to be bundled with a product. Templates are read from files that must have the extension ".tea", and any compilation error messages are sent to standard out.
 Usage: java com.go.tea.util.FileCompiler {options} 
 <template root directory> {templates}

 where {options} includes:
 -context <class>     Specify a runtime context class to compile against.
 -dest <directory>    Specify where to place generated class files.
 -force               Compile all templates, even if up-to-date.
 -package <package>   Root package to compile templates into.
 -encoding <encoding> Specify character encoding used by source files.
 -guardian            Enable the exception guardian.
 

setForceCompile

public void setForceCompile(boolean force)
Parameters:
force - When true, compile all source, even if up-to-date

compileAll

public java.lang.String[] compileAll(boolean recurse)
                              throws java.io.IOException
Compiles all files in the source directory.
Parameters:
recurse - When true, recursively compiles all files and directories
Returns:
The names of all the compiled sources

getAllTemplateNames

public java.lang.String[] getAllTemplateNames()
                                       throws java.io.IOException
Description copied from class: AbstractFileCompiler
Returns all sources (template names) available from the source directory and in all sub-directories.
Overrides:
getAllTemplateNames in class AbstractFileCompiler

sourceExists

public boolean sourceExists(java.lang.String name)
Overrides:
sourceExists in class Compiler
Following copied from class: com.go.tea.compiler.Compiler
Returns:
true if source exists for the given qualified name

createCompilationUnit

protected CompilationUnit createCompilationUnit(java.lang.String name)
Always returns an instance of FileCompiler.Unit. Any errors reported by the compiler that have a reference to a CompilationUnit will have been created by this factory method. Casting this to FileCompiler.Unit allows error reporters to access the source file via the getSourceFile method.
Overrides:
createCompilationUnit in class Compiler
See Also:
FileCompiler.Unit.getSourceFile()