*/
public boolean execute() throws BuildException {
attributes.log("Using classic compiler", Project.MSG_VERBOSE);
Commandline cmd = setupJavacCommand(true);
OutputStream logstr = new LogOutputStream(attributes, Project.MSG_WARN);
try {
// Create an instance of the compiler, redirecting output to
// the project log
Class c = Class.forName("sun.tools.javac.Main");
Constructor cons =
c.getConstructor(new Class[] { OutputStream.class,
String.class });
Object compiler = cons.newInstance(new Object[] { logstr,
"javac" });
// Call the compile() method
Method compile = c.getMethod("compile",
new Class [] { String[].class });
Boolean ok =
(Boolean) compile.invoke(compiler,
new Object[] {cmd.getArguments()});
return ok.booleanValue();
} catch (ClassNotFoundException ex) {
throw new BuildException("Cannot use classic compiler, as it is "
+ "not available. A common solution is "
+ "to set the environment variable"
+ " JAVA_HOME to your jdk directory.",
location);
} catch (Exception ex) {
if (ex instanceof BuildException) {
throw (BuildException) ex;
} else {
throw new BuildException("Error starting classic compiler: ",
ex, location);
}
} finally {
try {
logstr.close();
} catch (IOException e) {
// plain impossible
throw new BuildException(e);
}
}