static CompilerResult compileInProcess( String[] args, final CompilerConfiguration config,
String[] sourceFiles )
throws CompilerException
{
JavaCompiler compiler = getJavaCompiler( config );
try
{
if ( compiler == null )
{
CompilerMessage message =
new CompilerMessage( "No compiler is provided in this environment. "
+ "Perhaps you are running on a JRE rather than a JDK?",
CompilerMessage.Kind.ERROR );
return new CompilerResult( false, Collections.singletonList( message ) );
}
final String sourceEncoding = config.getSourceEncoding();
final Charset sourceCharset = sourceEncoding == null ? null : Charset.forName( sourceEncoding );
final DiagnosticCollector<JavaFileObject> collector = new DiagnosticCollector<JavaFileObject>();
final StandardJavaFileManager standardFileManager =
compiler.getStandardFileManager( collector, null, sourceCharset );
final Iterable<? extends JavaFileObject> fileObjects =
standardFileManager.getJavaFileObjectsFromStrings( Arrays.asList( sourceFiles ) );
final JavaCompiler.CompilationTask task =
/*(Writer out,
JavaFileManager fileManager,
DiagnosticListener<? super JavaFileObject> diagnosticListener,
Iterable<String> options,
Iterable<String> classes,
Iterable<? extends JavaFileObject> compilationUnits)*/
compiler.getTask( null, standardFileManager, collector, Arrays.asList( args ), null, fileObjects );
final Boolean result = task.call();
final ArrayList<CompilerMessage> compilerMsgs = new ArrayList<CompilerMessage>();
for ( Diagnostic<? extends JavaFileObject> diagnostic : collector.getDiagnostics() )
{
CompilerMessage.Kind kind;