public class JavacCompiler extends AbstractCompiler
Modifier and Type | Field and Description |
---|---|
private static java.lang.Class<?> |
JAVAC_CLASS |
private static java.lang.String |
JAVAC_CLASSNAME |
private java.util.List<java.lang.Class<?>> |
javaccClasses |
private static java.lang.Object |
LOCK |
private static java.lang.String[] |
MISC_PREFIXES |
private static java.lang.String[] |
NOTE_PREFIXES |
private static java.lang.String[] |
WARNING_PREFIXES |
EOL, PS
Constructor and Description |
---|
JavacCompiler() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String[] |
buildCompilerArguments(CompilerConfiguration config,
java.lang.String[] sourceFiles) |
(package private) CompilerResult |
compileInProcess(java.lang.String[] args,
CompilerConfiguration config)
Compile the java sources in the current JVM, without calling an external executable,
using
com.sun.tools.javac.Main class |
private static CompilerResult |
compileInProcess0(java.lang.Class<?> javacClass,
java.lang.String[] args)
Helper method for compileInProcess()
|
protected CompilerResult |
compileInProcessWithProperClassloader(java.lang.Class<?> javacClass,
java.lang.String[] args) |
protected CompilerResult |
compileOutOfProcess(CompilerConfiguration config,
java.lang.String executable,
java.lang.String[] args)
Compile the java sources in a external process, calling an external executable,
like javac.
|
java.lang.String[] |
createCommandLine(CompilerConfiguration config)
Create the command line that would be executed using this configuration.
|
private java.io.File |
createFileWithArguments(java.lang.String[] args,
java.lang.String outputDirectory)
put args into a temp file to be referenced using the @ option in javac command line
|
protected java.lang.Class<?> |
createJavacClass()
Helper method for create Javac class
|
private java.lang.Class<?> |
getJavacClass(CompilerConfiguration compilerConfiguration)
Find the main class of JavaC.
|
private static java.lang.String |
getJavacExecutable()
Get the path of the javac tool executable: try to find it depending the OS or the
java.home
system property or the JAVA_HOME environment variable. |
private static java.lang.String |
getWarnPrefix(java.lang.String msg) |
protected static boolean |
isJava16() |
private static boolean |
isMisc(java.lang.String line) |
private static boolean |
isNote(java.lang.String line) |
private static boolean |
isPreJava14(CompilerConfiguration config)
Determine if the compiler is a version prior to 1.4.
|
private static boolean |
isPreJava16(CompilerConfiguration config)
Determine if the compiler is a version prior to 1.6.
|
(package private) static CompilerMessage |
parseModernError(int exitCode,
java.lang.String error)
Construct a CompilerMessage object from a line of the compiler output
|
(package private) static java.util.List<CompilerMessage> |
parseModernStream(int exitCode,
java.io.BufferedReader input)
Parse the output from the compiler into a list of CompilerMessage objects
|
CompilerResult |
performCompile(CompilerConfiguration config)
Performs the compilation of the project.
|
private void |
releaseJavaccClass(java.lang.Class<?> javaccClass,
CompilerConfiguration compilerConfiguration) |
private static boolean |
startsWithPrefix(java.lang.String line,
java.lang.String[] prefixes) |
private static boolean |
suppressEncoding(CompilerConfiguration config) |
private static boolean |
suppressSource(CompilerConfiguration config) |
canUpdateTarget, compile, getCompilerOutputStyle, getInputFileEnding, getOutputFile, getOutputFileEnding, getPathString, getSourceFiles, getSourceFilesForSourceRoot, makeClassName, toStringArray
private static final java.lang.String[] WARNING_PREFIXES
private static final java.lang.String[] NOTE_PREFIXES
private static final java.lang.String[] MISC_PREFIXES
private static final java.lang.Object LOCK
private static final java.lang.String JAVAC_CLASSNAME
private static volatile java.lang.Class<?> JAVAC_CLASS
private java.util.List<java.lang.Class<?>> javaccClasses
public CompilerResult performCompile(CompilerConfiguration config) throws CompilerException
Compiler
performCompile
in interface Compiler
performCompile
in class AbstractCompiler
config
- the configuration description of the compilation
to performCompilerException
protected static boolean isJava16()
public java.lang.String[] createCommandLine(CompilerConfiguration config) throws CompilerException
Compiler
config
- the CompilerConfiguration describing the compilationCompilerException
- if there was an error generating the command
linepublic static java.lang.String[] buildCompilerArguments(CompilerConfiguration config, java.lang.String[] sourceFiles)
private static boolean isPreJava14(CompilerConfiguration config)
config
- The compiler configuration to test.private static boolean isPreJava16(CompilerConfiguration config)
config
- The compiler configuration to test.private static boolean suppressSource(CompilerConfiguration config)
private static boolean suppressEncoding(CompilerConfiguration config)
protected CompilerResult compileOutOfProcess(CompilerConfiguration config, java.lang.String executable, java.lang.String[] args) throws CompilerException
config
- compiler configurationexecutable
- name of the executable to launchargs
- arguments for the executable launchedCompilerException
CompilerResult compileInProcess(java.lang.String[] args, CompilerConfiguration config) throws CompilerException
com.sun.tools.javac.Main
classargs
- arguments for the compiler as they would be used in the command line javacconfig
- compiler configurationCompilerException
protected CompilerResult compileInProcessWithProperClassloader(java.lang.Class<?> javacClass, java.lang.String[] args) throws CompilerException
CompilerException
private static CompilerResult compileInProcess0(java.lang.Class<?> javacClass, java.lang.String[] args) throws CompilerException
CompilerException
static java.util.List<CompilerMessage> parseModernStream(int exitCode, java.io.BufferedReader input) throws java.io.IOException
exitCode
- The exit code of javac.input
- The output of the compilerjava.io.IOException
private static boolean isMisc(java.lang.String line)
private static boolean isNote(java.lang.String line)
private static boolean startsWithPrefix(java.lang.String line, java.lang.String[] prefixes)
static CompilerMessage parseModernError(int exitCode, java.lang.String error)
exitCode
- The exit code from javac.error
- output line from the compilerprivate static java.lang.String getWarnPrefix(java.lang.String msg)
private java.io.File createFileWithArguments(java.lang.String[] args, java.lang.String outputDirectory) throws java.io.IOException
args
- java.io.IOException
private static java.lang.String getJavacExecutable() throws java.io.IOException
java.home
system property or the JAVA_HOME
environment variable.java.io.IOException
- if not foundprivate void releaseJavaccClass(java.lang.Class<?> javaccClass, CompilerConfiguration compilerConfiguration)
private java.lang.Class<?> getJavacClass(CompilerConfiguration compilerConfiguration) throws CompilerException
CompilerException
- if the class has not been found.protected java.lang.Class<?> createJavacClass() throws CompilerException
CompilerException