KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > debugger > ide > IDEDebugger


1 /* -*- Mode: JDE; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the debugger and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  */

22 package org.aspectj.debugger.ide;
23
24 import java.io.File JavaDoc;
25
26 import org.aspectj.debugger.base.Options;
27 import org.aspectj.debugger.base.Debugger;
28 import org.aspectj.debugger.base.AJDebugger;
29 import org.aspectj.debugger.base.Modes;
30 import org.aspectj.debugger.gui.ComponentDirector;
31
32 /**
33  * The main class to use to launch a debugger in an IDE.
34  * To use correctly call the 'launch' method with the proper args.
35  *
36  * @see #launch
37  **/

38 public class IDEDebugger {
39
40     /** The main app. */
41     public static ComponentDirector director;
42
43     /** The name of the main class to launch. */
44     private String JavaDoc mainClass;
45
46     /** The source path to use in the debugger. */
47     private String JavaDoc sourcePath;
48
49     /** The classpath to use in the debugger. */
50     private String JavaDoc classPath;
51
52     /** The workingdir to use in the debugger. */
53     private String JavaDoc workingdir;
54
55     /**
56      * The mode we're in, this has to be one of:
57      * - Modes.FORTE
58      * - Modes.JBUILDER
59      * - Modes.JBUILDER3
60      * - Modes.JBUILDER4
61      * - Modes.GUI
62      *
63      * @see org.aspectj.debugger.base.Modes
64      * @see org.aspectj.debugger.base.Modes.FORTE
65      * @see org.aspectj.debugger.base.Modes.JBUILDER
66      * @see org.aspectj.debugger.base.Modes.JBUILDER3
67      * @see org.aspectj.debugger.base.Modes.JBUILDER4
68      * @see org.aspectj.debugger.base.Modes.GUI
69      */

70     private String JavaDoc mode;
71
72     /** Args to pass to the running debugger. */
73     private String JavaDoc[] args;
74
75     /**
76      * Launch a debugger. Will only allow one.
77      *
78      * @param mainClass The class whose 'main' method will be debugged.
79      * @param sourcePath The source path to use in the debugger.
80      * @param classPath The classpath to use in the debugger.
81      * @param mode The mode we're in, see the docs for the 'String' mode.
82      * @param args VM args to give the running application in the debugger.
83      * @param shower The 'SourceShower' to give the debugger.
84      * @param ide The 'IDEInterface' to give the component director.
85      * @see org.aspectj.debugger.base.Modes
86      * @see org.aspectj.debugger.ide.SourceShower
87      **/

88     public static void launch(String JavaDoc mainClass,
89                               String JavaDoc sourcePath,
90                               String JavaDoc classPath,
91                               String JavaDoc workingdir,
92                               String JavaDoc mode,
93                               String JavaDoc[] args,
94                               SourceShower shower,
95                               IDEInterface ide) {
96         new IDEDebugger(mainClass, sourcePath, classPath, workingdir, mode, args, shower, ide).go();
97     }
98
99     //XXX temp
100
public static void launch(String JavaDoc mainClass,
101                               String JavaDoc sourcePath,
102                               String JavaDoc classPath,
103                               String JavaDoc mode,
104                               String JavaDoc[] args,
105                               SourceShower shower,
106                               IDEInterface ide) {
107         new IDEDebugger(mainClass, sourcePath, classPath, null, mode, args, shower, ide).go();
108     }
109
110     private IDEDebugger(String JavaDoc mainClass,
111                         String JavaDoc sourcePath,
112                         String JavaDoc classPath,
113                         String JavaDoc workingdir,
114                         String JavaDoc mode,
115                         String JavaDoc[] args,
116                         SourceShower sourceShower,
117                         IDEInterface ide) {
118         this.mainClass = mainClass;
119         this.sourcePath = sourcePath;
120         this.classPath = classPath;
121         this.workingdir = workingdir;
122         this.mode = mode;
123         this.args = args;
124         if (ide == null) {
125             ide = new IDEInterfaceImpl();
126         }
127 // if (mode.equals(Modes.FORTE)) {
128
// ide.setComponentDirector(director = new ForteDebuggerFrame(args, sourceShower, ide));
129
// } else if (mode.equals(Modes.JBUILDER4) ||
130
// mode.equals(Modes.JBUILDER3)) {
131
// ide.setComponentDirector(director = new JBuilder4DebuggerFrame(args, sourceShower, ide));
132
// } else {
133
// System.err.println("Invalid mode: " + mode);
134
// }
135
}
136
137     private void go() {
138         director.go();
139         Debugger debugger = director.getGUIDebugger().getDebugger();
140         Options options = debugger.getOptions();
141         if (check(classPath)) options.setClassPath(classPath);
142         if (check(sourcePath)) options.setSourcePath(sourcePath);
143         if (check(mainClass)) options.setMainClass(mainClass);
144         debugger.setOptions(options);
145         //XXX This sucks!!!
146
debugger.execute("use " + debugger.getSourcePath());
147         if (check(workingdir)) {
148             debugger.execute("workingdir " + workingdir);
149         }
150 // File workingdir = ((AJDebugger)debugger).getWorkingdir();
151
// if (workingdir != null) {
152
// debugger.execute("workingdir " + workingdir.getAbsolutePath());
153
// }
154
if (director instanceof IDEComponentDirector) {
155             ((IDEComponentDirector)director).finishUp();
156         }
157         try {
158             if (check(mainClass)) debugger.run(mainClass, args);
159         } catch (Throwable JavaDoc t) {
160             org.aspectj.debugger.base.ErrorLogger.error(t);
161         }
162     }
163
164     private boolean check(String JavaDoc str) {
165         return str != null && str.length() > 0;
166     }
167 }
168
Popular Tags