01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.components.language.programming.java;
18:
19: import net.sf.pizzacompiler.compiler.ClassReader;
20: import net.sf.pizzacompiler.compiler.FileCompilerOutput;
21: import net.sf.pizzacompiler.compiler.FileSourceReader;
22: import net.sf.pizzacompiler.compiler.Main;
23: import org.apache.cocoon.util.ClassUtils;
24: import org.apache.log.Hierarchy;
25:
26: import java.io.ByteArrayInputStream;
27: import java.io.ByteArrayOutputStream;
28: import java.io.File;
29: import java.io.IOException;
30: import java.io.PrintStream;
31:
32: /**
33: * This class wraps the Pizza Java Compiler.
34: *
35: * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
36: * @version CVS $Id: Pizza.java 433543 2006-08-22 06:22:54Z crossley $
37: * @deprecated Will be removed in 2.2
38: */
39: public class Pizza extends Javac {
40:
41: public final static String PIZZA_CLASS = "net.sf.pizzacompiler.compiler.Main";
42:
43: public Pizza() {
44: try {
45: ClassUtils.loadClass(PIZZA_CLASS);
46: } catch (ClassNotFoundException e) {
47: Hierarchy
48: .getDefaultHierarchy()
49: .getLoggerFor("cocoon")
50: .error(
51: "No Pizza Java compiler found in your classpath. Make sure you added 'pizza.jar'",
52: e);
53: throw new RuntimeException(
54: "No Pizza Java compiler found in your classpath. Make sure you added 'pizza.jar'");
55: }
56: net.sf.pizzacompiler.compiler.Main.init();
57: }
58:
59: /**
60: * Compile a source file yielding a loadable class file.
61: *
62: * @exception IOException
63: */
64: public boolean compile() throws IOException {
65:
66: ByteArrayOutputStream err = new ByteArrayOutputStream();
67:
68: Main.init();
69: Main.setClassReader(new ClassReader(this .classpath, null));
70: Main.argument("-java");
71: Main.argument("-O");
72: Main.argument("-nowarn");
73: Main.compile(new String[] { file }, new FileSourceReader(),
74: new FileCompilerOutput(new File(destDir)),
75: new PrintStream(err));
76:
77: this .errors = new ByteArrayInputStream(err.toByteArray());
78: return err.size() == 0;
79: }
80:
81: public String toString() {
82: return "Pizza Java Compiler";
83: }
84: }
|