Initial Commit
[packages] / xemacs-packages / jde / java / src / jde / util / AntServer.java
1 /*
2  * $Id: AntServer.java,v 1.4 2002/02/15 14:05:14 jslopez Exp $
3  */
4 /*
5  *    AntServer.java
6  *    Copyright (C) 2001 Javier Lopez (jslopez@alum.mit.edu)
7  *
8  *    $Revision: 1.4 $
9  *
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.
14  *
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.
19  *
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.
23  */
24 package jde.util;
25
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;
32
33 /**
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
38  * of java.exe
39  *
40  * Created: Sun Aug 12 21:56:50 2001
41  *
42  * @author <a href="mailto:jslopez@alum.mit.edu"></a>
43  * @version 1.0
44  * @since jde-2.2.9beta5
45  */
46 public class AntServer {
47     
48     private static Class ant;
49     static {
50         try {
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.");
56         }
57     }
58     
59     private static Method m;
60     static {
61         try {
62             if (ant != null) {
63                 Class[] params = new Class[] {String[].class};
64                 m = ant.getMethod("main", params);
65             }
66         } catch (NoSuchMethodException e) {
67         } catch (SecurityException e) {
68         }
69     
70     }
71     public static void start(String command) {
72         SecurityManager sm = System.getSecurityManager();
73         if (sm == null) {
74             System.setSecurityManager(new JDESecurityManager());
75         }
76         
77         //Parsing commands
78         StringTokenizer st = new StringTokenizer(command);
79         String[] args = new String[st.countTokens()];
80         
81         for (int i = 0; st.hasMoreTokens(); i++) { //Fetching the array 
82             args[i] = st.nextToken();
83         }
84         try {
85             if (m != null) {
86                 Object[] arguments = new Object[] {args};
87                 m.invoke(ant, arguments);
88             }
89         } catch (InvocationTargetException e) {
90         } catch (IllegalAccessException e) {
91         } catch (SecurityException e) {
92         }
93     }
94     
95     public static void main (String[] args) {
96         AntServer.start("-buildfile c:/cygwin/home/jslopez/code/dev/build.xml");
97     }
98 }// AntServer
99
100 /*
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.
104  *
105  * Revision 1.3  2001/11/08 12:45:10  paulk
106  * Updated to support Ant.
107  *
108  * Revision 1.2  2001/11/05 14:10:30  jslopez
109  * Modified the code to depend only indirectly
110  * on ant.jar.
111  *
112  * Revision 1.1  2001/11/05 01:32:49  jslopez
113  * Initial development.
114  *
115  */