Class AbstractCompiler
- java.lang.Object
-
- org.codehaus.commons.compiler.AbstractCompiler
-
-
Field Summary
Fields Modifier and Type Field Description protected java.io.File[]bootClassPathThis is always non-nullfor JVMs that support BOOTCLASSPATH (1.0-1.8), and this is alwaysnullfor JVMs that don't (9+).protected ResourceCreatorclassFileCreatorImplements the "write side" of the JAVAC-doption.protected ResourceFinderclassFileFinderImplements the "read side" of the JAVAC-doption.protected java.io.File[]classPathThe classpath of the currently executing JRE.protected ErrorHandlercompileErrorHandlerStores the value configured withsetCompileErrorHandler(ErrorHandler).protected booleandebugLinesImplements the JAVAC-g:linesoption.protected booleandebugSourceImplements the JAVAC-g:sourceoption.protected booleandebugVarsImplements the JAVAC-g:varsoption.protected java.io.File[]extensionDirectoriesThe list of extension directories of the currently executing JRE.java.nio.charset.CharsetsourceCharsetImplements the JAVAC-encodingoption.protected ResourceFindersourceFinderImplements the JAVAC-sourcepathoption.protected intsourceVersionprotected inttargetVersionprotected WarningHandlerwarningHandlerStores the value configured withsetWarningHandler(WarningHandler).-
Fields inherited from interface org.codehaus.commons.compiler.ICompiler
CREATE_NEXT_TO_SOURCE_FILE, FIND_NEXT_TO_SOURCE_FILE, NO_DESTINATION_DIRECTORY
-
-
Constructor Summary
Constructors Constructor Description AbstractCompiler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancompile(java.io.File[] sourceFiles)Reads a set of Java compilation units (a.k.a.voidsetBootClassPath(java.io.File[] directoriesAndArchives)Equivalent of--boot-class-path.voidsetCharacterEncoding(java.lang.String characterEncoding)voidsetClassFileCreator(ResourceCreator classFileCreator)ThisResourceCreatoris used to store generated.classfiles.voidsetClassFileFinder(ResourceFinder classFileFinder)ThisResourceFinderis used to check whether a.classresource already exists and is younger than the.javaresource from which it was generated.voidsetClassFileFinder(ResourceFinder destination, boolean rebuild)Equivalent withsetClassFileFinder(rebuild ? ResourceFinder.EMPTY_RESOURCE_FINDER : classFileFinder).voidsetClassPath(java.io.File[] directoriesAndArchives)Equivalent of --class-path.voidsetCompileErrorHandler(ErrorHandler compileErrorHandler)Installs anErrorHandlerwhich is invoked during compilation on each error.voidsetDebugLines(boolean value)Equivalent of-g:lines.voidsetDebugSource(boolean value)Equivalent of-g:source.voidsetDebugVars(boolean value)Equivalent of-g:vars.voidsetDestinationDirectory(java.io.File destinationDirectory, boolean rebuild)Equivalent of -d and-rebuild.voidsetEncoding(java.nio.charset.Charset encoding)The equivalent of JAVA's "-encoding" command line option.voidsetExtensionDirectories(java.io.File[] directories)Equivalent of-extdirs.voidsetSourceCharset(java.nio.charset.Charset charset)Same asICompiler.setEncoding(Charset), but with a more precise name.voidsetSourceFinder(ResourceFinder sourceFinder)Finds more.javaresources that need to be compiled, i.e. implements JAVAC's-sourcepathoption.voidsetSourcePath(java.io.File[] directoriesAndArchives)Equivalent of--source-path.voidsetSourceVersion(int version)Specifies the version of source code accepted, in analogy with JAVAC's-sourcecommand line option.voidsetTargetVersion(int version)Generates class files that target a specified release of the virtual machine, in analogy with JAVAC's-targetcommand line option.voidsetWarningHandler(WarningHandler warningHandler)By default, warnings are discarded, but an application my install a customWarningHandler.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.codehaus.commons.compiler.ICompiler
compile, setVerbose
-
-
-
-
Field Detail
-
sourceFinder
protected ResourceFinder sourceFinder
Implements the JAVAC-sourcepathoption.
-
classFileFinder
protected ResourceFinder classFileFinder
Implements the "read side" of the JAVAC-doption.
-
classFileCreator
protected ResourceCreator classFileCreator
Implements the "write side" of the JAVAC-doption.
-
sourceCharset
public java.nio.charset.Charset sourceCharset
Implements the JAVAC-encodingoption.
-
debugSource
protected boolean debugSource
Implements the JAVAC-g:sourceoption.
-
debugLines
protected boolean debugLines
Implements the JAVAC-g:linesoption.
-
debugVars
protected boolean debugVars
Implements the JAVAC-g:varsoption.
-
sourceVersion
protected int sourceVersion
-
targetVersion
protected int targetVersion
-
extensionDirectories
protected java.io.File[] extensionDirectories
The list of extension directories of the currently executing JRE. Empty for Java 9+, because the system property "java.ext.dirs" is not set in JRE 9+.
-
classPath
protected java.io.File[] classPath
The classpath of the currently executing JRE.
-
bootClassPath
@Nullable protected java.io.File[] bootClassPath
This is always non-nullfor JVMs that support BOOTCLASSPATH (1.0-1.8), and this is alwaysnullfor JVMs that don't (9+).
-
compileErrorHandler
@Nullable protected ErrorHandler compileErrorHandler
Stores the value configured withsetCompileErrorHandler(ErrorHandler).
-
warningHandler
@Nullable protected WarningHandler warningHandler
Stores the value configured withsetWarningHandler(WarningHandler).
-
-
Method Detail
-
setSourceFinder
public void setSourceFinder(ResourceFinder sourceFinder)
Description copied from interface:ICompilerFinds more.javaresources that need to be compiled, i.e. implements JAVAC's-sourcepathoption.- Specified by:
setSourceFinderin interfaceICompiler
-
setClassFileFinder
public final void setClassFileFinder(ResourceFinder destination, boolean rebuild)
Description copied from interface:ICompilerEquivalent withsetClassFileFinder(rebuild ? ResourceFinder.EMPTY_RESOURCE_FINDER : classFileFinder).- Specified by:
setClassFileFinderin interfaceICompiler
-
setClassFileFinder
public void setClassFileFinder(ResourceFinder classFileFinder)
Description copied from interface:ICompilerThisResourceFinderis used to check whether a.classresource already exists and is younger than the.javaresource from which it was generated.If it is impossible to check whether an already-compiled class file exists, or if you want to enforce recompilation, pass
ResourceFinder.EMPTY_RESOURCE_FINDERas the classFileFinder.The default is, as for JAVAC,
ICompiler.FIND_NEXT_TO_SOURCE_FILE.- Specified by:
setClassFileFinderin interfaceICompiler- Parameters:
classFileFinder- Special valueICompiler.FIND_NEXT_TO_SOURCE_FILEmeans ".class file is next to its source file, not in the destination directory"- See Also:
ICompiler.FIND_NEXT_TO_SOURCE_FILE
-
setClassFileCreator
public final void setClassFileCreator(ResourceCreator classFileCreator)
Description copied from interface:ICompilerThisResourceCreatoris used to store generated.classfiles.The default is, as for JAVAC,
ICompiler.CREATE_NEXT_TO_SOURCE_FILE.- Specified by:
setClassFileCreatorin interfaceICompiler- Parameters:
classFileCreator- Stores the generated class files (a.k.a. "-d"); special valueICompiler.CREATE_NEXT_TO_SOURCE_FILEmeans "create each .class file in the same directory as its source file"- See Also:
ICompiler.CREATE_NEXT_TO_SOURCE_FILE
-
compile
public final boolean compile(java.io.File[] sourceFiles) throws CompileException, java.io.IOExceptionDescription copied from interface:ICompilerReads a set of Java compilation units (a.k.a. "source files") from the file system, compiles them into a set of "class files" and stores these in the file system. Additional source files are parsed and compiled on demand through the "source path" set of directories.For example, if the source path comprises the directories "A/B" and "../C", then the source file for class "com.acme.Main" is searched in
- A/B/com/acme/Main.java
- ../C/com/acme/Main.java
Notice that it does make a difference whether you pass multiple source files to
ICompiler.compile(File[])or if you invokeICompiler.compile(File[])multiply: In the former case, the source files may contain arbitrary references among each other (even circular ones). In the latter case, only the source files on the source path may contain circular references, not the sourceFiles.This method must be called exactly once after object construction.
Compile errors are reported as described at
ICompiler.setCompileErrorHandler(ErrorHandler).- Specified by:
compilein interfaceICompiler- Parameters:
sourceFiles- Contain the compilation units to compile- Returns:
truefor backwards compatibility (return value can safely be ignored)- Throws:
CompileException- Fatal compilation error, or theCompileExceptionthrown be the installed compile error handlerjava.io.IOException- Occurred when reading from the sourceFiles
- A/B/com/acme/Main.java
-
setEncoding
public final void setEncoding(java.nio.charset.Charset encoding)
Description copied from interface:ICompilerThe equivalent of JAVA's "-encoding" command line option.- Specified by:
setEncodingin interfaceICompiler- See Also:
ICompiler.setSourceCharset(Charset)
-
setSourceCharset
public void setSourceCharset(java.nio.charset.Charset charset)
Description copied from interface:ICompilerSame asICompiler.setEncoding(Charset), but with a more precise name.- Specified by:
setSourceCharsetin interfaceICompiler
-
setCharacterEncoding
public final void setCharacterEncoding(@Nullable java.lang.String characterEncoding)
- Specified by:
setCharacterEncodingin interfaceICompiler
-
setDebugLines
public void setDebugLines(boolean value)
Description copied from interface:ICompilerEquivalent of-g:lines.- Specified by:
setDebugLinesin interfaceICompiler
-
setDebugVars
public void setDebugVars(boolean value)
Description copied from interface:ICompilerEquivalent of-g:vars.- Specified by:
setDebugVarsin interfaceICompiler
-
setDebugSource
public void setDebugSource(boolean value)
Description copied from interface:ICompilerEquivalent of-g:source.- Specified by:
setDebugSourcein interfaceICompiler
-
setSourceVersion
public void setSourceVersion(int version)
Description copied from interface:ICompilerSpecifies the version of source code accepted, in analogy with JAVAC's-sourcecommand line option. May be ignored by an implementation (e.g. thejaninoimplementation always accepts the language features as described on the home page). Allowed values, and the default value, depend on the implementation.-1means to use a default version.- Specified by:
setSourceVersionin interfaceICompiler
-
setTargetVersion
public void setTargetVersion(int version)
Description copied from interface:ICompilerGenerates class files that target a specified release of the virtual machine, in analogy with JAVAC's-targetcommand line option. Allowed values depend on the implementation. The default value also depends on the implementation. The only invariant is that the generated class files are suitable for the currently executing JVM.-1means to use a default version.- Specified by:
setTargetVersionin interfaceICompiler
-
setSourcePath
public void setSourcePath(java.io.File[] directoriesAndArchives)
Description copied from interface:ICompilerEquivalent of--source-path.Equivalent with
setSourceFinder(new PathResourceFinder(directoriesAndArchives)).- Specified by:
setSourcePathin interfaceICompiler
-
setBootClassPath
public void setBootClassPath(java.io.File[] directoriesAndArchives)
Description copied from interface:ICompilerEquivalent of--boot-class-path.- Specified by:
setBootClassPathin interfaceICompiler
-
setExtensionDirectories
public void setExtensionDirectories(java.io.File[] directories)
Description copied from interface:ICompilerEquivalent of-extdirs.- Specified by:
setExtensionDirectoriesin interfaceICompiler
-
setClassPath
public void setClassPath(java.io.File[] directoriesAndArchives)
Description copied from interface:ICompilerEquivalent of --class-path.- Specified by:
setClassPathin interfaceICompiler
-
setDestinationDirectory
public final void setDestinationDirectory(@Nullable java.io.File destinationDirectory, boolean rebuild)
Description copied from interface:ICompilerEquivalent of -d and-rebuild.Overrides any previously configured
class file finderandclass file creator.- Specified by:
setDestinationDirectoryin interfaceICompiler- Parameters:
destinationDirectory-ICompiler.NO_DESTINATION_DIRECTORYmeans "create .class resources in the directory of the .java resource from which they are generated"- See Also:
ICompiler.NO_DESTINATION_DIRECTORY,ICompiler.setClassFileFinder(ResourceFinder),ICompiler.setClassFileCreator(ResourceCreator)
-
setCompileErrorHandler
public void setCompileErrorHandler(@Nullable ErrorHandler compileErrorHandler)
Description copied from interface:ICompilerInstalls anErrorHandlerwhich is invoked during compilation on each error. (By default, the compilation throws aCompileExceptionon the first error and terminates.)If the given
ErrorHandlerthrows aCompileException, then the compilation terminates and the exception is propagated.If the given
ErrorHandlerdoes not throw aCompileExceptionbut completes normally, then the compilation may or may not continue, depending on the error. Iff the compilation of a compilation unit completes normally but errors were reported, then it will throw aCompileExceptionindicating the number of errors.In other words: The
ErrorHandlermay throw aCompileExceptionor not, but the compilation will definitely throw aCompileExceptionif one or more compile errors have occurred.- Specified by:
setCompileErrorHandlerin interfaceICompiler- Parameters:
compileErrorHandler-nullto restore the default behavior (throwing aCompileException)
-
setWarningHandler
public void setWarningHandler(@Nullable WarningHandler warningHandler)
Description copied from interface:ICompilerBy default, warnings are discarded, but an application my install a customWarningHandler.- Specified by:
setWarningHandlerin interfaceICompiler- Parameters:
warningHandler-nullto indicate that no warnings be issued
-
-