public final class JkJavaCompiler
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
boolean |
compile(JkJavaCompileSpec compileSpec)
Actually compile the source files to the output directory.
|
static JkProcess |
getForkedProcessOnJavaSourceVersion(java.util.Map<java.lang.String,java.lang.String> jdkLocations,
java.lang.String version)
Returns a
JkProcess standing for a forking compiler with relevant JDK if this specified source version
does not match with the current running JDK. |
boolean |
isDefault()
Returns
true if no compiler or fork has been set on. |
static JkJavaCompiler |
of(javax.tools.JavaCompiler compiler) |
static JkJavaCompiler |
ofJdk()
Creates a
JkJavaCompiler producing its output in the given directory. |
JkJavaCompiler |
withCompiler(javax.tools.JavaCompiler compiler)
Creates a copy of this
JkJavaCompiler but with the specified compileRunner instance. |
JkJavaCompiler |
withFailOnError(boolean fail)
Creates a copy of this
JkJavaCompiler but with the specified
failed-on-error parameter. |
JkJavaCompiler |
withForking(boolean fork,
java.lang.String... parameters)
|
JkJavaCompiler |
withForking(JkProcess compileProcess) |
JkJavaCompiler |
withForking(java.lang.String... parameters)
Creates a copy of this
JkJavaCompiler but with forking the javac
process. |
JkJavaCompiler |
withForkingOnCompiler(java.lang.String executable,
java.lang.String... parameters)
As
withForking(String...) but specifying the executable for the compileRunner. |
JkJavaCompiler |
withJavacBin(JkJavaVersion version,
java.nio.file.Path javacBin)
Creates a copy of this
JkJavaCompiler but adding an external java compileRunner for
the specified source version. |
public static JkJavaCompiler ofJdk()
JkJavaCompiler
producing its output in the given directory.public static JkJavaCompiler of(javax.tools.JavaCompiler compiler)
public JkJavaCompiler withFailOnError(boolean fail)
JkJavaCompiler
but with the specified
failed-on-error parameter. If true
then
a compilation error will throw a IllegalStateException
.public JkJavaCompiler withForking(java.lang.String... parameters)
JkJavaCompiler
but with forking the javac
process. The javac process is created using specified argument defined in
JkProcess.ofJavaTool(String, String...)
public JkJavaCompiler withForking(boolean fork, java.lang.String... parameters)
public JkJavaCompiler withForking(JkProcess compileProcess)
public JkJavaCompiler withForkingOnCompiler(java.lang.String executable, java.lang.String... parameters)
withForking(String...)
but specifying the executable for the compileRunner.executable
- The executable for the compileRunner as 'jike' or '/my/specific/jdk/javac'public JkJavaCompiler withCompiler(javax.tools.JavaCompiler compiler)
JkJavaCompiler
but with the specified compileRunner instance.
Since in-process compilers cannot be run andAccept a withForking process, this method disables any
previous fork options that may have been set.public JkJavaCompiler withJavacBin(JkJavaVersion version, java.nio.file.Path javacBin)
JkJavaCompiler
but adding an external java compileRunner for
the specified source version. The compileRunner will try to get compliant compileRunner to
compile source.public boolean isDefault()
true
if no compiler or fork has been set on.public boolean compile(JkJavaCompileSpec compileSpec)
false
if a compilation error occurred.java.lang.IllegalStateException
- if a compilation error occurred and the 'withFailOnError' flag is true
.public static JkProcess getForkedProcessOnJavaSourceVersion(java.util.Map<java.lang.String,java.lang.String> jdkLocations, java.lang.String version)
JkProcess
standing for a forking compiler with relevant JDK if this specified source version
does not match with the current running JDK. The specified map may include
the JDK location for this source version.
If no need to fork, cause current JDK is aligned with target version, then this method returns null
.
The keys must be formatted as "jdk.[source version]". For example, "jdk.1.4" or
"jdk.7". The values must absolute path.