Class AbstractCompiler
- All Implemented Interfaces:
ICompiler
Compiler
that implements all redundant API methods.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected File[]
This is always non-null
for JVMs that support BOOTCLASSPATH (1.0-1.8), and this is alwaysnull
for JVMs that don't (9+).protected ResourceCreator
Implements the "write side" of the JAVAC-d
option.protected ResourceFinder
Implements the "read side" of the JAVAC-d
option.protected File[]
The classpath of the currently executing JRE.protected ErrorHandler
Stores the value configured withsetCompileErrorHandler(ErrorHandler)
.protected boolean
Implements the JAVAC-g:lines
option.protected boolean
Implements the JAVAC-g:source
option.protected boolean
Implements the JAVAC-g:vars
option.protected File[]
The list of extension directories of the currently executing JRE.Implements the JAVAC-encoding
option.protected ResourceFinder
Implements the JAVAC-sourcepath
option.protected int
protected int
protected WarningHandler
Stores 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 -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
Reads a set of Java compilation units (a.k.a.void
setBootClassPath
(File[] directoriesAndArchives) Equivalent of--boot-class-path
.final void
setCharacterEncoding
(String characterEncoding) final void
setClassFileCreator
(ResourceCreator classFileCreator) ThisResourceCreator
is used to store generated.class
files.void
setClassFileFinder
(ResourceFinder classFileFinder) ThisResourceFinder
is used to check whether a.class
resource already exists and is younger than the.java
resource from which it was generated.final void
setClassFileFinder
(ResourceFinder destination, boolean rebuild) Equivalent withsetClassFileFinder(rebuild ? ResourceFinder.EMPTY_RESOURCE_FINDER : classFileFinder)
.void
setClassPath
(File[] directoriesAndArchives) Equivalent of --class-path.void
setCompileErrorHandler
(ErrorHandler compileErrorHandler) Installs anErrorHandler
which is invoked during compilation on each error.void
setDebugLines
(boolean value) Equivalent of-g:lines
.void
setDebugSource
(boolean value) Equivalent of-g:source
.void
setDebugVars
(boolean value) Equivalent of-g:vars
.final void
setDestinationDirectory
(File destinationDirectory, boolean rebuild) Equivalent of -d and-rebuild
.final void
setEncoding
(Charset encoding) The equivalent of JAVA's "-encoding
" command line option.void
setExtensionDirectories
(File[] directories) Equivalent of-extdirs
.void
setSourceCharset
(Charset charset) Same asICompiler.setEncoding(Charset)
, but with a more precise name.void
setSourceFinder
(ResourceFinder sourceFinder) Finds more.java
resources that need to be compiled, i.e.void
setSourcePath
(File[] directoriesAndArchives) Equivalent of--source-path
.void
setSourceVersion
(int version) Specifies the version of source code accepted, in analogy with JAVAC's-source
command line option.void
setTargetVersion
(int version) Generates class files that target a specified release of the virtual machine, in analogy with JAVAC's-target
command line option.void
setWarningHandler
(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 Details
-
sourceFinder
Implements the JAVAC-sourcepath
option. -
classFileFinder
Implements the "read side" of the JAVAC-d
option. -
classFileCreator
Implements the "write side" of the JAVAC-d
option. -
sourceCharset
Implements the JAVAC-encoding
option. -
debugSource
protected boolean debugSourceImplements the JAVAC-g:source
option. -
debugLines
protected boolean debugLinesImplements the JAVAC-g:lines
option. -
debugVars
protected boolean debugVarsImplements the JAVAC-g:vars
option. -
sourceVersion
protected int sourceVersion -
targetVersion
protected int targetVersion -
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
The classpath of the currently executing JRE. -
bootClassPath
This is always non-null
for JVMs that support BOOTCLASSPATH (1.0-1.8), and this is alwaysnull
for JVMs that don't (9+). -
compileErrorHandler
Stores the value configured withsetCompileErrorHandler(ErrorHandler)
. -
warningHandler
Stores the value configured withsetWarningHandler(WarningHandler)
.
-
-
Constructor Details
-
AbstractCompiler
public AbstractCompiler()
-
-
Method Details
-
setSourceFinder
Description copied from interface:ICompiler
Finds more.java
resources that need to be compiled, i.e. implements JAVAC's-sourcepath
option.- Specified by:
setSourceFinder
in interfaceICompiler
-
setClassFileFinder
Description copied from interface:ICompiler
Equivalent withsetClassFileFinder(rebuild ? ResourceFinder.EMPTY_RESOURCE_FINDER : classFileFinder)
.- Specified by:
setClassFileFinder
in interfaceICompiler
-
setClassFileFinder
Description copied from interface:ICompiler
ThisResourceFinder
is used to check whether a.class
resource already exists and is younger than the.java
resource 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_FINDER
as the classFileFinder.The default is, as for JAVAC,
ICompiler.FIND_NEXT_TO_SOURCE_FILE
.- Specified by:
setClassFileFinder
in interfaceICompiler
- Parameters:
classFileFinder
- Special valueICompiler.FIND_NEXT_TO_SOURCE_FILE
means ".class file is next to its source file, not in the destination directory"- See Also:
-
setClassFileCreator
Description copied from interface:ICompiler
ThisResourceCreator
is used to store generated.class
files.The default is, as for JAVAC,
ICompiler.CREATE_NEXT_TO_SOURCE_FILE
.- Specified by:
setClassFileCreator
in interfaceICompiler
- Parameters:
classFileCreator
- Stores the generated class files (a.k.a. "-d"); special valueICompiler.CREATE_NEXT_TO_SOURCE_FILE
means "create each .class file in the same directory as its source file"- See Also:
-
compile
Description copied from interface:ICompiler
Reads 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:
compile
in interfaceICompiler
- Parameters:
sourceFiles
- Contain the compilation units to compile- Returns:
true
for backwards compatibility (return value can safely be ignored)- Throws:
CompileException
- Fatal compilation error, or theCompileException
thrown be the installed compile error handlerIOException
- Occurred when reading from the sourceFiles
- A/B/com/acme/Main.java
-
setEncoding
Description copied from interface:ICompiler
The equivalent of JAVA's "-encoding
" command line option.- Specified by:
setEncoding
in interfaceICompiler
- See Also:
-
setSourceCharset
Description copied from interface:ICompiler
Same asICompiler.setEncoding(Charset)
, but with a more precise name.- Specified by:
setSourceCharset
in interfaceICompiler
-
setCharacterEncoding
- Specified by:
setCharacterEncoding
in interfaceICompiler
-
setDebugLines
public void setDebugLines(boolean value) Description copied from interface:ICompiler
Equivalent of-g:lines
.- Specified by:
setDebugLines
in interfaceICompiler
-
setDebugVars
public void setDebugVars(boolean value) Description copied from interface:ICompiler
Equivalent of-g:vars
.- Specified by:
setDebugVars
in interfaceICompiler
-
setDebugSource
public void setDebugSource(boolean value) Description copied from interface:ICompiler
Equivalent of-g:source
.- Specified by:
setDebugSource
in interfaceICompiler
-
setSourceVersion
public void setSourceVersion(int version) Description copied from interface:ICompiler
Specifies the version of source code accepted, in analogy with JAVAC's-source
command line option. May be ignored by an implementation (e.g. thejanino
implementation always accepts the language features as described on the home page). Allowed values, and the default value, depend on the implementation.-1
means to use a default version.- Specified by:
setSourceVersion
in interfaceICompiler
-
setTargetVersion
public void setTargetVersion(int version) Description copied from interface:ICompiler
Generates class files that target a specified release of the virtual machine, in analogy with JAVAC's-target
command 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.-1
means to use a default version.- Specified by:
setTargetVersion
in interfaceICompiler
-
setSourcePath
Description copied from interface:ICompiler
Equivalent of--source-path
.Equivalent with
setSourceFinder(new PathResourceFinder(directoriesAndArchives))
.- Specified by:
setSourcePath
in interfaceICompiler
-
setBootClassPath
Description copied from interface:ICompiler
Equivalent of--boot-class-path
.- Specified by:
setBootClassPath
in interfaceICompiler
-
setExtensionDirectories
Description copied from interface:ICompiler
Equivalent of-extdirs
.- Specified by:
setExtensionDirectories
in interfaceICompiler
-
setClassPath
Description copied from interface:ICompiler
Equivalent of --class-path.- Specified by:
setClassPath
in interfaceICompiler
-
setDestinationDirectory
Description copied from interface:ICompiler
Equivalent of -d and-rebuild
.Overrides any previously configured
class file finder
andclass file creator
.- Specified by:
setDestinationDirectory
in interfaceICompiler
- Parameters:
destinationDirectory
-ICompiler.NO_DESTINATION_DIRECTORY
means "create .class resources in the directory of the .java resource from which they are generated"- See Also:
-
setCompileErrorHandler
Description copied from interface:ICompiler
Installs anErrorHandler
which is invoked during compilation on each error. (By default, the compilation throws aCompileException
on the first error and terminates.)If the given
ErrorHandler
throws aCompileException
, then the compilation terminates and the exception is propagated.If the given
ErrorHandler
does not throw aCompileException
but 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 aCompileException
indicating the number of errors.In other words: The
ErrorHandler
may throw aCompileException
or not, but the compilation will definitely throw aCompileException
if one or more compile errors have occurred.- Specified by:
setCompileErrorHandler
in interfaceICompiler
- Parameters:
compileErrorHandler
-null
to restore the default behavior (throwing aCompileException
)
-
setWarningHandler
Description copied from interface:ICompiler
By default, warnings are discarded, but an application my install a customWarningHandler
.- Specified by:
setWarningHandler
in interfaceICompiler
- Parameters:
warningHandler
-null
to indicate that no warnings be issued
-