1 28 package net.sf.jasperreports.engine.design; 29 30 import java.io.ByteArrayOutputStream ; 31 import java.io.File ; 32 import java.io.InputStream ; 33 34 import net.sf.jasperreports.engine.JRException; 35 36 37 41 public class JRJikesCompiler extends JRAbstractMultiClassCompiler 42 { 43 44 45 48 public String compileClasses(File [] sourceFiles, String classpath) throws JRException 49 { 50 String [] source = new String [sourceFiles.length + 3]; 51 source[0] = "jikes"; 52 source[1] = "-classpath"; 53 source[2] = classpath; 54 for (int i = 0; i < sourceFiles.length; i++) 55 { 56 source[i + 3] = sourceFiles[i].getPath(); 57 } 58 59 try 60 { 61 Process compile = Runtime.getRuntime().exec(source); 63 InputStream errFile = compile.getErrorStream(); 64 65 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 67 byte[] buffer = new byte[1024]; 68 int count = 0; 69 do 70 { 71 count = errFile.read(buffer); 72 if (count > 0) 73 { 74 baos.write(buffer, 0, count); 75 } 76 } while (count >= 0); 77 78 if( baos.toString().indexOf("error") != -1 ) 79 { 80 return baos.toString(); 81 } 82 83 return null; 84 } 85 catch (Exception e) 86 { 87 StringBuffer files = new StringBuffer (); 88 for (int i = 0; i < sourceFiles.length; ++i) 89 { 90 files.append(sourceFiles[i].getPath()); 91 files.append(' '); 92 } 93 throw new JRException("Error compiling report java source files : " + files, e); 94 } 95 } 96 97 98 } 99 | Popular Tags |