Class AbstractCompiler

  • All Implemented Interfaces:
    ICompiler
    Direct Known Subclasses:
    Compiler, Compiler

    public abstract class AbstractCompiler
    extends java.lang.Object
    implements ICompiler
    A base class and wrapper for Compiler that implements all redundant API methods.
    • Field Detail

      • sourceFinder

        protected ResourceFinder sourceFinder
        Implements the JAVAC -sourcepath option.
      • classFileFinder

        protected ResourceFinder classFileFinder
        Implements the "read side" of the JAVAC -d option.
      • classFileCreator

        protected ResourceCreator classFileCreator
        Implements the "write side" of the JAVAC -d option.
      • sourceCharset

        public java.nio.charset.Charset sourceCharset
        Implements the JAVAC -encoding option.
      • debugSource

        protected boolean debugSource
        Implements the JAVAC -g:source option.
      • debugLines

        protected boolean debugLines
        Implements the JAVAC -g:lines option.
      • debugVars

        protected boolean debugVars
        Implements the JAVAC -g:vars option.
      • 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-null for JVMs that support BOOTCLASSPATH (1.0-1.8), and this is always null for JVMs that don't (9+).
    • Constructor Detail

      • AbstractCompiler

        public AbstractCompiler()
    • Method Detail

      • setSourceFinder

        public void setSourceFinder​(ResourceFinder sourceFinder)
        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 interface ICompiler
      • setClassFileFinder

        public final void setClassFileFinder​(ResourceFinder destination,
                                             boolean rebuild)
        Description copied from interface: ICompiler
        Equivalent with setClassFileFinder(rebuild ? ResourceFinder.EMPTY_RESOURCE_FINDER : classFileFinder).
        Specified by:
        setClassFileFinder in interface ICompiler
      • compile

        public final boolean compile​(java.io.File[] sourceFiles)
                              throws CompileException,
                                     java.io.IOException
        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 invoke ICompiler.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 interface ICompiler
        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 the CompileException thrown be the installed compile error handler
        java.io.IOException - Occurred when reading from the sourceFiles
      • setDebugLines

        public void setDebugLines​(boolean value)
        Description copied from interface: ICompiler
        Equivalent of -g:lines.
        Specified by:
        setDebugLines in interface ICompiler
      • setDebugVars

        public void setDebugVars​(boolean value)
        Description copied from interface: ICompiler
        Equivalent of -g:vars.
        Specified by:
        setDebugVars in interface ICompiler
      • setDebugSource

        public void setDebugSource​(boolean value)
        Description copied from interface: ICompiler
        Equivalent of -g:source.
        Specified by:
        setDebugSource in interface ICompiler
      • 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. the janino 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 interface ICompiler
      • 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 interface ICompiler
      • setSourcePath

        public void setSourcePath​(java.io.File[] directoriesAndArchives)
        Description copied from interface: ICompiler
        Equivalent of --source-path.

        Equivalent with setSourceFinder(new PathResourceFinder(directoriesAndArchives)).

        Specified by:
        setSourcePath in interface ICompiler
      • setExtensionDirectories

        public void setExtensionDirectories​(java.io.File[] directories)
        Description copied from interface: ICompiler
        Equivalent of -extdirs.
        Specified by:
        setExtensionDirectories in interface ICompiler
      • setWarningHandler

        public void setWarningHandler​(@Nullable
                                      WarningHandler warningHandler)
        Description copied from interface: ICompiler
        By default, warnings are discarded, but an application my install a custom WarningHandler.
        Specified by:
        setWarningHandler in interface ICompiler
        Parameters:
        warningHandler - null to indicate that no warnings be issued