1 23 24 package org.enhydra.xml.xmlc.compiler; 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.codegen.JavaCompile; 32 import org.enhydra.xml.xmlc.metadata.DocumentClass; 33 import org.enhydra.xml.xmlc.metadata.GenerateType; 34 import org.enhydra.xml.xmlc.metadata.JavaCompilerSection; 35 import org.enhydra.xml.xmlc.metadata.MetaData; 36 37 40 public class Javac { 41 42 private boolean fThrowErrorMsgs; 43 44 45 48 public void setThrowErrorMsgs(boolean enable) { 49 fThrowErrorMsgs = enable; 50 } 51 52 60 public void compile(MetaData metaData, 61 ErrorReporter errorReporter, 62 PrintWriter verboseOut) 63 throws XMLCException { 64 65 DocumentClass documentClass = metaData.getDocumentClass(); 66 GenerateType generate = documentClass.getGenerate(); 67 JavaCompilerSection compilerSection = metaData.getJavaCompilerSection(); 68 69 String classOutputRoot = metaData.getCompileOptions().getClassOutputRoot(); 70 ArrayList cmd = new ArrayList (); 71 72 JavaCompile compile = new JavaCompile(errorReporter, 73 compilerSection.getJavac()); 74 75 if (fThrowErrorMsgs) { 76 compile.setOptions(JavaCompile.COLLECT_STDOUT 77 |JavaCompile.COLLECT_STDERR 78 |JavaCompile.DUMP_STDERR_ON_FAIL); 79 } 80 if (classOutputRoot != null) { 81 compile.setClassOutputRoot(classOutputRoot); 82 } 83 compile.addArgs(compilerSection.getJavacArgs()); 84 85 compile.addArg("-encoding", "ISO-8859-1"); 86 if (generate.generateClass()) { 87 compile.addSrc(documentClass.getJavaClassSource().getPath()); 88 } 89 if (generate.generateInterface()) { 90 compile.addSrc(documentClass.getJavaInterfaceSource().getPath()); 91 } 92 compile.compile(verboseOut); 93 } 94 } 95 | Popular Tags |