public final class JkJavaCompilerToolChain
extends java.lang.Object
JavaCompiler
instance either an external
process (forked mode).
The compiler selection follows these rules :
Modifier and Type | Class and Description |
---|---|
static class |
JkJavaCompilerToolChain.JkJdks |
Modifier and Type | Field and Description |
---|---|
static java.nio.file.PathMatcher |
JAVA_SOURCE_MATCHER
Filter to consider only Java source
|
Modifier and Type | Method and Description |
---|---|
boolean |
compile(JkJavaCompileSpec compileSpec) |
boolean |
compile(JkJavaVersion targetVersion,
JkJavaCompileSpec compileSpec)
Actually compile the source files to the output directory.
|
boolean |
isCompilationForked(JkJavaVersion javaVersion,
JkJavaCompileSpec compileSpec)
Determines if the Java compilation process is forked into an external process.
|
boolean |
isToolOrProcessSpecified() |
static JkJavaCompilerToolChain |
of()
Creates a
JkJavaCompilerToolChain without specifying a JavaCompiler instance or an external process. |
JkJavaCompilerToolChain |
setCompileTool(javax.tools.JavaCompiler tool,
java.lang.String... params)
Sets underlying java compiler tool to use.
|
JkJavaCompilerToolChain |
setForkCompiler(boolean forkCompiler)
Configures whether the Java compilation process should be forked into
an external process.
|
JkJavaCompilerToolChain |
setJavacProcess(JkProcess compileProcess)
Sets the underlying compiler with the specified process.
|
JkJavaCompilerToolChain |
setJdkHints(JkJavaCompilerToolChain.JkJdks jdks,
boolean preferInProcess)
Sets the JDK hints to specify the available JDKs and whether to prefer in-process tool for compilation.
|
public static final java.nio.file.PathMatcher JAVA_SOURCE_MATCHER
public static JkJavaCompilerToolChain of()
JkJavaCompilerToolChain
without specifying a JavaCompiler
instance or an external process.
When nothing is specified, this compiler will try the default JavaCompiler
instance provided
by the running JDK.public JkJavaCompilerToolChain setCompileTool(javax.tools.JavaCompiler tool, java.lang.String... params)
public JkJavaCompilerToolChain setJavacProcess(JkProcess compileProcess)
public JkJavaCompilerToolChain setJdkHints(JkJavaCompilerToolChain.JkJdks jdks, boolean preferInProcess)
jdks
- A JkJavaCompilerToolChain.JkJdks
instance defining the JDKs to be considered during compilation.preferInProcess
- If true, the compiler tool is preferred over process-based compilation;
otherwise, the process is preferred.JkJavaCompilerToolChain
with updated JDK hints.public JkJavaCompilerToolChain setForkCompiler(boolean forkCompiler)
forkCompiler
- If true, the compilation process will be forked into
an external process. If false, the compilation will
occur in-process.JkJavaCompilerToolChain
with the
updated fork configuration.public boolean isToolOrProcessSpecified()
public boolean compile(JkJavaVersion targetVersion, JkJavaCompileSpec compileSpec)
targetVersion
- Can be null
. Provides the version of JDK
to use for javac. If null
, it will try
to infer JDK version from #compileSpec.compileSpec
- Contains options to pass to the Java compiler. It includes sources,
versions, and other options specified for the compiler.false
if a compilation error occurred.java.lang.IllegalStateException
- if a compilation error occurred and the 'withFailOnError' flag is true
.public boolean compile(JkJavaCompileSpec compileSpec)
public boolean isCompilationForked(JkJavaVersion javaVersion, JkJavaCompileSpec compileSpec)