1 18 19 package org.apache.tools.ant.taskdefs.rmic; 20 21 import java.io.IOException ; 22 import java.io.OutputStream ; 23 import java.lang.reflect.Constructor ; 24 import java.lang.reflect.Method ; 25 import org.apache.tools.ant.BuildException; 26 import org.apache.tools.ant.Project; 27 import org.apache.tools.ant.taskdefs.LogOutputStream; 28 import org.apache.tools.ant.types.Commandline; 29 30 35 public class SunRmic extends DefaultRmicAdapter { 36 37 40 public static final String RMIC_CLASSNAME = "sun.rmi.rmic.Main"; 41 42 45 public static final String COMPILER_NAME = "sun"; 46 47 50 public static final String RMIC_EXECUTABLE = "rmic"; 51 52 public static final String ERROR_NO_RMIC_ON_CLASSPATH = "Cannot use SUN rmic, as it is not " 53 + "available. A common solution is to " 54 + "set the environment variable " 55 + "JAVA_HOME or CLASSPATH."; 56 57 public static final String ERROR_RMIC_FAILED = "Error starting SUN rmic: "; 58 59 64 public boolean execute() throws BuildException { 65 getRmic().log("Using SUN rmic compiler", Project.MSG_VERBOSE); 66 Commandline cmd = setupRmicCommand(); 67 68 LogOutputStream logstr = new LogOutputStream(getRmic(), 71 Project.MSG_WARN); 72 73 try { 74 Class c = Class.forName(RMIC_CLASSNAME); 75 Constructor cons 76 = c.getConstructor(new Class [] {OutputStream .class, String .class}); 77 Object rmic = cons.newInstance(new Object [] {logstr, "rmic"}); 78 79 Method doRmic = c.getMethod("compile", 80 new Class [] {String [].class}); 81 Boolean ok = 82 (Boolean ) doRmic.invoke(rmic, 83 (new Object [] {cmd.getArguments()})); 84 return ok.booleanValue(); 85 } catch (ClassNotFoundException ex) { 86 throw new BuildException(ERROR_NO_RMIC_ON_CLASSPATH, 87 getRmic().getLocation()); 88 } catch (Exception ex) { 89 if (ex instanceof BuildException) { 90 throw (BuildException) ex; 91 } else { 92 throw new BuildException(ERROR_RMIC_FAILED, 93 ex, getRmic().getLocation()); 94 } 95 } finally { 96 try { 97 logstr.close(); 98 } catch (IOException e) { 99 throw new BuildException(e); 100 } 101 } 102 } 103 } 104 | Popular Tags |