org.teatrove.tea.util
Class FileCompiler

java.lang.Object
  extended by org.teatrove.tea.compiler.Compiler
      extended by org.teatrove.tea.util.AbstractCompiler
          extended by org.teatrove.tea.util.FileCompiler
Direct Known Subclasses:
TestCompiler

public class FileCompiler
extends AbstractCompiler

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.

Author:
Brian S O'Neill
See Also:
ClassInjector

Nested Class Summary
 class FileCompiler.FileUnit
           
 class FileCompiler.JarredUnit
           
 class FileCompiler.Unit
           
 
Nested classes/interfaces inherited from class org.teatrove.tea.util.AbstractCompiler
AbstractCompiler.AbstractUnit
 
Field Summary
 
Fields inherited from class org.teatrove.tea.util.AbstractCompiler
mEncoding, mForce, mInjector, mPrecompiledTolerance, mRootDestDir, mRootPackage
 
Constructor Summary
FileCompiler(File[] rootSourceDirs, String rootPackage, File rootDestDir, ClassInjector injector)
           
FileCompiler(File[] rootSourceDirs, String rootPackage, File rootDestDir, ClassInjector injector, String encoding)
           
FileCompiler(File[] rootSourceDirs, String rootPackage, File rootDestDir, ClassInjector injector, String encoding, Map<String,Template> parseTreeMap)
           
FileCompiler(File rootSourceDir, String rootPackage, File rootDestDir, ClassInjector injector)
           
FileCompiler(File rootSourceDir, String rootPackage, File rootDestDir, ClassInjector injector, String encoding)
           
 
Method Summary
 String[] compile(String[] names)
          Overrides Compiler class implementation (TemplateRepository integration).
 String[] compileAll(boolean recurse)
          Compiles all files in the source directory.
protected  CompilationUnit createCompilationUnit(String name)
          Always returns an instance of FileCompiler.Unit.
 String[] getAllTemplateNames()
          Returns all sources (template names) available from the source directory and in all sub-directories.
static void main(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(String name)
           
 
Methods inherited from class org.teatrove.tea.util.AbstractCompiler
compileAll, getRootPackage
 
Methods inherited from class org.teatrove.tea.compiler.Compiler
addErrorListener, addImportedPackage, addImportedPackages, addStatusListener, compile, createCodeGenerator, createParser, createScanner, createSourceReader, createTypeChecker, getClassLoader, getCompilationUnit, getErrorCount, getImportedPackages, getParseTree, 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(File rootSourceDir,
                    String rootPackage,
                    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(File rootSourceDir,
                    String rootPackage,
                    File rootDestDir,
                    ClassInjector injector,
                    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(File[] rootSourceDirs,
                    String rootPackage,
                    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(File[] rootSourceDirs,
                    String rootPackage,
                    File rootDestDir,
                    ClassInjector injector,
                    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(File[] rootSourceDirs,
                    String rootPackage,
                    File rootDestDir,
                    ClassInjector injector,
                    String encoding,
                    Map<String,Template> 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(String[] args)
                 throws 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 org.teatrove.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.
 

Throws:
Exception

setForceCompile

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

compileAll

public String[] compileAll(boolean recurse)
                    throws 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
Throws:
IOException

compile

public String[] compile(String[] names)
                 throws IOException
Description copied from class: AbstractCompiler
Overrides Compiler class implementation (TemplateRepository integration).

Overrides:
compile in class AbstractCompiler
Parameters:
names - an array of fully qualified template names
Returns:
The names of all the sources compiled by this compiler
Throws:
IOException

getAllTemplateNames

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

Specified by:
getAllTemplateNames in class AbstractCompiler
Throws:
IOException

sourceExists

public boolean sourceExists(String name)
Specified by:
sourceExists in class Compiler
Returns:
true if source exists for the given qualified name

createCompilationUnit

protected CompilationUnit createCompilationUnit(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.

Specified by:
createCompilationUnit in class Compiler
See Also:
FileCompiler.Unit.getSourceFile()


Copyright © 1997-2012 TeaTrove.org. All Rights Reserved.