Class JavacCompiler
java.lang.Object
org.codehaus.plexus.compiler.AbstractCompiler
org.codehaus.plexus.compiler.javac.JavacCompiler
- All Implemented Interfaces:
Compiler
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static enumRepresents a particular Java version (through their according version prefixes) -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate InProcessCompilerprivate static final Patternprivate static final Stringprivate static final Patternprivate Class<?> private static final Objectprivate static final String[]private static final String[]private static final Patternprivate static final PatternCache of javac version per executable (never invalidated)private static final String[]Fields inherited from class org.codehaus.plexus.compiler.AbstractCompiler
EOL, PS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String[]buildCompilerArguments(CompilerConfiguration config, String[] sourceFiles, String javacVersion) (package private) CompilerResultcompileInProcess(String[] args, CompilerConfiguration config) Compile the java sources in the current JVM, without calling an external executable, usingcom.sun.tools.javac.Mainclassprivate static CompilerResultcompileInProcess0(Class<?> javacClass, String[] args) Helper method for compileInProcess()protected CompilerResultcompileInProcessWithProperClassloader(Class<?> javacClass, String[] args) protected CompilerResultcompileOutOfProcess(CompilerConfiguration config, String executable, String[] args) Compile the java sources in a external process, calling an external executable, like javac.String[]Create the command line that would be executed using this configuration.private FilecreateFileWithArguments(String[] args, String outputDirectory) put args into a temp file to be referenced using the @ option in javac command lineprotected Class<?> Helper method for create Javac class(package private) static Stringprivate Stringprivate Class<?> getJavacClass(CompilerConfiguration compilerConfiguration) Find the main class of JavaC.private static StringGet the path of the javac tool executable: try to find it depending the OS or thejava.homesystem property or theJAVA_HOMEenvironment variable.protected StringGet the path of the javac tool executable to use.private StringgetOutOfProcessJavacVersion(String executable) private static StringgetWarnPrefix(String msg) protected static booleanprotected InProcessCompilerprivate static booleanprivate static boolean(package private) static CompilerMessageparseModernError(int exitCode, String error) Construct a CompilerMessage object from a line of the compiler output(package private) static List<CompilerMessage> parseModernStream(int exitCode, BufferedReader input) Parse the output from the compiler into a list of CompilerMessage objectsperformCompile(CompilerConfiguration config) Performs the compilation of the project.private voidreleaseJavaccClass(Class<?> javaccClass, CompilerConfiguration compilerConfiguration) private static booleanstartsWithPrefix(String line, String[] prefixes) Methods inherited from class org.codehaus.plexus.compiler.AbstractCompiler
canUpdateTarget, getCompilerOutputStyle, getInputFileEnding, getLog, getLogger, getOutputFile, getOutputFileEnding, getPathString, getSourceFiles, getSourceFilesForSourceRoot, logCompiling, makeClassNameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.codehaus.plexus.compiler.Compiler
supportsIncrementalCompilation
-
Field Details
-
WARNING_PREFIXES
-
NOTE_PREFIXES
-
MISC_PREFIXES
-
LOCK
-
JAVAC_CLASSNAME
- See Also:
-
javacClass
-
javacClasses
-
JAVA_MAJOR_AND_MINOR_VERSION_PATTERN
-
VERSION_PER_EXECUTABLE
Cache of javac version per executable (never invalidated) -
inProcessCompiler
-
STACK_TRACE_FIRST_LINE
-
STACK_TRACE_OTHER_LINE
-
JAVAC_OR_JVM_ERROR
-
-
Constructor Details
-
JavacCompiler
public JavacCompiler()
-
-
Method Details
-
getCompilerId
- Specified by:
getCompilerIdin classAbstractCompiler
-
getInProcessJavacVersion
- Throws:
CompilerException
-
getOutOfProcessJavacVersion
- Throws:
CompilerException
-
extractMajorAndMinorVersion
-
performCompile
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
-
hasJavaxToolProvider
protected static boolean hasJavaxToolProvider()- Returns:
trueif the current context class loader has access tojavax.tools.ToolProvider
-
createCommandLine
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 String[] buildCompilerArguments(CompilerConfiguration config, String[] sourceFiles, String javacVersion) -
compileOutOfProcess
protected CompilerResult compileOutOfProcess(CompilerConfiguration config, String executable, 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(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(Class<?> javacClass, String[] args) throws CompilerException - Throws:
CompilerException
-
compileInProcess0
private static CompilerResult compileInProcess0(Class<?> javacClass, String[] args) throws CompilerException Helper method for compileInProcess()- Throws:
CompilerException
-
parseModernStream
static List<CompilerMessage> parseModernStream(int exitCode, BufferedReader input) throws 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:
IOException
-
isMisc
-
isNote
-
startsWithPrefix
-
parseModernError
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
-
createFileWithArguments
put 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:
IOException
-
getJavacExecutable
Get the path of the javac tool executable to use. Either given through explicit configuration or viagetJavacExecutable().- Parameters:
config- the configuration- Returns:
- the path of the javac tool
-
getJavacExecutable
Get 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 javac tool
- Throws:
IOException- if not found
-
releaseJavaccClass
-
getJavacClass
private 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
Helper method for create Javac class- Throws:
CompilerException
-