1 23 24 package org.enhydra.xml.xmlc.codegen; 25 26 import java.io.PrintWriter ; 27 import java.util.ArrayList ; 28 29 import org.enhydra.xml.io.ErrorReporter; 30 import org.enhydra.xml.xmlc.XMLCException; 31 import org.enhydra.xml.xmlc.misc.ProcessRunner; 32 33 34 36 39 public class JavaCompile extends ProcessRunner { 40 43 private static final int DEFAULT_OPTIONS = PASS_STDOUT|PASS_STDERR; 44 45 48 private static final String DEFAULT_JAVAC = "javac"; 49 50 53 private ErrorReporter fErrorReporter; 54 55 58 private String fJavac; 59 60 63 private String fClassOutputRoot; 64 65 68 private ArrayList fArgs = new ArrayList (); 69 70 73 private ArrayList fSrcs = new ArrayList (); 74 75 78 public JavaCompile(ErrorReporter errorReporter, 79 String javac) { 80 super(DEFAULT_OPTIONS); 81 fErrorReporter = errorReporter; 82 if (javac != null) { 83 fJavac = javac; 84 } else { 85 fJavac = DEFAULT_JAVAC; 86 } 87 } 88 89 92 public void setClassOutputRoot(String root) { 93 fClassOutputRoot = root; 94 } 95 96 99 public void addArg(String arg) { 100 fArgs.add(arg); 101 } 102 103 106 public void addArg(String arg, 107 String value) { 108 fArgs.add(arg); 109 fArgs.add(value); 110 } 111 112 115 public void addArgs(String [] args) { 116 for (int i = 0; i < args.length; i++) { 117 fArgs.add(args[i]); 118 } 119 } 120 121 124 public void addSrc(String srcFile) { 125 fSrcs.add(srcFile); 126 } 127 128 136 public void compile(PrintWriter verboseOut) throws XMLCException { 137 ArrayList cmd = new ArrayList (); 138 cmd.add(fJavac); 139 if (fClassOutputRoot != null) { 140 cmd.add("-d"); 141 cmd.add(fClassOutputRoot); 142 } 143 cmd.addAll(fArgs); 144 cmd.addAll(fSrcs); 145 run((String [])cmd.toArray(new String [cmd.size()]), 147 fErrorReporter, verboseOut, 148 "compile of generated java code failed"); 149 } 150 } 151 | Popular Tags |