|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| package edu.rice.cs.drjava.model; |
|
38 |
| |
|
39 |
| |
|
40 |
| import java.awt.EventQueue; |
|
41 |
| |
|
42 |
| import java.io.*; |
|
43 |
| |
|
44 |
| import java.util.LinkedList; |
|
45 |
| import java.util.List; |
|
46 |
| import java.util.Vector; |
|
47 |
| import java.util.Map; |
|
48 |
| import java.util.TreeMap; |
|
49 |
| |
|
50 |
| import edu.rice.cs.drjava.DrJava; |
|
51 |
| |
|
52 |
| import edu.rice.cs.drjava.model.FileSaveSelector; |
|
53 |
| import edu.rice.cs.drjava.model.compiler.DummyCompilerListener; |
|
54 |
| import edu.rice.cs.drjava.config.BooleanOption; |
|
55 |
| import edu.rice.cs.drjava.model.definitions.ClassNameNotFoundException; |
|
56 |
| import edu.rice.cs.drjava.model.definitions.InvalidPackageException; |
|
57 |
| import edu.rice.cs.drjava.model.debug.Breakpoint; |
|
58 |
| import edu.rice.cs.drjava.model.debug.Debugger; |
|
59 |
| import edu.rice.cs.drjava.model.debug.DebugException; |
|
60 |
| import edu.rice.cs.drjava.model.debug.NoDebuggerAvailable; |
|
61 |
| import edu.rice.cs.drjava.model.debug.DebugListener; |
|
62 |
| import edu.rice.cs.drjava.model.debug.DebugWatchData; |
|
63 |
| import edu.rice.cs.drjava.model.debug.DebugThreadData; |
|
64 |
| import edu.rice.cs.drjava.model.javadoc.JavadocModel; |
|
65 |
| import edu.rice.cs.drjava.model.javadoc.NoJavadocAvailable; |
|
66 |
| import edu.rice.cs.drjava.model.repl.DefaultInteractionsModel; |
|
67 |
| import edu.rice.cs.drjava.model.repl.DummyInteractionsListener; |
|
68 |
| import edu.rice.cs.drjava.model.repl.InteractionsDocument; |
|
69 |
| import edu.rice.cs.drjava.model.repl.InteractionsDJDocument; |
|
70 |
| import edu.rice.cs.drjava.model.repl.InteractionsListener; |
|
71 |
| import edu.rice.cs.drjava.model.repl.InteractionsScriptModel; |
|
72 |
| import edu.rice.cs.drjava.model.repl.newjvm.MainJVM; |
|
73 |
| import edu.rice.cs.drjava.model.compiler.CompilerListener; |
|
74 |
| import edu.rice.cs.drjava.model.compiler.CompilerModel; |
|
75 |
| import edu.rice.cs.drjava.model.compiler.DefaultCompilerModel; |
|
76 |
| import edu.rice.cs.drjava.model.compiler.CompilerInterface; |
|
77 |
| import edu.rice.cs.drjava.model.junit.DefaultJUnitModel; |
|
78 |
| import edu.rice.cs.drjava.model.junit.JUnitModel; |
|
79 |
| import edu.rice.cs.util.text.ConsoleDocument; |
|
80 |
| |
|
81 |
| import edu.rice.cs.plt.reflect.JavaVersion; |
|
82 |
| import edu.rice.cs.plt.reflect.ReflectUtil; |
|
83 |
| import edu.rice.cs.plt.iter.IterUtil; |
|
84 |
| import edu.rice.cs.plt.io.IOUtil; |
|
85 |
| import edu.rice.cs.plt.tuple.Pair; |
|
86 |
| |
|
87 |
| import edu.rice.cs.util.FileOpenSelector; |
|
88 |
| import edu.rice.cs.util.FileOps; |
|
89 |
| import edu.rice.cs.util.NullFile; |
|
90 |
| import edu.rice.cs.util.AbsRelFile; |
|
91 |
| import edu.rice.cs.util.OperationCanceledException; |
|
92 |
| import edu.rice.cs.util.UnexpectedException; |
|
93 |
| import edu.rice.cs.util.swing.Utilities; |
|
94 |
| |
|
95 |
| import static edu.rice.cs.plt.debug.DebugUtil.debug; |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
| |
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
| public class DefaultGlobalModel extends AbstractGlobalModel { |
|
104 |
| |
|
105 |
| |
|
106 |
| |
|
107 |
| |
|
108 |
| |
|
109 |
| |
|
110 |
| |
|
111 |
| protected final InteractionsDJDocument _interactionsDocument; |
|
112 |
| |
|
113 |
| |
|
114 |
| final MainJVM _jvm; |
|
115 |
| |
|
116 |
| private final Thread _jvmStarter; |
|
117 |
| |
|
118 |
| |
|
119 |
| protected final DefaultInteractionsModel _interactionsModel; |
|
120 |
| |
|
121 |
| |
|
122 |
| protected InteractionsListener _interactionsListener = new InteractionsListener() { |
|
123 |
35
| public void interactionStarted() { }
|
|
124 |
| |
|
125 |
33
| public void interactionEnded() { }
|
|
126 |
| |
|
127 |
0
| public void interactionErrorOccurred(int offset, int length) { }
|
|
128 |
| |
|
129 |
21
| public void interpreterResetting() { }
|
|
130 |
| |
|
131 |
25
| public void interpreterReady(File wd) {
|
|
132 |
25
| File buildDir = _state.getBuildDirectory();
|
|
133 |
25
| if (buildDir != null) {
|
|
134 |
| |
|
135 |
25
| _jvm.addBuildDirectoryClassPath(IOUtil.attemptAbsoluteFile(buildDir));
|
|
136 |
| } |
|
137 |
| } |
|
138 |
| |
|
139 |
0
| public void interpreterResetFailed(Throwable t) { }
|
|
140 |
| |
|
141 |
1
| public void interpreterExited(int status) { }
|
|
142 |
| |
|
143 |
1
| public void interpreterChanged(boolean inProgress) { }
|
|
144 |
| |
|
145 |
0
| public void interactionIncomplete() { }
|
|
146 |
| }; |
|
147 |
| |
|
148 |
| private CompilerListener _clearInteractionsListener = new DummyCompilerListener() { |
|
149 |
56
| public void compileEnded(File workDir, List<? extends File> excludedFiles) {
|
|
150 |
| |
|
151 |
56
| if ( (_compilerModel.getNumErrors() == 0 || _compilerModel.getCompilerErrorModel().hasOnlyWarnings())
|
|
152 |
| && ! _junitModel.isTestInProgress() && _resetAfterCompile) { |
|
153 |
| |
|
154 |
10
| resetInteractions(workDir);
|
|
155 |
| } |
|
156 |
| } |
|
157 |
0
| public void activeCompilerChanged() {
|
|
158 |
0
| File workDir = _interactionsModel.getWorkingDirectory();
|
|
159 |
0
| resetInteractions(workDir, true);
|
|
160 |
| } |
|
161 |
| }; |
|
162 |
| |
|
163 |
| |
|
164 |
| |
|
165 |
| |
|
166 |
| private final CompilerModel _compilerModel; |
|
167 |
| |
|
168 |
| |
|
169 |
| private volatile boolean _resetAfterCompile = true; |
|
170 |
| |
|
171 |
| |
|
172 |
| private volatile int _numCompErrors = 0; |
|
173 |
| |
|
174 |
| |
|
175 |
| |
|
176 |
| |
|
177 |
| private final DefaultJUnitModel _junitModel; |
|
178 |
| |
|
179 |
| |
|
180 |
| |
|
181 |
| |
|
182 |
| protected volatile JavadocModel _javadocModel; |
|
183 |
| |
|
184 |
| |
|
185 |
| |
|
186 |
| |
|
187 |
| private volatile Debugger _debugger; |
|
188 |
| |
|
189 |
| |
|
190 |
| |
|
191 |
157
| public DefaultGlobalModel() {
|
|
192 |
157
| Iterable<? extends JDKToolsLibrary> tools = findLibraries();
|
|
193 |
157
| List<CompilerInterface> compilers = new LinkedList<CompilerInterface>();
|
|
194 |
157
| _debugger = null;
|
|
195 |
157
| _javadocModel = null;
|
|
196 |
157
| for (JDKToolsLibrary t : tools) {
|
|
197 |
| |
|
198 |
785
| if (t.compiler().isAvailable() && t.version().supports(JavaVersion.JAVA_5)) {
|
|
199 |
471
| compilers.add(t.compiler());
|
|
200 |
| } |
|
201 |
157
| if (_debugger == null && t.debugger().isAvailable()) { _debugger = t.debugger(); }
|
|
202 |
157
| if (_javadocModel == null && t.javadoc().isAvailable()) { _javadocModel = t.javadoc(); }
|
|
203 |
| } |
|
204 |
0
| if (_debugger == null) { _debugger = NoDebuggerAvailable.ONLY; }
|
|
205 |
0
| if (_javadocModel == null) { _javadocModel = new NoJavadocAvailable(this); }
|
|
206 |
| |
|
207 |
157
| File workDir = Utilities.TEST_MODE ? new File(System.getProperty("user.home")) : getWorkingDirectory();
|
|
208 |
157
| _jvm = new MainJVM(workDir);
|
|
209 |
| |
|
210 |
157
| _compilerModel = new DefaultCompilerModel(this, compilers);
|
|
211 |
157
| _junitModel = new DefaultJUnitModel(_jvm, _compilerModel, this);
|
|
212 |
157
| _interactionsDocument = new InteractionsDJDocument(_notifier);
|
|
213 |
| |
|
214 |
157
| _interactionsModel = new DefaultInteractionsModel(this, _jvm, _interactionsDocument, workDir);
|
|
215 |
157
| _interactionsModel.addListener(_interactionsListener);
|
|
216 |
157
| _jvm.setInteractionsModel(_interactionsModel);
|
|
217 |
157
| _jvm.setJUnitModel(_junitModel);
|
|
218 |
| |
|
219 |
157
| _setupDebugger();
|
|
220 |
| |
|
221 |
| |
|
222 |
157
| _interactionsModel.addListener(_notifier);
|
|
223 |
157
| _compilerModel.addListener(_notifier);
|
|
224 |
157
| _junitModel.addListener(_notifier);
|
|
225 |
157
| _javadocModel.addListener(_notifier);
|
|
226 |
| |
|
227 |
| |
|
228 |
| |
|
229 |
| |
|
230 |
157
| _compilerModel.addListener(_clearInteractionsListener);
|
|
231 |
| |
|
232 |
157
| _jvmStarter = new Thread("Start interpreter JVM") {
|
|
233 |
157
| public void run() { _jvm.startInterpreterJVM(); }
|
|
234 |
| }; |
|
235 |
157
| _jvmStarter.start();
|
|
236 |
| |
|
237 |
| |
|
238 |
| |
|
239 |
| } |
|
240 |
| |
|
241 |
| |
|
242 |
| |
|
243 |
5966
| private static JavaVersion.FullVersion coarsenVersion(JavaVersion.FullVersion tVersion) {
|
|
244 |
5966
| BooleanOption displayAllOption = edu.rice.cs.drjava.config.OptionConstants.DISPLAY_ALL_COMPILER_VERSIONS;
|
|
245 |
5966
| if (!DrJava.getConfig().getSetting(displayAllOption).booleanValue()) {
|
|
246 |
5966
| tVersion = tVersion.onlyMajorVersionAndVendor();
|
|
247 |
| } |
|
248 |
5966
| return tVersion;
|
|
249 |
| } |
|
250 |
| |
|
251 |
| |
|
252 |
| |
|
253 |
| |
|
254 |
| private static class LibraryKey implements Comparable<LibraryKey> { |
|
255 |
| public static final int PRIORITY_BUILTIN = 0; |
|
256 |
| public static final int PRIORITY_SEARCH = 1; |
|
257 |
| public static final int PRIORITY_RUNTIME = 2; |
|
258 |
| public static final int PRIORITY_CONFIG = 3; |
|
259 |
| protected final int _priority; |
|
260 |
| protected final JavaVersion.FullVersion _first; |
|
261 |
| protected final JDKDescriptor _second; |
|
262 |
| |
|
263 |
3454
| public LibraryKey(int priority, JavaVersion.FullVersion first, JDKDescriptor second) {
|
|
264 |
3454
| _priority = priority;
|
|
265 |
3454
| _first = first;
|
|
266 |
3454
| _second = second;
|
|
267 |
| } |
|
268 |
| |
|
269 |
0
| public boolean equals(Object o) {
|
|
270 |
| |
|
271 |
0
| if (this == o) { return true; }
|
|
272 |
| |
|
273 |
0
| else if (o == null || !getClass().equals(o.getClass())) { return false; }
|
|
274 |
| else { |
|
275 |
0
| LibraryKey cast = (LibraryKey) o;
|
|
276 |
| |
|
277 |
0
| return
|
|
278 |
| (_priority == cast._priority) && |
|
279 |
0
| (_first == null ? cast._first == null : _first.equals(cast._first)) &&
|
|
280 |
0
| (_second == null ? cast._second == null :
|
|
281 |
| ((_second==JDKDescriptor.NONE) && (cast._second==JDKDescriptor.NONE))); |
|
282 |
| } |
|
283 |
| } |
|
284 |
| |
|
285 |
0
| public String toString() {
|
|
286 |
0
| return "priority "+_priority+", version "+_first.versionString()+" "+_first.maintenance()+" "+_first.update()+" "+_first.release()+" "+_first.vendor()+" "+_first.location()+", descriptor "+_second.getName();
|
|
287 |
| } |
|
288 |
| |
|
289 |
0
| public int hashCode() {
|
|
290 |
0
| return
|
|
291 |
| _priority ^ |
|
292 |
0
| (_first == null ? 0 : _first.hashCode()) ^
|
|
293 |
0
| (_second == null ? 0 : _second.hashCode() << 1) ^
|
|
294 |
| getClass().hashCode(); |
|
295 |
| } |
|
296 |
| |
|
297 |
6437
| public int compareTo(LibraryKey o) {
|
|
298 |
6437
| int result = _priority - o._priority;
|
|
299 |
6437
| if (result == 0) {
|
|
300 |
4710
| result = _first.compareTo(o._first);
|
|
301 |
| } |
|
302 |
6437
| if (result == 0) {
|
|
303 |
1884
| if (_second==JDKDescriptor.NONE) {
|
|
304 |
1884
| if (o._second==JDKDescriptor.NONE) {
|
|
305 |
1884
| result = 0;
|
|
306 |
| } |
|
307 |
| else { |
|
308 |
| |
|
309 |
0
| result = 1;
|
|
310 |
| } |
|
311 |
| } |
|
312 |
0
| else if (o._second==JDKDescriptor.NONE) {
|
|
313 |
| |
|
314 |
0
| result = -1;
|
|
315 |
| } |
|
316 |
| else { |
|
317 |
0
| result = _second.toString().compareTo(o._second.toString());
|
|
318 |
| } |
|
319 |
| } |
|
320 |
6437
| return result;
|
|
321 |
| } |
|
322 |
| } |
|
323 |
| |
|
324 |
| |
|
325 |
3454
| private LibraryKey getLibraryKey(int priority, JDKToolsLibrary lib) {
|
|
326 |
3454
| return new LibraryKey(priority, coarsenVersion(lib.version()), lib.jdkDescriptor());
|
|
327 |
| } |
|
328 |
| |
|
329 |
157
| private Iterable<JDKToolsLibrary> findLibraries() {
|
|
330 |
| |
|
331 |
| |
|
332 |
| |
|
333 |
| |
|
334 |
| |
|
335 |
| |
|
336 |
157
| Map<LibraryKey, JDKToolsLibrary> results = new TreeMap<LibraryKey, JDKToolsLibrary>();
|
|
337 |
| |
|
338 |
157
| File configTools = DrJava.getConfig().getSetting(JAVAC_LOCATION);
|
|
339 |
157
| if (configTools != FileOps.NULL_FILE) {
|
|
340 |
0
| JDKToolsLibrary fromConfig = JarJDKToolsLibrary.makeFromFile(configTools, this, JDKDescriptor.NONE);
|
|
341 |
0
| if (fromConfig.isValid()) {
|
|
342 |
0
| JarJDKToolsLibrary.msg("From config: "+fromConfig);
|
|
343 |
0
| results.put(getLibraryKey(LibraryKey.PRIORITY_CONFIG, fromConfig), fromConfig);
|
|
344 |
| } |
|
345 |
0
| else { JarJDKToolsLibrary.msg("From config: invalid "+fromConfig); }
|
|
346 |
| } |
|
347 |
157
| else { JarJDKToolsLibrary.msg("From config: not set"); }
|
|
348 |
| |
|
349 |
157
| Iterable<JDKToolsLibrary> allFromRuntime = JDKToolsLibrary.makeFromRuntime(this);
|
|
350 |
| |
|
351 |
157
| for(JDKToolsLibrary fromRuntime: allFromRuntime) {
|
|
352 |
157
| if (fromRuntime.isValid()) {
|
|
353 |
157
| if (!results.containsKey(getLibraryKey(LibraryKey.PRIORITY_RUNTIME, fromRuntime))) {
|
|
354 |
157
| JarJDKToolsLibrary.msg("From runtime: "+fromRuntime);
|
|
355 |
157
| results.put(getLibraryKey(LibraryKey.PRIORITY_RUNTIME, fromRuntime), fromRuntime);
|
|
356 |
| } |
|
357 |
0
| else { JarJDKToolsLibrary.msg("From runtime: duplicate "+fromRuntime); }
|
|
358 |
| } |
|
359 |
0
| else { JarJDKToolsLibrary.msg("From runtime: invalid "+fromRuntime); }
|
|
360 |
| } |
|
361 |
| |
|
362 |
157
| Iterable<JarJDKToolsLibrary> fromSearch = JarJDKToolsLibrary.search(this);
|
|
363 |
157
| for (JDKToolsLibrary t : fromSearch) {
|
|
364 |
2512
| JavaVersion.FullVersion tVersion = t.version();
|
|
365 |
2512
| JarJDKToolsLibrary.msg("From search: "+t);
|
|
366 |
2512
| JavaVersion.FullVersion coarsenedVersion = coarsenVersion(tVersion);
|
|
367 |
2512
| JarJDKToolsLibrary.msg("\ttVersion: "+tVersion+" "+tVersion.vendor());
|
|
368 |
2512
| JarJDKToolsLibrary.msg("\tcoarsenedVersion: "+coarsenedVersion+" "+coarsenedVersion.vendor());
|
|
369 |
| |
|
370 |
2512
| int priority = (edu.rice.cs.util.FileOps.getDrJavaFile().equals(tVersion.location()))?LibraryKey.PRIORITY_BUILTIN:LibraryKey.PRIORITY_SEARCH;
|
|
371 |
2512
| if (!results.containsKey(getLibraryKey(priority, t))) {
|
|
372 |
628
| JarJDKToolsLibrary.msg("\tadded");
|
|
373 |
628
| results.put(getLibraryKey(priority, t), t);
|
|
374 |
| } |
|
375 |
1884
| else { JarJDKToolsLibrary.msg("\tduplicate"); }
|
|
376 |
| } |
|
377 |
| |
|
378 |
157
| return IterUtil.reverse(results.values());
|
|
379 |
| } |
|
380 |
| |
|
381 |
| |
|
382 |
| |
|
383 |
| |
|
384 |
2
| public void setBuildDirectory(File f) {
|
|
385 |
2
| _state.setBuildDirectory(f);
|
|
386 |
2
| if (f != FileOps.NULL_FILE) {
|
|
387 |
| |
|
388 |
0
| _jvm.addBuildDirectoryClassPath(IOUtil.attemptAbsoluteFile(f));
|
|
389 |
| } |
|
390 |
| |
|
391 |
2
| _notifier.projectBuildDirChanged();
|
|
392 |
2
| setProjectChanged(true);
|
|
393 |
2
| setClassPathChanged(true);
|
|
394 |
| } |
|
395 |
| |
|
396 |
| |
|
397 |
| |
|
398 |
| |
|
399 |
388
| public DefaultInteractionsModel getInteractionsModel() { return _interactionsModel; }
|
|
400 |
| |
|
401 |
| |
|
402 |
153
| public InteractionsDJDocument getSwingInteractionsDocument() { return _interactionsDocument; }
|
|
403 |
| |
|
404 |
35
| public InteractionsDocument getInteractionsDocument() { return _interactionsModel.getDocument(); }
|
|
405 |
| |
|
406 |
| |
|
407 |
1246
| public CompilerModel getCompilerModel() { return _compilerModel; }
|
|
408 |
| |
|
409 |
| |
|
410 |
64
| public JUnitModel getJUnitModel() { return _junitModel; }
|
|
411 |
| |
|
412 |
| |
|
413 |
122
| public JavadocModel getJavadocModel() { return _javadocModel; }
|
|
414 |
| |
|
415 |
4
| public int getNumCompErrors() { return _numCompErrors; }
|
|
416 |
56
| public void setNumCompErrors(int num) { _numCompErrors = num; }
|
|
417 |
| |
|
418 |
| |
|
419 |
155
| public void dispose() {
|
|
420 |
155
| ensureJVMStarterFinished();
|
|
421 |
155
| _jvm.dispose();
|
|
422 |
155
| _notifier.removeAllListeners();
|
|
423 |
| } |
|
424 |
| |
|
425 |
| |
|
426 |
270
| public void ensureJVMStarterFinished() {
|
|
427 |
270
| try { _jvmStarter.join(); }
|
|
428 |
0
| catch (InterruptedException e) { throw new UnexpectedException(e); }
|
|
429 |
| } |
|
430 |
| |
|
431 |
| |
|
432 |
0
| public void disposeExternalResources() { _jvm.stopInterpreterJVM(); }
|
|
433 |
| |
|
434 |
23
| public void resetInteractions(File wd) { resetInteractions(wd, false); }
|
|
435 |
| |
|
436 |
| |
|
437 |
| |
|
438 |
| |
|
439 |
| |
|
440 |
| |
|
441 |
| |
|
442 |
24
| public void resetInteractions(File wd, boolean forceReset) {
|
|
443 |
24
| assert _interactionsModel._pane != null;
|
|
444 |
| |
|
445 |
24
| debug.logStart();
|
|
446 |
24
| File workDir = _interactionsModel.getWorkingDirectory();
|
|
447 |
0
| if (wd == null) { wd = workDir; }
|
|
448 |
24
| forceReset |= isClassPathChanged();
|
|
449 |
24
| forceReset |= !wd.equals(workDir);
|
|
450 |
| |
|
451 |
24
| DrJava.getConfig().setSetting(LAST_INTERACTIONS_DIRECTORY, wd);
|
|
452 |
24
| getDebugger().setAutomaticTraceEnabled(false);
|
|
453 |
24
| _interactionsModel.resetInterpreter(wd, forceReset);
|
|
454 |
24
| debug.logEnd();
|
|
455 |
| } |
|
456 |
| |
|
457 |
| |
|
458 |
31
| public void interpretCurrentInteraction() { _interactionsModel.interpretCurrentInteraction(); }
|
|
459 |
| |
|
460 |
| |
|
461 |
| |
|
462 |
| |
|
463 |
3
| public void loadHistory(final FileOpenSelector selector) {
|
|
464 |
3
| Utilities.invokeLater(new Runnable() {
|
|
465 |
3
| public void run() {
|
|
466 |
3
| try {_interactionsModel.loadHistory(selector); }
|
|
467 |
0
| catch(IOException e) { throw new UnexpectedException(e); }
|
|
468 |
| } |
|
469 |
| }); |
|
470 |
| } |
|
471 |
| |
|
472 |
| |
|
473 |
0
| public InteractionsScriptModel loadHistoryAsScript(FileOpenSelector selector)
|
|
474 |
| throws IOException, OperationCanceledException { |
|
475 |
0
| return _interactionsModel.loadHistoryAsScript(selector);
|
|
476 |
| } |
|
477 |
| |
|
478 |
| |
|
479 |
1
| public void clearHistory() { _interactionsModel.getDocument().clearHistory(); }
|
|
480 |
| |
|
481 |
| |
|
482 |
| |
|
483 |
| |
|
484 |
1
| public void saveHistory(FileSaveSelector selector) throws IOException {
|
|
485 |
1
| _interactionsModel.getDocument().saveHistory(selector);
|
|
486 |
| } |
|
487 |
| |
|
488 |
| |
|
489 |
| |
|
490 |
| |
|
491 |
| |
|
492 |
0
| public void saveConsoleCopy(ConsoleDocument doc, FileSaveSelector selector) throws IOException {
|
|
493 |
0
| doc.saveCopy(selector);
|
|
494 |
| } |
|
495 |
| |
|
496 |
| |
|
497 |
| |
|
498 |
| |
|
499 |
| |
|
500 |
| |
|
501 |
0
| public void saveHistory(FileSaveSelector selector, String editedVersion) throws IOException {
|
|
502 |
0
| _interactionsModel.getDocument().saveHistory(selector, editedVersion);
|
|
503 |
| } |
|
504 |
| |
|
505 |
| |
|
506 |
1
| public String getHistoryAsStringWithSemicolons() {
|
|
507 |
1
| return _interactionsModel.getDocument().getHistoryAsStringWithSemicolons();
|
|
508 |
| } |
|
509 |
| |
|
510 |
| |
|
511 |
2
| public String getHistoryAsString() {
|
|
512 |
2
| return _interactionsModel.getDocument().getHistoryAsString();
|
|
513 |
| } |
|
514 |
| |
|
515 |
| |
|
516 |
0
| public void printDebugMessage(String s) {
|
|
517 |
0
| _interactionsModel.getDocument().
|
|
518 |
| insertBeforeLastPrompt(s + "\n", InteractionsDocument.DEBUGGER_STYLE); |
|
519 |
| } |
|
520 |
| |
|
521 |
| |
|
522 |
0
| public Iterable<File> getInteractionsClassPath() {
|
|
523 |
0
| return _jvm.getClassPath().unwrap(IterUtil.<File>empty());
|
|
524 |
| } |
|
525 |
| |
|
526 |
| |
|
527 |
| |
|
528 |
| |
|
529 |
| |
|
530 |
122
| void setResetAfterCompile(boolean shouldReset) { _resetAfterCompile = shouldReset; }
|
|
531 |
| |
|
532 |
| |
|
533 |
498
| public Debugger getDebugger() { return _debugger; }
|
|
534 |
| |
|
535 |
| |
|
536 |
| |
|
537 |
| |
|
538 |
0
| public int getDebugPort() throws IOException { return _interactionsModel.getDebugPort(); }
|
|
539 |
| |
|
540 |
| |
|
541 |
| |
|
542 |
| |
|
543 |
| |
|
544 |
| |
|
545 |
| |
|
546 |
| class ConcreteOpenDefDoc extends AbstractGlobalModel.ConcreteOpenDefDoc { |
|
547 |
| |
|
548 |
| |
|
549 |
| |
|
550 |
79
| ConcreteOpenDefDoc(File f) {
|
|
551 |
79
| super(f);
|
|
552 |
| |
|
553 |
| |
|
554 |
| |
|
555 |
79
| updateSyntaxHighlighting();
|
|
556 |
| } |
|
557 |
| |
|
558 |
| |
|
559 |
309
| ConcreteOpenDefDoc(NullFile f) { super(f);
|
|
560 |
| |
|
561 |
| |
|
562 |
| |
|
563 |
309
| updateSyntaxHighlighting();
|
|
564 |
| } |
|
565 |
| |
|
566 |
| |
|
567 |
48
| public void startCompile() throws IOException {
|
|
568 |
48
| assert EventQueue.isDispatchThread();
|
|
569 |
48
| _compilerModel.compile(ConcreteOpenDefDoc.this);
|
|
570 |
| } |
|
571 |
| |
|
572 |
| private volatile InteractionsListener _runMain; |
|
573 |
| |
|
574 |
| |
|
575 |
| |
|
576 |
| |
|
577 |
| |
|
578 |
| |
|
579 |
| |
|
580 |
| |
|
581 |
| |
|
582 |
| |
|
583 |
| |
|
584 |
| |
|
585 |
| |
|
586 |
| |
|
587 |
| |
|
588 |
| |
|
589 |
| |
|
590 |
| |
|
591 |
2
| protected void _runInInteractions(final String command, String qualifiedClassName) throws ClassNameNotFoundException,
|
|
592 |
| IOException { |
|
593 |
| |
|
594 |
2
| assert EventQueue.isDispatchThread();
|
|
595 |
| |
|
596 |
2
| _notifier.prepareForRun(ConcreteOpenDefDoc.this);
|
|
597 |
| |
|
598 |
2
| String tempClassName = null;
|
|
599 |
| |
|
600 |
2
| if(qualifiedClassName == null)
|
|
601 |
2
| tempClassName = getDocument().getQualifiedClassName();
|
|
602 |
| else |
|
603 |
0
| tempClassName = qualifiedClassName;
|
|
604 |
| |
|
605 |
| |
|
606 |
2
| final String className = tempClassName;
|
|
607 |
2
| final InteractionsDocument iDoc = _interactionsModel.getDocument();
|
|
608 |
2
| if (! checkIfClassFileInSync()) {
|
|
609 |
1
| iDoc.insertBeforeLastPrompt(DOCUMENT_OUT_OF_SYNC_MSG, InteractionsDocument.ERROR_STYLE);
|
|
610 |
1
| return;
|
|
611 |
| } |
|
612 |
| |
|
613 |
1
| final boolean wasDebuggerEnabled = getDebugger().isReady();
|
|
614 |
| |
|
615 |
1
| _runMain = new DummyInteractionsListener() {
|
|
616 |
1
| public void interpreterReady(File wd) {
|
|
617 |
| |
|
618 |
| |
|
619 |
| |
|
620 |
| |
|
621 |
| |
|
622 |
| |
|
623 |
1
| _interactionsModel.removeListener(_runMain);
|
|
624 |
| |
|
625 |
| |
|
626 |
| |
|
627 |
1
| javax.swing.SwingUtilities.invokeLater(new Runnable() {
|
|
628 |
1
| public void run() {
|
|
629 |
| |
|
630 |
1
| if (wasDebuggerEnabled && (! getDebugger().isReady())) {
|
|
631 |
| |
|
632 |
0
| try { getDebugger().startUp(); } catch(DebugException de) { }
|
|
633 |
| } |
|
634 |
| |
|
635 |
1
| iDoc.clearCurrentInput();
|
|
636 |
1
| iDoc.append(java.text.MessageFormat.format(command, className), null);
|
|
637 |
| |
|
638 |
| |
|
639 |
1
| new Thread("Running document") {
|
|
640 |
1
| public void run() { _interactionsModel.interpretCurrentInteraction(); }
|
|
641 |
| }.start(); |
|
642 |
| } |
|
643 |
| }); |
|
644 |
| } |
|
645 |
| }; |
|
646 |
| |
|
647 |
1
| File oldWorkDir = _interactionsModel.getWorkingDirectory();
|
|
648 |
1
| _interactionsModel.addListener(_runMain);
|
|
649 |
| |
|
650 |
1
| File workDir;
|
|
651 |
1
| workDir = getWorkingDirectory();
|
|
652 |
| |
|
653 |
| |
|
654 |
1
| resetInteractions(workDir, !workDir.equals(oldWorkDir));
|
|
655 |
| } |
|
656 |
| |
|
657 |
| |
|
658 |
| |
|
659 |
| |
|
660 |
| |
|
661 |
| |
|
662 |
| |
|
663 |
| |
|
664 |
| |
|
665 |
| |
|
666 |
| |
|
667 |
| |
|
668 |
| |
|
669 |
2
| public void runMain(String qualifiedClassName) throws ClassNameNotFoundException, IOException {
|
|
670 |
2
| _runInInteractions("java {0}", qualifiedClassName);
|
|
671 |
| } |
|
672 |
| |
|
673 |
| |
|
674 |
| |
|
675 |
| |
|
676 |
| |
|
677 |
| |
|
678 |
| |
|
679 |
| |
|
680 |
| |
|
681 |
| |
|
682 |
| |
|
683 |
| |
|
684 |
| |
|
685 |
0
| public void runApplet(String qualifiedClassName) throws ClassNameNotFoundException, IOException {
|
|
686 |
0
| _runInInteractions("applet {0}", qualifiedClassName);
|
|
687 |
| } |
|
688 |
| |
|
689 |
| |
|
690 |
| |
|
691 |
| |
|
692 |
| |
|
693 |
| |
|
694 |
| |
|
695 |
| |
|
696 |
| |
|
697 |
| |
|
698 |
| |
|
699 |
| |
|
700 |
| |
|
701 |
| |
|
702 |
| |
|
703 |
0
| public void runSmart(String qualifiedClassName) throws ClassNameNotFoundException, IOException {
|
|
704 |
0
| _runInInteractions("run {0}", qualifiedClassName);
|
|
705 |
| } |
|
706 |
| |
|
707 |
| |
|
708 |
17
| public void startJUnit() throws ClassNotFoundException, IOException { _junitModel.junit(this); }
|
|
709 |
| |
|
710 |
| |
|
711 |
| |
|
712 |
| |
|
713 |
| |
|
714 |
0
| public void generateJavadoc(FileSaveSelector saver) throws IOException {
|
|
715 |
| |
|
716 |
0
| _javadocModel.javadocDocument(this, saver);
|
|
717 |
| } |
|
718 |
| |
|
719 |
| |
|
720 |
151
| public void removeFromDebugger() { getBreakpointManager().removeRegions(this); }
|
|
721 |
| |
|
722 |
| |
|
723 |
| |
|
724 |
| |
|
725 |
| |
|
726 |
| |
|
727 |
| |
|
728 |
| |
|
729 |
| |
|
730 |
| } |
|
731 |
| |
|
732 |
| |
|
733 |
| |
|
734 |
| |
|
735 |
309
| protected ConcreteOpenDefDoc _createOpenDefinitionsDocument(NullFile f) { return new ConcreteOpenDefDoc(f); }
|
|
736 |
| |
|
737 |
| |
|
738 |
| |
|
739 |
| |
|
740 |
87
| protected ConcreteOpenDefDoc _createOpenDefinitionsDocument(File f) throws IOException {
|
|
741 |
8
| if (! f.exists()) throw new FileNotFoundException("file " + f + " cannot be found");
|
|
742 |
79
| return new ConcreteOpenDefDoc(f);
|
|
743 |
| } |
|
744 |
| |
|
745 |
| |
|
746 |
| |
|
747 |
| |
|
748 |
207
| protected void addDocToClassPath(OpenDefinitionsDocument doc) {
|
|
749 |
207
| try {
|
|
750 |
207
| File sourceRoot = doc.getSourceRoot();
|
|
751 |
0
| if (doc.isAuxiliaryFile()) { _interactionsModel.addProjectFilesClassPath(sourceRoot); }
|
|
752 |
206
| else { _interactionsModel.addExternalFilesClassPath(sourceRoot); }
|
|
753 |
206
| setClassPathChanged(true);
|
|
754 |
| } |
|
755 |
| catch (InvalidPackageException e) { |
|
756 |
| |
|
757 |
| } |
|
758 |
| } |
|
759 |
| |
|
760 |
157
| private void _setupDebugger() {
|
|
761 |
157
| _jvm.setDebugModel(_debugger.callback());
|
|
762 |
| |
|
763 |
| |
|
764 |
157
| getBreakpointManager().addListener(new RegionManagerListener<Breakpoint>() {
|
|
765 |
0
| public void regionAdded(final Breakpoint bp) { setProjectChanged(true); }
|
|
766 |
0
| public void regionChanged(final Breakpoint bp) { setProjectChanged(true); }
|
|
767 |
0
| public void regionRemoved(final Breakpoint bp) {
|
|
768 |
0
| try { getDebugger().removeBreakpoint(bp); }
|
|
769 |
| catch(DebugException de) { |
|
770 |
| |
|
771 |
| |
|
772 |
| |
|
773 |
| |
|
774 |
| |
|
775 |
| |
|
776 |
| |
|
777 |
| } |
|
778 |
0
| setProjectChanged(true);
|
|
779 |
| } |
|
780 |
| }); |
|
781 |
157
| getBookmarkManager().addListener(new RegionManagerListener<MovingDocumentRegion>() {
|
|
782 |
5
| public void regionAdded(MovingDocumentRegion r) { setProjectChanged(true); }
|
|
783 |
0
| public void regionChanged(MovingDocumentRegion r) { setProjectChanged(true); }
|
|
784 |
5
| public void regionRemoved(MovingDocumentRegion r) { setProjectChanged(true); }
|
|
785 |
| }); |
|
786 |
| |
|
787 |
157
| _debugger.addListener(new DebugListener() {
|
|
788 |
0
| public void watchSet(final DebugWatchData w) { setProjectChanged(true); }
|
|
789 |
0
| public void watchRemoved(final DebugWatchData w) { setProjectChanged(true); }
|
|
790 |
| |
|
791 |
0
| public void regionAdded(final Breakpoint bp) { }
|
|
792 |
0
| public void regionChanged(final Breakpoint bp) { }
|
|
793 |
0
| public void regionRemoved(final Breakpoint bp) { }
|
|
794 |
0
| public void debuggerStarted() { }
|
|
795 |
0
| public void debuggerShutdown() { }
|
|
796 |
0
| public void threadLocationUpdated(OpenDefinitionsDocument doc, int lineNumber, boolean shouldHighlight) { }
|
|
797 |
0
| public void breakpointReached(final Breakpoint bp) { }
|
|
798 |
0
| public void stepRequested() { }
|
|
799 |
0
| public void currThreadSuspended() { }
|
|
800 |
0
| public void currThreadResumed() { }
|
|
801 |
0
| public void threadStarted() { }
|
|
802 |
0
| public void currThreadDied() { }
|
|
803 |
0
| public void nonCurrThreadDied() { }
|
|
804 |
0
| public void currThreadSet(DebugThreadData thread) { }
|
|
805 |
| }); |
|
806 |
| } |
|
807 |
| |
|
808 |
| |
|
809 |
| |
|
810 |
| |
|
811 |
55
| public Iterable<File> getClassPath() {
|
|
812 |
55
| Iterable<File> result = IterUtil.empty();
|
|
813 |
| |
|
814 |
55
| if (isProjectActive()) {
|
|
815 |
0
| File buildDir = getBuildDirectory();
|
|
816 |
0
| if (buildDir != null) { result = IterUtil.compose(result, buildDir); }
|
|
817 |
| |
|
818 |
| |
|
819 |
| |
|
820 |
| |
|
821 |
| |
|
822 |
| |
|
823 |
| |
|
824 |
| |
|
825 |
0
| File projRoot = getProjectRoot();
|
|
826 |
0
| if (projRoot != null) { result = IterUtil.compose(result, projRoot); }
|
|
827 |
| |
|
828 |
0
| Iterable<AbsRelFile> projectExtras = getExtraClassPath();
|
|
829 |
0
| if (projectExtras != null) { result = IterUtil.compose(result, projectExtras); }
|
|
830 |
| } |
|
831 |
55
| else { result = IterUtil.compose(result, getSourceRootSet()); }
|
|
832 |
| |
|
833 |
55
| Vector<File> globalExtras = DrJava.getConfig().getSetting(EXTRA_CLASSPATH);
|
|
834 |
55
| if (globalExtras != null) { result = IterUtil.compose(result, globalExtras); }
|
|
835 |
| |
|
836 |
| |
|
837 |
| |
|
838 |
| |
|
839 |
| |
|
840 |
| |
|
841 |
55
| result = IterUtil.compose(result, ReflectUtil.SYSTEM_CLASS_PATH);
|
|
842 |
| |
|
843 |
55
| return result;
|
|
844 |
| } |
|
845 |
| |
|
846 |
| |
|
847 |
| |
|
848 |
| |
|
849 |
| |
|
850 |
| |
|
851 |
183
| public void resetInteractionsClassPath() {
|
|
852 |
| |
|
853 |
183
| Iterable<AbsRelFile> projectExtras = getExtraClassPath();
|
|
854 |
| |
|
855 |
0
| if (projectExtras != null) for (File cpE : projectExtras) { _interactionsModel.addProjectClassPath(cpE); }
|
|
856 |
| |
|
857 |
183
| Vector<File> cp = DrJava.getConfig().getSetting(EXTRA_CLASSPATH);
|
|
858 |
183
| if (cp != null) {
|
|
859 |
2
| for (File f : cp) { _interactionsModel.addExtraClassPath(f); }
|
|
860 |
| } |
|
861 |
| |
|
862 |
183
| for (OpenDefinitionsDocument odd: getAuxiliaryDocuments()) {
|
|
863 |
| |
|
864 |
0
| try { _interactionsModel.addProjectFilesClassPath(odd.getSourceRoot()); }
|
|
865 |
| catch(InvalidPackageException e) { } |
|
866 |
| } |
|
867 |
| |
|
868 |
183
| for (OpenDefinitionsDocument odd: getNonProjectDocuments()) {
|
|
869 |
| |
|
870 |
213
| try {
|
|
871 |
213
| File sourceRoot = odd.getSourceRoot();
|
|
872 |
18
| if (sourceRoot != null) _interactionsModel.addExternalFilesClassPath(sourceRoot);
|
|
873 |
| } |
|
874 |
| catch(InvalidPackageException e) { } |
|
875 |
| } |
|
876 |
| |
|
877 |
| |
|
878 |
| |
|
879 |
183
| _interactionsModel.addProjectFilesClassPath(getProjectRoot());
|
|
880 |
183
| setClassPathChanged(false);
|
|
881 |
| } |
|
882 |
| } |