1 16 package org.apache.cocoon.components.language.programming.java; 17 18 import net.sf.pizzacompiler.compiler.ClassReader; 19 import net.sf.pizzacompiler.compiler.FileCompilerOutput; 20 import net.sf.pizzacompiler.compiler.FileSourceReader; 21 import net.sf.pizzacompiler.compiler.Main; 22 import org.apache.cocoon.util.ClassUtils; 23 import org.apache.log.Hierarchy; 24 25 import java.io.ByteArrayInputStream ; 26 import java.io.ByteArrayOutputStream ; 27 import java.io.File ; 28 import java.io.IOException ; 29 import java.io.PrintStream ; 30 31 38 public class Pizza extends Javac { 39 40 public final static String PIZZA_CLASS = "net.sf.pizzacompiler.compiler.Main"; 41 42 public Pizza() { 43 try { 44 ClassUtils.loadClass(PIZZA_CLASS); 45 } catch (ClassNotFoundException e) { 46 Hierarchy.getDefaultHierarchy().getLoggerFor("cocoon").error("No Pizza Java compiler found in your classpath. Make sure you added 'pizza.jar'", e); 47 throw new RuntimeException ("No Pizza Java compiler found in your classpath. Make sure you added 'pizza.jar'"); 48 } 49 net.sf.pizzacompiler.compiler.Main.init(); 50 } 51 52 57 public boolean compile() throws IOException { 58 59 ByteArrayOutputStream err = new ByteArrayOutputStream (); 60 61 Main.init(); 62 Main.setClassReader(new ClassReader(this.classpath, null)); 63 Main.argument("-java"); 64 Main.argument("-O"); 65 Main.argument("-nowarn"); 66 Main.compile(new String []{file}, 67 new FileSourceReader(), 68 new FileCompilerOutput(new File (destDir)), 69 new PrintStream (err)); 70 71 this.errors = new ByteArrayInputStream (err.toByteArray()); 72 return err.size() == 0; 73 } 74 75 public String toString() { 76 return "Pizza Java Compiler"; 77 } 78 } 79 | Popular Tags |