2 * $Id: AntServer.java,v 1.4 2002/02/15 14:05:14 jslopez Exp $
6 * Copyright (C) 2001 Javier Lopez (jslopez@alum.mit.edu)
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 import java.lang.ClassNotFoundException;
27 import java.lang.IllegalAccessException;
28 import java.lang.NoSuchMethodException;
29 import java.lang.reflect.InvocationTargetException;
30 import java.lang.reflect.Method;
31 import java.util.StringTokenizer;
34 * AntServer.java provides an interface between
35 * the command line(or from Emacs) and the ant executable.
36 * Calling the ant server instead of running the ant script will
37 * avoid the start up time that occur with every incovation
40 * Created: Sun Aug 12 21:56:50 2001
42 * @author <a href="mailto:jslopez@alum.mit.edu"></a>
44 * @since jde-2.2.9beta5
46 public class AntServer {
48 private static Class ant;
51 ant = ant.forName("org.apache.tools.ant.Main");
52 } catch (ClassNotFoundException e) {
53 System.out.println("You need ant.jar in the beanshell classpath.");
54 System.out.println("The beanshell uses jde-global-classpath or ");
55 System.out.println("the environment variable CLASSPATH.");
59 private static Method m;
63 Class[] params = new Class[] {String[].class};
64 m = ant.getMethod("main", params);
66 } catch (NoSuchMethodException e) {
67 } catch (SecurityException e) {
71 public static void start(String command) {
72 SecurityManager sm = System.getSecurityManager();
74 System.setSecurityManager(new JDESecurityManager());
78 StringTokenizer st = new StringTokenizer(command);
79 String[] args = new String[st.countTokens()];
81 for (int i = 0; st.hasMoreTokens(); i++) { //Fetching the array
82 args[i] = st.nextToken();
86 Object[] arguments = new Object[] {args};
87 m.invoke(ant, arguments);
89 } catch (InvocationTargetException e) {
90 } catch (IllegalAccessException e) {
91 } catch (SecurityException e) {
95 public static void main (String[] args) {
96 AntServer.start("-buildfile c:/cygwin/home/jslopez/code/dev/build.xml");
101 * $Log: AntServer.java,v $
102 * Revision 1.4 2002/02/15 14:05:14 jslopez
103 * Adds an error when the ant class is not found.
105 * Revision 1.3 2001/11/08 12:45:10 paulk
106 * Updated to support Ant.
108 * Revision 1.2 2001/11/05 14:10:30 jslopez
109 * Modified the code to depend only indirectly
112 * Revision 1.1 2001/11/05 01:32:49 jslopez
113 * Initial development.