3 * Copyright (C) 2001 Javier Lopez (jslopez@alum.mit.edu)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 import java.util.StringTokenizer;
25 import java.lang.reflect.Method;
26 import java.lang.reflect.InvocationTargetException;
29 * CompileServer.java provides an interface between
30 * the command line(or from Emacs) and the javac compiler.
31 * @see com.sun.tools.javac.main
32 * Calling the compile server instead of doing javac will
33 * avoid the start up time that occur with every incovation
36 * Created: Sun Aug 12 21:56:50 2001
38 * @author <a href="mailto:jslopez@alum.mit.edu"></a>
40 * @since jde-2.2.8beta5
42 public class CompileServer {
43 private static Class compiler;
46 compiler = Class.forName("com.sun.tools.javac.Main");
47 } catch (ClassNotFoundException e) {
52 private static Method compile;
55 if (compiler != null) {
56 Class[] params = new Class[] {String[].class};
57 compile = compiler.getMethod("compile", params);
59 } catch (NoSuchMethodException e) {
61 } catch (SecurityException e) {
68 * @param args a <code>String[]</code> with
69 * the arguments to passed to compiler.
70 * @see com.sun.tools.javac.Main#compiler(String[] args)
72 public static void compile(String[] args) {
74 if (compile != null) {
75 Object[] arguments = new Object[] {args};
76 System.out.println(compile.invoke(compiler.newInstance(), arguments));
78 } catch (InstantiationException e) {
80 } catch (InvocationTargetException e) {
82 } catch (IllegalAccessException e) {
84 } catch (IllegalArgumentException e) {
91 * @param commands a <code>String[]</code> with
92 * the arguments to passed to compiler.
93 * @see com.sun.tools.javac.Main#compiler(String[] args)
95 public static void compile(String commands) {
97 StringTokenizer st = new StringTokenizer(commands);
98 String[] args = new String[st.countTokens()];
100 for (int i = 0; st.hasMoreTokens(); i++) { //Fetching the array
101 args[i] = st.nextToken();
106 public static void main (String[] args) {
107 CompileServer.compile("CompileServer.java");
112 * $Log: CompileServer.java,v $
113 * Revision 1.7 2001/11/21 15:45:34 jslopez
114 * Fixes causing a compilation error when using
117 * Revision 1.6 2001/11/21 07:07:00 paulk
120 * Revision 1.5 2001/11/18 03:08:17 jslopez
121 * Modifies the code to use reflection to
122 * get a handle on the Main compiler. This
123 * will avoid IncompatibleClassChangeError.
125 * Revision 1.4 2001/11/12 13:06:45 jslopez
126 * Removing control characters from the end of the lines.
128 * Revision 1.3 2001/10/17 04:15:30 paulk
129 * Added change log at the end of the file.
134 // End of CompileServer.java