Class JavacCompiler
- java.lang.Object
-
- org.codehaus.plexus.logging.AbstractLogEnabled
-
- org.codehaus.plexus.compiler.AbstractCompiler
-
- org.codehaus.plexus.compiler.javac.JavacCompiler
-
- All Implemented Interfaces:
Compiler,org.codehaus.plexus.logging.LogEnabled
@Component(role=Compiler.class, hint="javac ") public class JavacCompiler extends AbstractCompiler
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.Class<?>JAVAC_CLASSprivate static java.lang.StringJAVAC_CLASSNAMEprivate java.util.List<java.lang.Class<?>>javaccClassesprivate static java.lang.ObjectLOCKprivate static java.lang.String[]MISC_PREFIXESprivate static java.lang.String[]NOTE_PREFIXESprivate static java.lang.String[]WARNING_PREFIXES-
Fields inherited from class org.codehaus.plexus.compiler.AbstractCompiler
EOL, PS
-
-
Constructor Summary
Constructors Constructor Description JavacCompiler()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.String[]buildCompilerArguments(CompilerConfiguration config, java.lang.String[] sourceFiles)(package private) CompilerResultcompileInProcess(java.lang.String[] args, CompilerConfiguration config)Compile the java sources in the current JVM, without calling an external executable, usingcom.sun.tools.javac.Mainclassprivate static CompilerResultcompileInProcess0(java.lang.Class<?> javacClass, java.lang.String[] args)Helper method for compileInProcess()protected CompilerResultcompileInProcessWithProperClassloader(java.lang.Class<?> javacClass, java.lang.String[] args)protected CompilerResultcompileOutOfProcess(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.FilecreateFileWithArguments(java.lang.String[] args, java.lang.String outputDirectory)put args into a temp file to be referenced using the @ option in javac command lineprotected java.lang.Class<?>createJavacClass()Helper method for create Javac classprivate java.lang.Class<?>getJavacClass(CompilerConfiguration compilerConfiguration)Find the main class of JavaC.private static java.lang.StringgetJavacExecutable()Get the path of the javac tool executable: try to find it depending the OS or thejava.homesystem property or theJAVA_HOMEenvironment variable.private static java.lang.StringgetWarnPrefix(java.lang.String msg)protected InProcessCompilerinProcessCompiler()protected static booleanisJava16()private static booleanisMisc(java.lang.String line)private static booleanisNote(java.lang.String line)private static booleanisPreJava14(CompilerConfiguration config)Determine if the compiler is a version prior to 1.4.private static booleanisPreJava16(CompilerConfiguration config)Determine if the compiler is a version prior to 1.6.private static booleanisPreJava18(CompilerConfiguration config)(package private) static CompilerMessageparseModernError(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 objectsCompilerResultperformCompile(CompilerConfiguration config)Performs the compilation of the project.private voidreleaseJavaccClass(java.lang.Class<?> javaccClass, CompilerConfiguration compilerConfiguration)private static booleanstartsWithPrefix(java.lang.String line, java.lang.String[] prefixes)private static booleansuppressEncoding(CompilerConfiguration config)private static booleansuppressSource(CompilerConfiguration config)-
Methods inherited from class org.codehaus.plexus.compiler.AbstractCompiler
canUpdateTarget, compile, getCompilerOutputStyle, getInputFileEnding, getOutputFile, getOutputFileEnding, getPathString, getSourceFiles, getSourceFilesForSourceRoot, makeClassName, toStringArray
-
-
-
-
Field Detail
-
WARNING_PREFIXES
private static final java.lang.String[] WARNING_PREFIXES
-
NOTE_PREFIXES
private static final java.lang.String[] NOTE_PREFIXES
-
MISC_PREFIXES
private static final java.lang.String[] MISC_PREFIXES
-
LOCK
private static final java.lang.Object LOCK
-
JAVAC_CLASSNAME
private static final java.lang.String JAVAC_CLASSNAME
- See Also:
- Constant Field Values
-
JAVAC_CLASS
private static volatile java.lang.Class<?> JAVAC_CLASS
-
javaccClasses
private java.util.List<java.lang.Class<?>> javaccClasses
-
-
Method Detail
-
performCompile
public CompilerResult performCompile(CompilerConfiguration config) throws CompilerException
Description copied from interface:CompilerPerforms the compilation of the project. Clients must implement this method.- Specified by:
performCompilein interfaceCompiler- Overrides:
performCompilein classAbstractCompiler- Parameters:
config- the configuration description of the compilation to perform- Returns:
- the result of the compilation returned by the language processor
- Throws:
CompilerException
-
inProcessCompiler
protected InProcessCompiler inProcessCompiler()
-
isJava16
protected static boolean isJava16()
-
createCommandLine
public java.lang.String[] createCommandLine(CompilerConfiguration config) throws CompilerException
Description copied from interface:CompilerCreate the command line that would be executed using this configuration. If this particular compiler has no concept of a command line then returns null.- Parameters:
config- the CompilerConfiguration describing the compilation- Returns:
- an array of Strings that make up the command line, or null if this compiler has no concept of command line
- Throws:
CompilerException- if there was an error generating the command line
-
buildCompilerArguments
public static java.lang.String[] buildCompilerArguments(CompilerConfiguration config, java.lang.String[] sourceFiles)
-
isPreJava14
private static boolean isPreJava14(CompilerConfiguration config)
Determine if the compiler is a version prior to 1.4. This is needed as 1.3 and earlier did not support -source or -encoding parameters- Parameters:
config- The compiler configuration to test.- Returns:
- true if the compiler configuration represents a Java 1.4 compiler or later, false otherwise
-
isPreJava16
private static boolean isPreJava16(CompilerConfiguration config)
Determine if the compiler is a version prior to 1.6. This is needed for annotation processing parameters.- Parameters:
config- The compiler configuration to test.- Returns:
- true if the compiler configuration represents a Java 1.6 compiler or later, false otherwise
-
isPreJava18
private static boolean isPreJava18(CompilerConfiguration config)
-
suppressSource
private static boolean suppressSource(CompilerConfiguration config)
-
suppressEncoding
private static boolean suppressEncoding(CompilerConfiguration config)
-
compileOutOfProcess
protected CompilerResult compileOutOfProcess(CompilerConfiguration config, java.lang.String executable, java.lang.String[] args) throws CompilerException
Compile the java sources in a external process, calling an external executable, like javac.- Parameters:
config- compiler configurationexecutable- name of the executable to launchargs- arguments for the executable launched- Returns:
- a CompilerResult object encapsulating the result of the compilation and any compiler messages
- Throws:
CompilerException
-
compileInProcess
CompilerResult compileInProcess(java.lang.String[] args, CompilerConfiguration config) throws CompilerException
Compile the java sources in the current JVM, without calling an external executable, usingcom.sun.tools.javac.Mainclass- Parameters:
args- arguments for the compiler as they would be used in the command line javacconfig- compiler configuration- Returns:
- a CompilerResult object encapsulating the result of the compilation and any compiler messages
- Throws:
CompilerException
-
compileInProcessWithProperClassloader
protected CompilerResult compileInProcessWithProperClassloader(java.lang.Class<?> javacClass, java.lang.String[] args) throws CompilerException
- Throws:
CompilerException
-
compileInProcess0
private static CompilerResult compileInProcess0(java.lang.Class<?> javacClass, java.lang.String[] args) throws CompilerException
Helper method for compileInProcess()- Throws:
CompilerException
-
parseModernStream
static java.util.List<CompilerMessage> parseModernStream(int exitCode, java.io.BufferedReader input) throws java.io.IOException
Parse the output from the compiler into a list of CompilerMessage objects- Parameters:
exitCode- The exit code of javac.input- The output of the compiler- Returns:
- List of CompilerMessage objects
- Throws:
java.io.IOException
-
isMisc
private static boolean isMisc(java.lang.String line)
-
isNote
private static boolean isNote(java.lang.String line)
-
startsWithPrefix
private static boolean startsWithPrefix(java.lang.String line, java.lang.String[] prefixes)
-
parseModernError
static CompilerMessage parseModernError(int exitCode, java.lang.String error)
Construct a CompilerMessage object from a line of the compiler output- Parameters:
exitCode- The exit code from javac.error- output line from the compiler- Returns:
- the CompilerMessage object
-
getWarnPrefix
private static java.lang.String getWarnPrefix(java.lang.String msg)
-
createFileWithArguments
private java.io.File createFileWithArguments(java.lang.String[] args, java.lang.String outputDirectory) throws java.io.IOExceptionput args into a temp file to be referenced using the @ option in javac command line- Parameters:
args-- Returns:
- the temporary file wth the arguments
- Throws:
java.io.IOException
-
getJavacExecutable
private static java.lang.String getJavacExecutable() throws java.io.IOExceptionGet the path of the javac tool executable: try to find it depending the OS or thejava.homesystem property or theJAVA_HOMEenvironment variable.- Returns:
- the path of the Javadoc tool
- Throws:
java.io.IOException- if not found
-
releaseJavaccClass
private void releaseJavaccClass(java.lang.Class<?> javaccClass, CompilerConfiguration compilerConfiguration)
-
getJavacClass
private java.lang.Class<?> getJavacClass(CompilerConfiguration compilerConfiguration) throws CompilerException
Find the main class of JavaC. Return the same class for subsequent calls.- Returns:
- the non-null class.
- Throws:
CompilerException- if the class has not been found.
-
createJavacClass
protected java.lang.Class<?> createJavacClass() throws CompilerExceptionHelper method for create Javac class- Throws:
CompilerException
-
-