1 package org.ozoneDB.tools.OPP.compiler; 9 10 import java.util.Collection ; 11 import java.util.Arrays ; 12 import java.io.IOException ; 13 import java.io.InputStreamReader ; 14 import java.io.BufferedReader ; 15 import java.io.InputStream ; 16 17 20 public class ExternalJavaCompiler extends AbstractJavaCompiler { 21 22 private String compilerCommand; 23 24 27 public ExternalJavaCompiler(String compilerCommand) { 28 this.compilerCommand = compilerCommand; 29 } 30 31 36 public void compile(Collection classes) throws CompilerException { 37 String args[] = getArguments(compilerCommand, classes); 38 Process process = null; 39 try { 40 process = Runtime.getRuntime().exec(args); 41 process.waitFor(); 42 } catch (IOException e) { 43 throw new CompilerException("Failed to start compiler: " + e.getMessage(), args); 44 } catch (InterruptedException e) { 45 throw new CompilerException("Failed to start compiler: " + e.getMessage(), args); 46 } 47 if (process.exitValue() != 0) { 48 String output = streamToString(process.getInputStream()); 49 String error = streamToString(process.getErrorStream()); 50 51 System.out.println("Error running compiler: " + error); 53 System.out.println("compiling source " + getSourcePath() + " to " + getOutputPath()); 54 System.out.println("output: " + output); 55 System.out.println("args: " + Arrays.asList(args)); 56 throw new CompilerException("Failed to compile generated resolver", args); 57 } 58 } 59 60 private String streamToString(InputStream stream) { 61 BufferedReader reader = new BufferedReader (new InputStreamReader (stream)); 62 String result = null; 63 64 try { 65 String temp = reader.readLine(); 66 while (temp != null ) { 67 result += " " + temp; 68 temp = reader.readLine(); 69 } 70 } catch (IOException e) { 71 e.printStackTrace(); 72 } 73 return result; 74 } 75 } 76 | Popular Tags |