01: /*
02: * Copyright 2004,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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:
17: package org.apache.bsf.util;
18:
19: import java.io.IOException;
20:
21: import org.apache.commons.logging.Log;
22: import org.apache.commons.logging.LogFactory;
23:
24: public class JavaUtils {
25: // Temporarily copied from JavaEngine...
26:
27: private static Log logger;
28:
29: static {
30: logger = LogFactory
31: .getLog((org.apache.bsf.util.JavaUtils.class).getName());
32: }
33:
34: public static boolean JDKcompile(String fileName, String classPath) {
35: String option = (logger.isDebugEnabled()) ? "-g" : "-O";
36: String args[] = { "javac", option, "-classpath", classPath,
37: fileName };
38:
39: logger.debug("JavaEngine: Compiling " + fileName);
40: logger.debug("JavaEngine: Classpath is " + classPath);
41:
42: try {
43: Process p = java.lang.Runtime.getRuntime().exec(args);
44: p.waitFor();
45: return (p.exitValue() != 0);
46: } catch (IOException e) {
47: logger.error("ERROR: IO exception during exec(javac).", e);
48: } catch (SecurityException e) {
49: logger
50: .error(
51: "ERROR: Unable to create subprocess to exec(javac).",
52: e);
53: } catch (InterruptedException e) {
54: logger.error(
55: "ERROR: Wait for exec(javac) was interrupted.", e);
56: }
57: return false;
58: }
59: }
|