1 18 19 package org.apache.tools.ant.taskdefs.compilers; 20 21 import java.lang.reflect.Method ; 22 import org.apache.tools.ant.BuildException; 23 import org.apache.tools.ant.Project; 24 import org.apache.tools.ant.types.Commandline; 25 26 27 34 public class Javac13 extends DefaultCompilerAdapter { 35 36 39 private static final int MODERN_COMPILER_SUCCESS = 0; 40 41 46 public boolean execute() throws BuildException { 47 attributes.log("Using modern compiler", Project.MSG_VERBOSE); 48 Commandline cmd = setupModernJavacCommand(); 49 50 try { 52 Class c = Class.forName ("com.sun.tools.javac.Main"); 53 Object compiler = c.newInstance (); 54 Method compile = c.getMethod ("compile", 55 new Class [] {(new String [] {}).getClass ()}); 56 int result = ((Integer ) compile.invoke 57 (compiler, new Object [] {cmd.getArguments()})) 58 .intValue (); 59 return (result == MODERN_COMPILER_SUCCESS); 60 } catch (Exception ex) { 61 if (ex instanceof BuildException) { 62 throw (BuildException) ex; 63 } else { 64 throw new BuildException("Error starting modern compiler", 65 ex, location); 66 } 67 } 68 } 69 } 70 | Popular Tags |