String message = "Unable to locate the Javac Compiler in:" + EOL + " " + toolsJar + EOL
+ "Please ensure you are using JDK 1.4 or above and" + EOL
+ "not a JRE (the com.sun.tools.javac.Main class is required)." + EOL
+ "In most cases you can change the location of your Java" + EOL
+ "installation by setting the JAVA_HOME environment variable.";
return Collections.singletonList( new CompilerError( message, true ) );
}
StringWriter out = new StringWriter();
Integer ok;
List messages;
try
{
Method compile = c.getMethod( "compile", new Class[] { String[].class, PrintWriter.class } );
ok = (Integer) compile.invoke( null, new Object[] { args, new PrintWriter( out ) } );
messages = parseModernStream( new BufferedReader( new StringReader( out.toString() ) ) );
}
catch ( NoSuchMethodException e )
{
throw new CompilerException( "Error while executing the compiler.", e );
}
catch ( IllegalAccessException e )
{
throw new CompilerException( "Error while executing the compiler.", e );
}
catch ( InvocationTargetException e )
{
throw new CompilerException( "Error while executing the compiler.", e );
}
catch ( IOException e )
{
throw new CompilerException( "Error while executing the compiler.", e );
}
if ( ok.intValue() != 0 && messages.isEmpty() )
{
// TODO: exception?
messages.add( new CompilerError( "Failure executing javac, but could not parse the error:" + EOL +
out.toString(), true ) );
}
return messages;
}