/** * Run the compilation. * @return true if the compiler ran with a zero exit result (ok) * @exception BuildException if the compilation has problems. */ @Override public boolean execute() throws BuildException { attributes.log("Using modern compiler", Project.MSG_VERBOSE); Commandline cmd = setupModernJavacCommand(); // Use reflection to be able to build on all JDKs >= 1.1: try { Class<?> c = Class.forName("com.sun.tools.javac.Main"); Object compiler = c.newInstance(); Method compile = c.getMethod("compile", String[].class); int result = (Integer) compile.invoke(compiler, (Object) cmd.getArguments()); return result == MODERN_COMPILER_SUCCESS; } catch (Exception ex) { if (ex instanceof BuildException) { throw (BuildException) ex; } throw new BuildException("Error starting modern compiler", ex, location); } } }
return new Javac13();