KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > language > programming > java > Pizza


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 JavaDoc;
26 import java.io.ByteArrayOutputStream JavaDoc;
27 import java.io.File JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.io.PrintStream JavaDoc;
30
31 /**
32  * This class wraps the Pizza Java Compiler.
33  *
34  * @author <a HREF="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
35  * @version CVS $Id: Pizza.java 156603 2005-03-09 04:00:17Z antonio $
36  * @deprecated Will be removed in 2.2
37  */

38 public class Pizza extends Javac {
39
40     public final static String JavaDoc PIZZA_CLASS = "net.sf.pizzacompiler.compiler.Main";
41
42     public Pizza() {
43         try {
44             ClassUtils.loadClass(PIZZA_CLASS);
45         } catch (ClassNotFoundException JavaDoc 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 JavaDoc("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     /**
53      * Compile a source file yielding a loadable class file.
54      *
55      * @exception IOException
56      */

57     public boolean compile() throws IOException JavaDoc {
58
59         ByteArrayOutputStream JavaDoc err = new ByteArrayOutputStream JavaDoc();
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 JavaDoc[]{file},
67                 new FileSourceReader(),
68                 new FileCompilerOutput(new File JavaDoc(destDir)),
69                 new PrintStream JavaDoc(err));
70
71         this.errors = new ByteArrayInputStream JavaDoc(err.toByteArray());
72         return err.size() == 0;
73     }
74
75     public String JavaDoc toString() {
76         return "Pizza Java Compiler";
77     }
78 }
79
Popular Tags