|
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 |
| package edu.rice.cs.drjava.model; |
|
37 |
| |
|
38 |
| import java.awt.Color; |
|
39 |
| import java.awt.Container; |
|
40 |
| import java.awt.EventQueue; |
|
41 |
| import java.awt.Font; |
|
42 |
| import java.awt.event.FocusEvent; |
|
43 |
| import java.awt.event.FocusListener; |
|
44 |
| import java.awt.print.PageFormat; |
|
45 |
| import java.awt.print.Pageable; |
|
46 |
| import java.awt.print.PrinterException; |
|
47 |
| import java.awt.print.PrinterJob; |
|
48 |
| import java.awt.Component; |
|
49 |
| import java.io.File; |
|
50 |
| import java.io.FileNotFoundException; |
|
51 |
| import java.io.FileReader; |
|
52 |
| import java.io.FilenameFilter; |
|
53 |
| import java.io.IOException; |
|
54 |
| import java.io.OutputStream; |
|
55 |
| import java.io.StringReader; |
|
56 |
| |
|
57 |
| import java.util.AbstractMap; |
|
58 |
| import java.util.ArrayList; |
|
59 |
| import java.util.Collection; |
|
60 |
| import java.util.Collections; |
|
61 |
| import java.util.Comparator; |
|
62 |
| import java.util.Set; |
|
63 |
| import java.util.LinkedHashSet; |
|
64 |
| import java.util.HashMap; |
|
65 |
| import java.util.HashSet; |
|
66 |
| import java.util.LinkedHashMap; |
|
67 |
| import java.util.LinkedList; |
|
68 |
| import java.util.List; |
|
69 |
| import java.util.Vector; |
|
70 |
| import java.util.WeakHashMap; |
|
71 |
| import java.util.Map; |
|
72 |
| |
|
73 |
| import javax.swing.*; |
|
74 |
| import javax.swing.event.DocumentListener; |
|
75 |
| import javax.swing.event.UndoableEditListener; |
|
76 |
| import javax.swing.text.AttributeSet; |
|
77 |
| import javax.swing.text.BadLocationException; |
|
78 |
| import javax.swing.text.DefaultEditorKit; |
|
79 |
| import javax.swing.text.Element; |
|
80 |
| import javax.swing.text.Position; |
|
81 |
| import javax.swing.text.Segment; |
|
82 |
| import javax.swing.text.Style; |
|
83 |
| import javax.swing.ProgressMonitor; |
|
84 |
| |
|
85 |
| import edu.rice.cs.drjava.DrJava; |
|
86 |
| import edu.rice.cs.drjava.DrJavaRoot; |
|
87 |
| import edu.rice.cs.drjava.config.Option; |
|
88 |
| import edu.rice.cs.drjava.config.OptionParser; |
|
89 |
| import edu.rice.cs.drjava.config.OptionConstants; |
|
90 |
| import edu.rice.cs.drjava.config.OptionEvent; |
|
91 |
| import edu.rice.cs.drjava.config.OptionListener; |
|
92 |
| import edu.rice.cs.drjava.model.cache.DCacheAdapter; |
|
93 |
| import edu.rice.cs.drjava.model.cache.DDReconstructor; |
|
94 |
| import edu.rice.cs.drjava.model.cache.DocumentCache ; |
|
95 |
| import edu.rice.cs.drjava.model.compiler.CompilerModel; |
|
96 |
| import edu.rice.cs.drjava.model.debug.Breakpoint; |
|
97 |
| import edu.rice.cs.drjava.model.debug.DebugBreakpointData; |
|
98 |
| import edu.rice.cs.drjava.model.debug.DebugException ; |
|
99 |
| import edu.rice.cs.drjava.model.debug.DebugWatchData; |
|
100 |
| import edu.rice.cs.drjava.model.debug.Debugger; |
|
101 |
| import edu.rice.cs.drjava.model.debug.NoDebuggerAvailable; |
|
102 |
| import edu.rice.cs.drjava.model.javadoc.JavadocModel; |
|
103 |
| import edu.rice.cs.drjava.model.definitions.ClassNameNotFoundException; |
|
104 |
| import edu.rice.cs.drjava.model.definitions.CompoundUndoManager; |
|
105 |
| import edu.rice.cs.drjava.model.definitions.DefinitionsDocument; |
|
106 |
| import edu.rice.cs.drjava.model.definitions.DefinitionsEditorKit; |
|
107 |
| import edu.rice.cs.drjava.model.definitions.DocumentUIListener ; |
|
108 |
| import edu.rice.cs.drjava.model.definitions.InvalidPackageException; |
|
109 |
| import edu.rice.cs.drjava.model.definitions.indent.Indenter; |
|
110 |
| import edu.rice.cs.drjava.model.definitions.reducedmodel.HighlightStatus; |
|
111 |
| import edu.rice.cs.drjava.model.definitions.reducedmodel.ReducedModelControl; |
|
112 |
| import edu.rice.cs.drjava.model.definitions.reducedmodel.ReducedModelState; |
|
113 |
| import edu.rice.cs.drjava.model.junit.JUnitModel; |
|
114 |
| import edu.rice.cs.drjava.model.print.DrJavaBook; |
|
115 |
| import edu.rice.cs.drjava.model.repl.DefaultInteractionsModel ; |
|
116 |
| import edu.rice.cs.drjava.model.repl.InteractionsDJDocument; |
|
117 |
| import edu.rice.cs.drjava.model.repl.InteractionsDocument; |
|
118 |
| import edu.rice.cs.drjava.model.repl.InteractionsScriptModel; |
|
119 |
| import edu.rice.cs.drjava.project.DocFile ; |
|
120 |
| import edu.rice.cs.drjava.project.DocumentInfoGetter; |
|
121 |
| import edu.rice.cs.drjava.project.MalformedProjectFileException; |
|
122 |
| import edu.rice.cs.drjava.project.ProjectFileIR; |
|
123 |
| import edu.rice.cs.drjava.project.ProjectFileParserFacade; |
|
124 |
| import edu.rice.cs.drjava.project.ProjectProfile; |
|
125 |
| import edu.rice.cs.drjava.ui.DrJavaErrorHandler; |
|
126 |
| |
|
127 |
| import edu.rice.cs.plt.reflect.ReflectUtil; |
|
128 |
| import edu.rice.cs.plt.tuple.Pair; |
|
129 |
| import edu.rice.cs.plt.io.IOUtil; |
|
130 |
| import edu.rice.cs.plt.iter.IterUtil; |
|
131 |
| import edu.rice.cs.plt.collect.CollectUtil; |
|
132 |
| import edu.rice.cs.plt.lambda.LambdaUtil; |
|
133 |
| import edu.rice.cs.plt.lambda.Predicate; |
|
134 |
| |
|
135 |
| import edu.rice.cs.util.FileOpenSelector; |
|
136 |
| import edu.rice.cs.util.FileOps; |
|
137 |
| import edu.rice.cs.util.Log; |
|
138 |
| import edu.rice.cs.util.NullFile; |
|
139 |
| import edu.rice.cs.util.AbsRelFile; |
|
140 |
| import edu.rice.cs.util.OperationCanceledException; |
|
141 |
| import edu.rice.cs.util.StringOps; |
|
142 |
| import edu.rice.cs.util.UnexpectedException; |
|
143 |
| import edu.rice.cs.util.docnavigation.AWTContainerNavigatorFactory; |
|
144 |
| import edu.rice.cs.util.docnavigation.IDocumentNavigator; |
|
145 |
| import edu.rice.cs.util.docnavigation.INavigationListener; |
|
146 |
| import edu.rice.cs.util.docnavigation.INavigatorItem; |
|
147 |
| import edu.rice.cs.util.docnavigation.INavigatorItemFilter; |
|
148 |
| import edu.rice.cs.util.docnavigation.JTreeSortNavigator; |
|
149 |
| import edu.rice.cs.util.docnavigation.NodeData; |
|
150 |
| import edu.rice.cs.util.docnavigation.NodeDataVisitor; |
|
151 |
| import edu.rice.cs.util.swing.AsyncCompletionArgs ; |
|
152 |
| import edu.rice.cs.util.swing.AsyncTask; |
|
153 |
| import edu.rice.cs.util.swing.IAsyncProgress; |
|
154 |
| import edu.rice.cs.util.swing.DocumentIterator; |
|
155 |
| import edu.rice.cs.util.swing.Utilities; |
|
156 |
| import edu.rice.cs.util.text.AbstractDocumentInterface; |
|
157 |
| import edu.rice.cs.util.text.ConsoleDocument; |
|
158 |
| |
|
159 |
| import static edu.rice.cs.plt.debug.DebugUtil.debug; |
|
160 |
| |
|
161 |
| |
|
162 |
| |
|
163 |
| |
|
164 |
| |
|
165 |
| public class AbstractGlobalModel implements SingleDisplayModel, OptionConstants, DocumentIterator { |
|
166 |
| |
|
167 |
| public static final Log _log = new Log("GlobalModel.txt", false); |
|
168 |
| |
|
169 |
| |
|
170 |
| protected DocumentCache _cache; |
|
171 |
| |
|
172 |
| static final String DOCUMENT_OUT_OF_SYNC_MSG = |
|
173 |
| "Current document is out of sync with the Interactions Pane and should be recompiled!\n"; |
|
174 |
| |
|
175 |
| static final String CLASSPATH_OUT_OF_SYNC_MSG = |
|
176 |
| "Interactions Pane is out of sync with the current classpath and should be reset!\n"; |
|
177 |
| |
|
178 |
| |
|
179 |
| |
|
180 |
| |
|
181 |
| |
|
182 |
| |
|
183 |
| |
|
184 |
| |
|
185 |
| public final GlobalEventNotifier _notifier = new GlobalEventNotifier(); |
|
186 |
| |
|
187 |
| |
|
188 |
| |
|
189 |
| |
|
190 |
| protected final DefinitionsEditorKit _editorKit = new DefinitionsEditorKit(_notifier); |
|
191 |
| |
|
192 |
| |
|
193 |
| private final AbstractMap<File, OpenDefinitionsDocument> _documentsRepos = |
|
194 |
| new LinkedHashMap<File, OpenDefinitionsDocument>(); |
|
195 |
| |
|
196 |
| |
|
197 |
| |
|
198 |
| |
|
199 |
| protected final ConsoleDocument _consoleDoc; |
|
200 |
| |
|
201 |
| |
|
202 |
| protected final InteractionsDJDocument _consoleDocAdapter; |
|
203 |
| |
|
204 |
| |
|
205 |
| protected volatile PageFormat _pageFormat = new PageFormat(); |
|
206 |
| |
|
207 |
| |
|
208 |
| |
|
209 |
| |
|
210 |
| private volatile OpenDefinitionsDocument _activeDocument; |
|
211 |
| |
|
212 |
| |
|
213 |
| |
|
214 |
| |
|
215 |
| |
|
216 |
| private volatile File _activeDirectory; |
|
217 |
| |
|
218 |
| |
|
219 |
| private volatile boolean classPathChanged = false; |
|
220 |
| |
|
221 |
| |
|
222 |
| |
|
223 |
| |
|
224 |
| protected volatile IDocumentNavigator<OpenDefinitionsDocument> _documentNavigator = |
|
225 |
| new AWTContainerNavigatorFactory<OpenDefinitionsDocument>().makeListNavigator(); |
|
226 |
| |
|
227 |
| |
|
228 |
0
| public GlobalEventNotifier getNotifier() { return _notifier; }
|
|
229 |
| |
|
230 |
| |
|
231 |
| protected final ConcreteRegionManager<Breakpoint> _breakpointManager; |
|
232 |
| |
|
233 |
| |
|
234 |
466
| public RegionManager<Breakpoint> getBreakpointManager() { return _breakpointManager; }
|
|
235 |
| |
|
236 |
| |
|
237 |
| protected final ConcreteRegionManager<MovingDocumentRegion> _bookmarkManager; |
|
238 |
| |
|
239 |
| |
|
240 |
242
| public RegionManager<MovingDocumentRegion> getBookmarkManager() { return _bookmarkManager; }
|
|
241 |
| |
|
242 |
| |
|
243 |
| protected final LinkedList<RegionManager<MovingDocumentRegion>> _findResultsManagers; |
|
244 |
| |
|
245 |
| |
|
246 |
79
| public List<RegionManager<MovingDocumentRegion>> getFindResultsManagers() {
|
|
247 |
79
| return new LinkedList<RegionManager<MovingDocumentRegion>>(_findResultsManagers);
|
|
248 |
| } |
|
249 |
| |
|
250 |
| |
|
251 |
0
| public RegionManager<MovingDocumentRegion> createFindResultsManager() {
|
|
252 |
0
| ConcreteRegionManager<MovingDocumentRegion> rm = new ConcreteRegionManager<MovingDocumentRegion>();
|
|
253 |
0
| _findResultsManagers.add(rm);
|
|
254 |
| |
|
255 |
0
| return rm;
|
|
256 |
| } |
|
257 |
| |
|
258 |
| |
|
259 |
0
| public void removeFindResultsManager(RegionManager<MovingDocumentRegion> rm) {
|
|
260 |
0
| _findResultsManagers.remove(rm);
|
|
261 |
| } |
|
262 |
| |
|
263 |
| |
|
264 |
| protected final BrowserHistoryManager _browserHistoryManager; |
|
265 |
| |
|
266 |
| |
|
267 |
178
| public BrowserHistoryManager getBrowserHistoryManager() { return _browserHistoryManager; }
|
|
268 |
| |
|
269 |
| |
|
270 |
| |
|
271 |
| |
|
272 |
| |
|
273 |
| |
|
274 |
| |
|
275 |
| |
|
276 |
| |
|
277 |
| |
|
278 |
| |
|
279 |
| |
|
280 |
| |
|
281 |
| |
|
282 |
159
| public AbstractGlobalModel() {
|
|
283 |
159
| _cache = new DocumentCache();
|
|
284 |
| |
|
285 |
159
| _consoleDocAdapter = new InteractionsDJDocument(_notifier);
|
|
286 |
159
| _consoleDoc = new ConsoleDocument(_consoleDocAdapter);
|
|
287 |
| |
|
288 |
159
| _bookmarkManager = new ConcreteRegionManager<MovingDocumentRegion>();
|
|
289 |
159
| _findResultsManagers = new LinkedList<RegionManager<MovingDocumentRegion>>();
|
|
290 |
159
| _browserHistoryManager = new BrowserHistoryManager();
|
|
291 |
| |
|
292 |
159
| _breakpointManager = new ConcreteRegionManager<Breakpoint>();
|
|
293 |
| |
|
294 |
| |
|
295 |
| |
|
296 |
| |
|
297 |
| |
|
298 |
| |
|
299 |
| |
|
300 |
| |
|
301 |
| |
|
302 |
| |
|
303 |
| |
|
304 |
| |
|
305 |
159
| _registerOptionListeners();
|
|
306 |
| |
|
307 |
159
| setFileGroupingState(makeFlatFileGroupingState());
|
|
308 |
159
| Utilities.invokeLater(new Runnable() { public void run() { _notifier.projectRunnableChanged(); } });
|
|
309 |
159
| _init();
|
|
310 |
| } |
|
311 |
| |
|
312 |
159
| private void _init() {
|
|
313 |
| |
|
314 |
| |
|
315 |
159
| final NodeDataVisitor<OpenDefinitionsDocument, Boolean> _gainVisitor =
|
|
316 |
| new NodeDataVisitor<OpenDefinitionsDocument, Boolean>() { |
|
317 |
396
| public Boolean itemCase(OpenDefinitionsDocument doc, Object... p) {
|
|
318 |
396
| _setActiveDoc(doc);
|
|
319 |
| |
|
320 |
| |
|
321 |
| |
|
322 |
396
| final File oldDir = _activeDirectory;
|
|
323 |
396
| final File dir = doc.getParentDirectory();
|
|
324 |
396
| if (dir != null && ! dir.equals(oldDir)) {
|
|
325 |
| |
|
326 |
| |
|
327 |
189
| _activeDirectory = dir;
|
|
328 |
189
| _notifier.currentDirectoryChanged(_activeDirectory);
|
|
329 |
| } |
|
330 |
396
| return Boolean.valueOf(true);
|
|
331 |
| } |
|
332 |
0
| public Boolean fileCase(File f, Object... p) {
|
|
333 |
0
| if (! f.isAbsolute()) {
|
|
334 |
0
| File root = _state.getProjectFile().getParentFile().getAbsoluteFile();
|
|
335 |
0
| f = new File(root, f.getPath());
|
|
336 |
| } |
|
337 |
0
| _activeDirectory = f;
|
|
338 |
0
| _notifier.currentDirectoryChanged(f);
|
|
339 |
0
| return Boolean.valueOf(true);
|
|
340 |
| } |
|
341 |
0
| public Boolean stringCase(String s, Object... p) { return Boolean.valueOf(false); }
|
|
342 |
| }; |
|
343 |
| |
|
344 |
| |
|
345 |
159
| _documentNavigator.addNavigationListener(new INavigationListener<OpenDefinitionsDocument>() {
|
|
346 |
396
| public void gainedSelection(NodeData<? extends OpenDefinitionsDocument> dat, boolean modelInitiated) {
|
|
347 |
396
| dat.execute(_gainVisitor, modelInitiated); }
|
|
348 |
291
| public void lostSelection(NodeData<? extends OpenDefinitionsDocument> dat, boolean modelInitiated) {
|
|
349 |
| } |
|
350 |
| }); |
|
351 |
| |
|
352 |
| |
|
353 |
159
| _documentNavigator.addFocusListener(new FocusListener() {
|
|
354 |
0
| public void focusGained(FocusEvent e) {
|
|
355 |
| |
|
356 |
| |
|
357 |
0
| Utilities.invokeLater(new Runnable() { public void run() { _notifier.focusOnDefinitionsPane(); } });
|
|
358 |
| } |
|
359 |
0
| public void focusLost(FocusEvent e) { }
|
|
360 |
| }); |
|
361 |
| |
|
362 |
159
| _ensureNotEmpty();
|
|
363 |
159
| setActiveFirstDocument();
|
|
364 |
| |
|
365 |
| |
|
366 |
159
| OptionListener<Integer> clipboardHistorySizeListener = new OptionListener<Integer>() {
|
|
367 |
0
| public void optionChanged(OptionEvent<Integer> oce) {
|
|
368 |
0
| ClipboardHistoryModel.singleton().resize(oce.value);
|
|
369 |
| } |
|
370 |
| }; |
|
371 |
159
| DrJava.getConfig().addOptionListener(CLIPBOARD_HISTORY_SIZE, clipboardHistorySizeListener);
|
|
372 |
159
| ClipboardHistoryModel.singleton().resize(DrJava.getConfig().getSetting(CLIPBOARD_HISTORY_SIZE).intValue());
|
|
373 |
| |
|
374 |
| |
|
375 |
159
| OptionListener<Integer> browserHistoryMaxSizeListener = new OptionListener<Integer>() {
|
|
376 |
0
| public void optionChanged(OptionEvent<Integer> oce) {
|
|
377 |
0
| AbstractGlobalModel.this.getBrowserHistoryManager().setMaximumSize(oce.value);
|
|
378 |
| } |
|
379 |
| }; |
|
380 |
159
| DrJava.getConfig().addOptionListener(BROWSER_HISTORY_MAX_SIZE, browserHistoryMaxSizeListener);
|
|
381 |
159
| getBrowserHistoryManager().setMaximumSize(DrJava.getConfig().getSetting(BROWSER_HISTORY_MAX_SIZE).intValue());
|
|
382 |
| } |
|
383 |
| |
|
384 |
| |
|
385 |
| |
|
386 |
| |
|
387 |
| |
|
388 |
| |
|
389 |
| protected volatile FileGroupingState _state; |
|
390 |
| |
|
391 |
| |
|
392 |
165
| public void setFileGroupingState(FileGroupingState state) {
|
|
393 |
165
| _state = state;
|
|
394 |
165
| _notifier.projectRunnableChanged();
|
|
395 |
165
| _notifier.projectBuildDirChanged();
|
|
396 |
165
| _notifier.projectWorkDirChanged();
|
|
397 |
| |
|
398 |
| |
|
399 |
| } |
|
400 |
| |
|
401 |
| |
|
402 |
| |
|
403 |
| |
|
404 |
1
| public void addAuxiliaryFile(OpenDefinitionsDocument doc) { _state.addAuxFile(doc.getRawFile()); }
|
|
405 |
| |
|
406 |
| |
|
407 |
| |
|
408 |
| |
|
409 |
1
| public void removeAuxiliaryFile(OpenDefinitionsDocument doc) { _state.remAuxFile(doc.getRawFile()); }
|
|
410 |
| |
|
411 |
4
| protected FileGroupingState
|
|
412 |
| makeProjectFileGroupingState(File pr, String main, File bd, File wd, File project, File[] srcFiles, File[] auxFiles, |
|
413 |
| File[] excludedFiles, Iterable<AbsRelFile> cp, File cjf, int cjflags, boolean refresh, |
|
414 |
| String manifest, Map<OptionParser<?>,String> storedPreferences) { |
|
415 |
| |
|
416 |
4
| return new ProjectFileGroupingState(pr, main, bd, wd, project, srcFiles, auxFiles, excludedFiles, cp, cjf, cjflags,
|
|
417 |
| refresh, manifest, storedPreferences); |
|
418 |
| } |
|
419 |
| |
|
420 |
| |
|
421 |
24
| public boolean isClassPathChanged() { return classPathChanged; }
|
|
422 |
| |
|
423 |
| |
|
424 |
438
| public void setClassPathChanged(boolean changed) {
|
|
425 |
438
| classPathChanged = changed;
|
|
426 |
| } |
|
427 |
| |
|
428 |
| |
|
429 |
132
| public void setProjectChanged(boolean changed) {
|
|
430 |
132
| _state.setProjectChanged(changed);
|
|
431 |
| |
|
432 |
| } |
|
433 |
| |
|
434 |
| |
|
435 |
4
| public boolean isProjectChanged() { return _state.isProjectChanged(); }
|
|
436 |
| |
|
437 |
| |
|
438 |
172
| public boolean isProjectActive() { return _state.isProjectActive(); }
|
|
439 |
| |
|
440 |
| |
|
441 |
| |
|
442 |
0
| public File getProjectFile() { return _state.getProjectFile(); }
|
|
443 |
| |
|
444 |
| |
|
445 |
| |
|
446 |
| |
|
447 |
0
| public File[] getProjectFiles() { return _state.getProjectFiles(); }
|
|
448 |
| |
|
449 |
| |
|
450 |
105
| public boolean inProject(File f) { return _state.inProject(f); }
|
|
451 |
| |
|
452 |
| |
|
453 |
| |
|
454 |
| |
|
455 |
| |
|
456 |
69
| public boolean inProjectPath(OpenDefinitionsDocument doc) { return _state.inProjectPath(doc); }
|
|
457 |
| |
|
458 |
| |
|
459 |
0
| public void setMainClass(String f) {
|
|
460 |
0
| _state.setMainClass(f);
|
|
461 |
0
| _notifier.projectRunnableChanged();
|
|
462 |
0
| setProjectChanged(true);
|
|
463 |
| } |
|
464 |
| |
|
465 |
| |
|
466 |
8
| public String getMainClass() { return _state.getMainClass(); }
|
|
467 |
| |
|
468 |
| |
|
469 |
0
| public File getMainClassContainingFile() {
|
|
470 |
0
| String path = getMainClass();
|
|
471 |
| |
|
472 |
0
| if (path == null) return null;
|
|
473 |
| |
|
474 |
| |
|
475 |
0
| if (path.toLowerCase().endsWith(OptionConstants.JAVA_FILE_EXTENSION)) {
|
|
476 |
0
| return new File(getProjectFile().getParent(), path);
|
|
477 |
| } |
|
478 |
| |
|
479 |
| |
|
480 |
| |
|
481 |
| |
|
482 |
| |
|
483 |
| |
|
484 |
| |
|
485 |
0
| path = path.replace('.', File.separatorChar);
|
|
486 |
0
| File tempFile = new File(getProjectRoot(), path+OptionConstants.JAVA_FILE_EXTENSION);
|
|
487 |
0
| while (path.length() > 0) {
|
|
488 |
0
| if (tempFile.exists()) return tempFile;
|
|
489 |
| |
|
490 |
0
| if (path.indexOf(File.separatorChar) == -1) break;
|
|
491 |
| |
|
492 |
0
| path = path.substring(0, path.lastIndexOf(File.separatorChar));
|
|
493 |
0
| tempFile = new File(getProjectRoot(), path + OptionConstants.JAVA_FILE_EXTENSION);
|
|
494 |
| } |
|
495 |
| |
|
496 |
0
| return null;
|
|
497 |
| } |
|
498 |
| |
|
499 |
| |
|
500 |
0
| public void setCreateJarFile(File f) {
|
|
501 |
0
| _state.setCreateJarFile(f);
|
|
502 |
0
| setProjectChanged(true);
|
|
503 |
| } |
|
504 |
| |
|
505 |
| |
|
506 |
1
| public File getCreateJarFile() { return _state.getCreateJarFile(); }
|
|
507 |
| |
|
508 |
| |
|
509 |
0
| public void setCreateJarFlags(int f) {
|
|
510 |
0
| _state.setCreateJarFlags(f);
|
|
511 |
0
| setProjectChanged(true);
|
|
512 |
| } |
|
513 |
| |
|
514 |
| |
|
515 |
1
| public int getCreateJarFlags() { return _state.getCreateJarFlags(); }
|
|
516 |
| |
|
517 |
| |
|
518 |
347
| public File getProjectRoot() { return _state.getProjectRoot(); }
|
|
519 |
| |
|
520 |
| |
|
521 |
0
| public void setProjectRoot(File f) {
|
|
522 |
0
| _state.setProjectRoot(f);
|
|
523 |
| |
|
524 |
0
| setProjectChanged(true);
|
|
525 |
| } |
|
526 |
| |
|
527 |
| |
|
528 |
1
| public void setProjectFile(File f) { _state.setProjectFile(f); }
|
|
529 |
| |
|
530 |
| |
|
531 |
393
| public File getBuildDirectory() { return _state.getBuildDirectory(); }
|
|
532 |
| |
|
533 |
| |
|
534 |
0
| public Map<OptionParser<?>,String> getPreferencesStoredInProject() { return _state.getPreferencesStoredInProject(); }
|
|
535 |
| |
|
536 |
0
| public void setPreferencesStoredInProject(Map<OptionParser<?>,String> sp) { _state.setPreferencesStoredInProject(sp); }
|
|
537 |
| |
|
538 |
| |
|
539 |
0
| public void setBuildDirectory(File f) {
|
|
540 |
0
| _state.setBuildDirectory(f);
|
|
541 |
0
| _notifier.projectBuildDirChanged();
|
|
542 |
0
| setProjectChanged(true);
|
|
543 |
| } |
|
544 |
| |
|
545 |
| |
|
546 |
32
| public boolean getAutoRefreshStatus() { return _state.getAutoRefreshStatus(); }
|
|
547 |
| |
|
548 |
| |
|
549 |
0
| public void setAutoRefreshStatus(boolean status) { _state.setAutoRefreshStatus(status); }
|
|
550 |
| |
|
551 |
| |
|
552 |
307
| public File getMasterWorkingDirectory() {
|
|
553 |
307
| File file;
|
|
554 |
307
| try {
|
|
555 |
| |
|
556 |
307
| file = FileOps.getValidDirectory(DrJava.getConfig().getSetting(LAST_DIRECTORY));
|
|
557 |
| } |
|
558 |
| catch (RuntimeException e) { |
|
559 |
| |
|
560 |
0
| DrJava.getConfig().setSetting(LAST_DIRECTORY, FileOps.NULL_FILE);
|
|
561 |
0
| file = FileOps.getValidDirectory(new File(System.getProperty("user.home", ".")));
|
|
562 |
| } |
|
563 |
| |
|
564 |
307
| DrJava.getConfig().setSetting(LAST_DIRECTORY, file);
|
|
565 |
307
| return file;
|
|
566 |
| } |
|
567 |
| |
|
568 |
| |
|
569 |
41
| public File getWorkingDirectory() { return _state.getWorkingDirectory(); }
|
|
570 |
| |
|
571 |
| |
|
572 |
0
| public void setWorkingDirectory(File f) {
|
|
573 |
0
| _state.setWorkingDirectory(f);
|
|
574 |
0
| _notifier.projectWorkDirChanged();
|
|
575 |
0
| setProjectChanged(true);
|
|
576 |
| |
|
577 |
0
| DrJava.getConfig().setSetting(LAST_INTERACTIONS_DIRECTORY, _state.getWorkingDirectory());
|
|
578 |
| } |
|
579 |
| |
|
580 |
0
| public void cleanBuildDirectory() { _state.cleanBuildDirectory(); }
|
|
581 |
| |
|
582 |
0
| public List<File> getClassFiles() { return _state.getClassFiles(); }
|
|
583 |
| |
|
584 |
| |
|
585 |
0
| protected static String getPackageName(String classname) {
|
|
586 |
0
| int index = classname.lastIndexOf(".");
|
|
587 |
0
| if (index != -1) return classname.substring(0, index);
|
|
588 |
0
| else return "";
|
|
589 |
| } |
|
590 |
| |
|
591 |
| class ProjectFileGroupingState implements FileGroupingState { |
|
592 |
| |
|
593 |
| volatile File _projRoot; |
|
594 |
| volatile String _mainClass; |
|
595 |
| volatile File _buildDir; |
|
596 |
| volatile File _workDir; |
|
597 |
| volatile File _projectFile; |
|
598 |
| final File[] _projectFiles; |
|
599 |
| volatile ArrayList<File> _auxFiles; |
|
600 |
| private volatile ArrayList<File> _exclFiles; |
|
601 |
| volatile Iterable<AbsRelFile> _projExtraClassPath; |
|
602 |
| private boolean _isProjectChanged = false; |
|
603 |
| volatile File _createJarFile; |
|
604 |
| volatile int _createJarFlags; |
|
605 |
| volatile boolean _autoRefreshStatus; |
|
606 |
| final Map<OptionParser<?>,String> _storedPreferences = new HashMap<OptionParser<?>,String>(); |
|
607 |
| |
|
608 |
| volatile String _manifest = null; |
|
609 |
| |
|
610 |
| HashSet<String> _projFilePaths = new HashSet<String>(); |
|
611 |
| |
|
612 |
| |
|
613 |
0
| ProjectFileGroupingState(File project) {
|
|
614 |
0
| this(project.getParentFile(), null, null, null, project, new File[0], new File[0], new File[0],
|
|
615 |
| IterUtil.<AbsRelFile>empty(), null, 0, false, null, new HashMap<OptionParser<?>,String>()); |
|
616 |
0
| HashMap<OptionParser<?>,String> defaultStoredPreferences = new HashMap<OptionParser<?>,String>();
|
|
617 |
| |
|
618 |
0
| defaultStoredPreferences.put(INDENT_LEVEL, DrJava.getConfig().getOptionMap().getString(INDENT_LEVEL));
|
|
619 |
0
| defaultStoredPreferences.put(LANGUAGE_LEVEL, DrJava.getConfig().getOptionMap().getString(LANGUAGE_LEVEL));
|
|
620 |
0
| setPreferencesStoredInProject(defaultStoredPreferences);
|
|
621 |
| } |
|
622 |
| |
|
623 |
4
| ProjectFileGroupingState(File pr, String main, File bd, File wd, File project, File[] srcFiles, File[] auxFiles,
|
|
624 |
| File[] excludedFiles, Iterable<AbsRelFile> cp, File cjf, int cjflags, boolean refreshStatus, |
|
625 |
| String customManifest, Map<OptionParser<?>,String> storedPreferences) { |
|
626 |
4
| _projRoot = pr;
|
|
627 |
4
| _mainClass = main;
|
|
628 |
4
| _buildDir = bd;
|
|
629 |
4
| _workDir = wd;
|
|
630 |
4
| _projectFile = project;
|
|
631 |
4
| _projectFiles = srcFiles;
|
|
632 |
4
| _auxFiles = new ArrayList<File>(auxFiles.length);
|
|
633 |
1
| for(File f: auxFiles) { _auxFiles.add(f); }
|
|
634 |
4
| _exclFiles = new ArrayList<File>(excludedFiles.length);
|
|
635 |
0
| for(File f: excludedFiles) { _exclFiles.add(f); }
|
|
636 |
4
| _projExtraClassPath = cp;
|
|
637 |
| |
|
638 |
4
| if (_projectFiles != null) {
|
|
639 |
8
| try { for (File file : _projectFiles) { _projFilePaths.add(file.getCanonicalPath()); } }
|
|
640 |
| catch(IOException e) { } |
|
641 |
| } |
|
642 |
| |
|
643 |
4
| _createJarFile = cjf;
|
|
644 |
4
| _createJarFlags = cjflags;
|
|
645 |
4
| _autoRefreshStatus = refreshStatus;
|
|
646 |
4
| _manifest = customManifest;
|
|
647 |
4
| setPreferencesStoredInProject(storedPreferences);
|
|
648 |
| } |
|
649 |
| |
|
650 |
19
| public boolean isProjectActive() { return true; }
|
|
651 |
| |
|
652 |
| |
|
653 |
| |
|
654 |
| |
|
655 |
31
| public boolean inProjectPath(OpenDefinitionsDocument doc) {
|
|
656 |
8
| if (doc.isUntitled()) return false;
|
|
657 |
| |
|
658 |
| |
|
659 |
| |
|
660 |
| |
|
661 |
23
| File f;
|
|
662 |
23
| try { f = doc.getFile(); }
|
|
663 |
0
| catch(FileMovedException fme) { f = fme.getFile(); }
|
|
664 |
23
| return inProjectPath(f);
|
|
665 |
| } |
|
666 |
| |
|
667 |
| |
|
668 |
| |
|
669 |
| |
|
670 |
38
| public boolean inProjectPath(File f) { return IOUtil.isMember(f, getProjectRoot()); }
|
|
671 |
| |
|
672 |
| |
|
673 |
0
| public File getProjectFile() { return _projectFile; }
|
|
674 |
| |
|
675 |
15
| public boolean inProject(File f) {
|
|
676 |
15
| String path;
|
|
677 |
| |
|
678 |
3
| if (isUntitled(f) || ! inProjectPath(f)) return false;
|
|
679 |
12
| try {
|
|
680 |
12
| path = f.getCanonicalPath();
|
|
681 |
12
| return _projFilePaths.contains(path);
|
|
682 |
| } |
|
683 |
0
| catch(IOException ioe) { return false; }
|
|
684 |
| } |
|
685 |
| |
|
686 |
0
| public File[] getProjectFiles() { return _projectFiles; }
|
|
687 |
| |
|
688 |
50
| public File getProjectRoot() {
|
|
689 |
0
| if (_projRoot == null || _projRoot.equals( FileOps.NULL_FILE)) return _projectFile.getParentFile();
|
|
690 |
| |
|
691 |
50
| return _projRoot;
|
|
692 |
| } |
|
693 |
| |
|
694 |
14
| public File getBuildDirectory() { return _buildDir; }
|
|
695 |
| |
|
696 |
4
| public File getWorkingDirectory() {
|
|
697 |
4
| try {
|
|
698 |
4
| if (_workDir == null || _workDir == FileOps.NULL_FILE) {
|
|
699 |
| |
|
700 |
4
| File prefWorkDir = DrJava.getConfig().getSetting(FIXED_INTERACTIONS_DIRECTORY);
|
|
701 |
4
| if ((prefWorkDir != null) && (prefWorkDir != FileOps.NULL_FILE)) {
|
|
702 |
0
| try {
|
|
703 |
| |
|
704 |
0
| prefWorkDir = FileOps.getValidDirectory(prefWorkDir);
|
|
705 |
| } |
|
706 |
0
| catch (RuntimeException e) { prefWorkDir = FileOps.NULL_FILE; }
|
|
707 |
| } |
|
708 |
0
| if ((prefWorkDir != null) && (prefWorkDir != FileOps.NULL_FILE)) { return prefWorkDir; }
|
|
709 |
| |
|
710 |
| |
|
711 |
| |
|
712 |
4
| File parentDir = _projectFile.getParentFile();
|
|
713 |
4
| if (parentDir != null) {
|
|
714 |
4
| return parentDir.getCanonicalFile();
|
|
715 |
| } |
|
716 |
0
| else return new File(System.getProperty("user.dir"));
|
|
717 |
| } |
|
718 |
0
| return _workDir.getCanonicalFile();
|
|
719 |
| } |
|
720 |
| catch(IOException e) { } |
|
721 |
0
| return _workDir.getAbsoluteFile();
|
|
722 |
| } |
|
723 |
| |
|
724 |
| |
|
725 |
1
| public void setProjectFile(File f) { _projectFile = f; }
|
|
726 |
| |
|
727 |
0
| public void setProjectRoot(File f) {
|
|
728 |
0
| _projRoot = f;
|
|
729 |
| |
|
730 |
| } |
|
731 |
| |
|
732 |
| |
|
733 |
1
| public void addAuxFile(File f) {
|
|
734 |
1
| synchronized(_auxFiles) {
|
|
735 |
1
| if (_auxFiles.add(f)) setProjectChanged(true);
|
|
736 |
| } |
|
737 |
| } |
|
738 |
| |
|
739 |
| |
|
740 |
1
| public void remAuxFile(File file) {
|
|
741 |
1
| synchronized(_auxFiles) {
|
|
742 |
1
| if (_auxFiles.remove(file)) setProjectChanged(true);
|
|
743 |
| } |
|
744 |
| } |
|
745 |
| |
|
746 |
0
| public void addExcludedFile(File f) {
|
|
747 |
0
| if(f == null) return;
|
|
748 |
0
| if (isAlreadyOpen(f)) return;
|
|
749 |
0
| synchronized(_exclFiles) {
|
|
750 |
0
| if (_exclFiles.add(f)) setProjectChanged(true);
|
|
751 |
| } |
|
752 |
| } |
|
753 |
| |
|
754 |
0
| public void removeExcludedFile(File f) {
|
|
755 |
0
| synchronized(_exclFiles) {
|
|
756 |
0
| for(int i = 0;i < _exclFiles.size();i++) {
|
|
757 |
0
| try {
|
|
758 |
0
| if(_exclFiles.get(i).getCanonicalPath().equals(f.getCanonicalPath())) {
|
|
759 |
0
| _exclFiles.remove(i);
|
|
760 |
0
| setProjectChanged(true);
|
|
761 |
| } |
|
762 |
| } |
|
763 |
| catch(IOException e) { } |
|
764 |
| } |
|
765 |
| } |
|
766 |
| } |
|
767 |
| |
|
768 |
1
| public File[] getExclFiles() { return _exclFiles.toArray(new File[_exclFiles.size()]); }
|
|
769 |
| |
|
770 |
0
| public void setExcludedFiles(File[] fs) {
|
|
771 |
0
| if(fs == null) return;
|
|
772 |
0
| synchronized(_exclFiles) {
|
|
773 |
0
| _exclFiles.clear();
|
|
774 |
0
| for(File f: fs) { addExcludedFile(f); }
|
|
775 |
0
| setProjectChanged(true);
|
|
776 |
| } |
|
777 |
| } |
|
778 |
| |
|
779 |
1
| public void setBuildDirectory(File f) { _buildDir = f; }
|
|
780 |
| |
|
781 |
0
| public void setWorkingDirectory(File f) { _workDir = f; }
|
|
782 |
| |
|
783 |
8
| public String getMainClass() { return _mainClass; }
|
|
784 |
| |
|
785 |
0
| public void setMainClass(String f) { _mainClass = f; }
|
|
786 |
| |
|
787 |
0
| public void setCreateJarFile(File f) { _createJarFile = f; }
|
|
788 |
| |
|
789 |
1
| public File getCreateJarFile() { return _createJarFile; }
|
|
790 |
| |
|
791 |
0
| public void setCreateJarFlags(int f) { _createJarFlags = f; }
|
|
792 |
| |
|
793 |
1
| public int getCreateJarFlags() { return _createJarFlags; }
|
|
794 |
| |
|
795 |
4
| public boolean isProjectChanged() { return _isProjectChanged; }
|
|
796 |
| |
|
797 |
7
| public void setProjectChanged(boolean changed) { _isProjectChanged = changed; }
|
|
798 |
| |
|
799 |
24
| public boolean isAuxiliaryFile(File f) {
|
|
800 |
24
| String path;
|
|
801 |
| |
|
802 |
0
| if (isUntitled(f)) return false;
|
|
803 |
| |
|
804 |
24
| try { path = f.getCanonicalPath();}
|
|
805 |
0
| catch(IOException ioe) { return false; }
|
|
806 |
| |
|
807 |
24
| synchronized(_auxFiles) {
|
|
808 |
24
| for (File file : _auxFiles) {
|
|
809 |
6
| try { if (file.getCanonicalPath().equals(path)) return true; }
|
|
810 |
| catch(IOException ioe) { } |
|
811 |
| } |
|
812 |
18
| return false;
|
|
813 |
| } |
|
814 |
| } |
|
815 |
| |
|
816 |
7
| public boolean isExcludedFile(File f) {
|
|
817 |
7
| String path;
|
|
818 |
0
| if (isUntitled(f)) return false;
|
|
819 |
| |
|
820 |
7
| try { path = f.getCanonicalPath();}
|
|
821 |
0
| catch(IOException ioe) { return false; }
|
|
822 |
| |
|
823 |
7
| synchronized(_exclFiles) {
|
|
824 |
7
| for (File file : _exclFiles) {
|
|
825 |
0
| try { if (file.getCanonicalPath().equals(path)) return true; }
|
|
826 |
| catch(IOException ioe) { } |
|
827 |
| } |
|
828 |
7
| return false;
|
|
829 |
| } |
|
830 |
| } |
|
831 |
| |
|
832 |
5
| public boolean getAutoRefreshStatus() { return _autoRefreshStatus; }
|
|
833 |
0
| public void setAutoRefreshStatus(boolean status) { _autoRefreshStatus = status; }
|
|
834 |
| |
|
835 |
| |
|
836 |
1
| public Map<OptionParser<?>,String> getPreferencesStoredInProject() {
|
|
837 |
1
| return new HashMap<OptionParser<?>,String>(_storedPreferences);
|
|
838 |
| } |
|
839 |
| |
|
840 |
5
| public void setPreferencesStoredInProject(Map<OptionParser<?>,String> sp) {
|
|
841 |
| |
|
842 |
5
| removePreviousListeners();
|
|
843 |
| |
|
844 |
5
| _storedPreferences.clear();
|
|
845 |
5
| _storedPreferences.putAll(sp);
|
|
846 |
| |
|
847 |
| |
|
848 |
5
| addNewListeners(sp);
|
|
849 |
| } |
|
850 |
| |
|
851 |
| |
|
852 |
0
| public void cleanBuildDirectory() {
|
|
853 |
0
| File dir = this.getBuildDirectory ();
|
|
854 |
0
| _notifier.executeAsyncTask(_findFilesToCleanTask, dir, false, true);
|
|
855 |
| } |
|
856 |
| |
|
857 |
| private AsyncTask<File,List<File>> _findFilesToCleanTask = new AsyncTask<File,List<File>>("Find Files to Clean") { |
|
858 |
| private FilenameFilter _filter = new FilenameFilter() { |
|
859 |
0
| public boolean accept(File parent, String name) {
|
|
860 |
0
| return new File(parent, name).isDirectory() || name.endsWith(".class");
|
|
861 |
| } |
|
862 |
| }; |
|
863 |
| |
|
864 |
0
| public List<File> runAsync(File buildDir, IAsyncProgress monitor) throws Exception {
|
|
865 |
0
| List<File> accumulator = new LinkedList<File>();
|
|
866 |
0
| helper(buildDir, accumulator);
|
|
867 |
0
| return accumulator;
|
|
868 |
| } |
|
869 |
0
| public void complete(AsyncCompletionArgs<List<File>> args) {
|
|
870 |
0
| _notifier.executeAsyncTask(_deleteFilesTask, args.getResult(), true, true);
|
|
871 |
| } |
|
872 |
0
| public String getDiscriptionMessage() {
|
|
873 |
0
| return "Finding files to delete...";
|
|
874 |
| } |
|
875 |
0
| private void helper(File file, List<File> accumulator) {
|
|
876 |
0
| if (file.isDirectory ()) {
|
|
877 |
0
| File[] children = file.listFiles(_filter);
|
|
878 |
0
| for (File child : children) {
|
|
879 |
0
| helper(child, accumulator);
|
|
880 |
0
| accumulator.add(file);
|
|
881 |
| } |
|
882 |
| } |
|
883 |
0
| else if ( file.getName().endsWith(".class")) accumulator.add(file);
|
|
884 |
| } |
|
885 |
| }; |
|
886 |
| |
|
887 |
| private AsyncTask<List<File>,List<File>> _deleteFilesTask = new AsyncTask<List<File>,List<File>>("Delete Files") { |
|
888 |
0
| public List<File> runAsync(List<File> filesToDelete, IAsyncProgress monitor) throws Exception {
|
|
889 |
0
| List<File> undeletableFiles = new ArrayList<File>();
|
|
890 |
| |
|
891 |
0
| monitor.setMinimum (0);
|
|
892 |
0
| monitor.setMaximum(filesToDelete.size());
|
|
893 |
0
| int progress = 1;
|
|
894 |
0
| for(File file : filesToDelete) {
|
|
895 |
0
| if (monitor.isCanceled()) {
|
|
896 |
0
| break;
|
|
897 |
| } |
|
898 |
0
| monitor.setNote(file.getName());
|
|
899 |
0
| boolean could = file.delete();
|
|
900 |
0
| if (!could) undeletableFiles.add(file);
|
|
901 |
0
| monitor.setProgress(progress++);
|
|
902 |
| } |
|
903 |
| |
|
904 |
0
| return undeletableFiles;
|
|
905 |
| } |
|
906 |
0
| public void complete(AsyncCompletionArgs<List<File>> args) {
|
|
907 |
| |
|
908 |
| } |
|
909 |
0
| public String getDiscriptionMessage() {
|
|
910 |
0
| return "Deleting files...";
|
|
911 |
| } |
|
912 |
| }; |
|
913 |
| |
|
914 |
0
| public List<File> getClassFiles() {
|
|
915 |
0
| File dir = this.getBuildDirectory ();
|
|
916 |
0
| LinkedList<File> acc = new LinkedList<File>();
|
|
917 |
0
| getClassFilesHelper(dir, acc);
|
|
918 |
0
| if (! dir.exists()) dir.mkdirs();
|
|
919 |
0
| return acc;
|
|
920 |
| } |
|
921 |
| |
|
922 |
0
| private void getClassFilesHelper(File f, LinkedList<File> acc) {
|
|
923 |
0
| if (f.isDirectory()) {
|
|
924 |
| |
|
925 |
0
| File fs[] = f.listFiles(new FilenameFilter() {
|
|
926 |
0
| public boolean accept(File parent, String name) {
|
|
927 |
0
| return new File(parent, name).isDirectory() || name.endsWith(".class");
|
|
928 |
| } |
|
929 |
| }); |
|
930 |
| |
|
931 |
0
| if (fs != null) {
|
|
932 |
0
| for (File kid: fs) { getClassFilesHelper(kid, acc); }
|
|
933 |
| } |
|
934 |
| |
|
935 |
0
| } else if (f.getName().endsWith(".class")) acc.add(f);
|
|
936 |
| } |
|
937 |
| |
|
938 |
| |
|
939 |
| |
|
940 |
4
| public Iterable<AbsRelFile> getExtraClassPath() { return _projExtraClassPath; }
|
|
941 |
0
| public void setExtraClassPath(Iterable<AbsRelFile> cp) {
|
|
942 |
0
| _projExtraClassPath = cp;
|
|
943 |
0
| setClassPathChanged(true);
|
|
944 |
| } |
|
945 |
| |
|
946 |
| |
|
947 |
1
| public String getCustomManifest() { return _manifest; }
|
|
948 |
0
| public void setCustomManifest(String manifest) { _manifest = manifest; }
|
|
949 |
| } |
|
950 |
| |
|
951 |
7
| @SuppressWarnings("unchecked")
|
|
952 |
| protected void removePreviousListeners() { |
|
953 |
7
| for(Map.Entry<OptionParser<?>, OptionListener<?>> e: LISTENERS_TO_REMOVE.entrySet()) {
|
|
954 |
| |
|
955 |
0
| if (e.getKey() instanceof Option) {
|
|
956 |
0
| DrJava.getConfig().removeOptionListener((Option)e.getKey(), e.getValue());
|
|
957 |
| } |
|
958 |
| } |
|
959 |
7
| LISTENERS_TO_REMOVE.clear();
|
|
960 |
| } |
|
961 |
| |
|
962 |
5
| @SuppressWarnings("unchecked")
|
|
963 |
| protected void addNewListeners(Map<OptionParser<?>,String> newValues) { |
|
964 |
5
| for(OptionParser<?> key: newValues.keySet()) {
|
|
965 |
| |
|
966 |
0
| if (key instanceof Option) {
|
|
967 |
0
| DrJava.getConfig().addOptionListener((Option)key, STORED_PREFERENCES_LISTENER);
|
|
968 |
0
| LISTENERS_TO_REMOVE.put(key, STORED_PREFERENCES_LISTENER);
|
|
969 |
| } |
|
970 |
| } |
|
971 |
| } |
|
972 |
| |
|
973 |
| protected static final HashMap<OptionParser<?>, OptionListener<? extends Object>> LISTENERS_TO_REMOVE = |
|
974 |
| new HashMap<OptionParser<?>, OptionListener<? extends Object>>(); |
|
975 |
| |
|
976 |
| public final OptionListener<? extends Object> STORED_PREFERENCES_LISTENER = new OptionListener<Object>() { |
|
977 |
0
| public void optionChanged(OptionEvent<Object> oce) {
|
|
978 |
0
| setProjectChanged(true);
|
|
979 |
| } |
|
980 |
| }; |
|
981 |
| |
|
982 |
161
| protected FileGroupingState makeFlatFileGroupingState() { return new FlatFileGroupingState(); }
|
|
983 |
| |
|
984 |
| class FlatFileGroupingState implements FileGroupingState { |
|
985 |
404
| public File getBuildDirectory() { return FileOps.NULL_FILE; }
|
|
986 |
335
| public File getProjectRoot() { return getWorkingDirectory(); }
|
|
987 |
372
| public File getWorkingDirectory() {
|
|
988 |
| |
|
989 |
372
| File prefWorkDir = DrJava.getConfig().getSetting(FIXED_INTERACTIONS_DIRECTORY);
|
|
990 |
372
| if ((prefWorkDir != null) && (prefWorkDir != FileOps.NULL_FILE)) {
|
|
991 |
0
| try {
|
|
992 |
| |
|
993 |
0
| prefWorkDir = FileOps.getValidDirectory(prefWorkDir);
|
|
994 |
| } |
|
995 |
0
| catch (RuntimeException e) { prefWorkDir = FileOps.NULL_FILE; }
|
|
996 |
| } |
|
997 |
372
| if ((prefWorkDir != null) && (prefWorkDir != FileOps.NULL_FILE)) {
|
|
998 |
| |
|
999 |
0
| DrJava.getConfig().setSetting(LAST_INTERACTIONS_DIRECTORY, prefWorkDir);
|
|
1000 |
0
| return prefWorkDir;
|
|
1001 |
| } |
|
1002 |
| |
|
1003 |
| |
|
1004 |
372
| File file = FileOps.NULL_FILE;
|
|
1005 |
372
| try {
|
|
1006 |
372
| file = getActiveDocument().getSourceRoot();
|
|
1007 |
| } |
|
1008 |
268
| catch(InvalidPackageException ipe) { file = FileOps.NULL_FILE; }
|
|
1009 |
372
| if ((file != null) && (file != FileOps.NULL_FILE)) {
|
|
1010 |
| |
|
1011 |
104
| DrJava.getConfig().setSetting(LAST_INTERACTIONS_DIRECTORY, file);
|
|
1012 |
104
| return file;
|
|
1013 |
| } |
|
1014 |
| |
|
1015 |
| |
|
1016 |
268
| Iterable<File> roots = getSourceRootSet();
|
|
1017 |
35
| if (!IterUtil.isEmpty(roots)) { return IterUtil.first(roots); }
|
|
1018 |
| else { |
|
1019 |
| |
|
1020 |
233
| if (DrJava.getConfig().getSetting(STICKY_INTERACTIONS_DIRECTORY)) {
|
|
1021 |
233
| try {
|
|
1022 |
| |
|
1023 |
233
| file = FileOps.getValidDirectory(DrJava.getConfig().getSetting(LAST_INTERACTIONS_DIRECTORY));
|
|
1024 |
| } |
|
1025 |
0
| catch (RuntimeException e) { file = FileOps.NULL_FILE; }
|
|
1026 |
| } |
|
1027 |
233
| if (file == FileOps.NULL_FILE) {
|
|
1028 |
| |
|
1029 |
0
| file = FileOps.getValidDirectory(new File(System.getProperty("user.home", ".")));
|
|
1030 |
| } |
|
1031 |
| |
|
1032 |
233
| DrJava.getConfig().setSetting(LAST_INTERACTIONS_DIRECTORY, file);
|
|
1033 |
233
| return file;
|
|
1034 |
| } |
|
1035 |
| } |
|
1036 |
153
| public boolean isProjectActive() { return false; }
|
|
1037 |
281
| public boolean inProjectPath(OpenDefinitionsDocument doc) { return false; }
|
|
1038 |
0
| public boolean inProjectPath(File f) { return false; }
|
|
1039 |
0
| public File getProjectFile() { return FileOps.NULL_FILE; }
|
|
1040 |
1
| public void setBuildDirectory(File f) { }
|
|
1041 |
0
| public void setProjectFile(File f) { }
|
|
1042 |
0
| public void setProjectRoot(File f) { }
|
|
1043 |
0
| public void addAuxFile(File f) { }
|
|
1044 |
0
| public void remAuxFile(File f) { }
|
|
1045 |
0
| public void setWorkingDirectory(File f) { }
|
|
1046 |
0
| public File[] getProjectFiles() { return new File[0]; }
|
|
1047 |
91
| public boolean inProject(File f) { return false; }
|
|
1048 |
0
| public String getMainClass() { return null; }
|
|
1049 |
0
| public void setMainClass(String f) { }
|
|
1050 |
0
| public void setCreateJarFile(File f) { }
|
|
1051 |
0
| public File getCreateJarFile() { return FileOps.NULL_FILE; }
|
|
1052 |
0
| public void setCreateJarFlags(int f) { }
|
|
1053 |
0
| public int getCreateJarFlags() { return 0; }
|
|
1054 |
180
| public Iterable<AbsRelFile> getExtraClassPath() { return IterUtil.empty(); }
|
|
1055 |
0
| public void setExtraClassPath(Iterable<AbsRelFile> cp) { }
|
|
1056 |
0
| public boolean isProjectChanged() { return false; }
|
|
1057 |
127
| public void setProjectChanged(boolean changed) { }
|
|
1058 |
256
| public boolean isAuxiliaryFile(File f) { return false; }
|
|
1059 |
22
| public boolean isExcludedFile(File f) { return false; }
|
|
1060 |
0
| public File[] getExclFiles() { return null; }
|
|
1061 |
0
| public void addExcludedFile(File f) { }
|
|
1062 |
0
| public void removeExcludedFile(File f) { }
|
|
1063 |
0
| public void setExcludedFiles(File[] fs) { }
|
|
1064 |
31
| public boolean getAutoRefreshStatus() {return false;}
|
|
1065 |
0
| public void setAutoRefreshStatus(boolean b) { }
|
|
1066 |
0
| public void setPreferencesStoredInProject(Map<OptionParser<?>,String> sp) { }
|
|
1067 |
0
| public Map<OptionParser<?>,String> getPreferencesStoredInProject() { return new HashMap<OptionParser<?>,String>(); }
|
|
1068 |
| |
|
1069 |
0
| public void cleanBuildDirectory() { }
|
|
1070 |
| |
|
1071 |
0
| public List<File> getClassFiles() { return new LinkedList<File>(); }
|
|
1072 |
| |
|
1073 |
0
| public String getCustomManifest() { return null; }
|
|
1074 |
0
| public void setCustomManifest(String manifest) { }
|
|
1075 |
| } |
|
1076 |
| |
|
1077 |
| |
|
1078 |
| |
|
1079 |
| |
|
1080 |
3
| public String getSourceBinTitle() { return "[ Source Files ]"; }
|
|
1081 |
| |
|
1082 |
| |
|
1083 |
| |
|
1084 |
| |
|
1085 |
3
| public String getExternalBinTitle() { return "[ External Files ]"; }
|
|
1086 |
| |
|
1087 |
| |
|
1088 |
| |
|
1089 |
| |
|
1090 |
3
| public String getAuxiliaryBinTitle() { return "[ Included External Files ]"; }
|
|
1091 |
| |
|
1092 |
| |
|
1093 |
| |
|
1094 |
| |
|
1095 |
| |
|
1096 |
| |
|
1097 |
261
| public void addListener(GlobalModelListener listener) { _notifier.addListener(listener); }
|
|
1098 |
| |
|
1099 |
| |
|
1100 |
| |
|
1101 |
| |
|
1102 |
| |
|
1103 |
191
| public void removeListener(GlobalModelListener listener) { _notifier.removeListener(listener); }
|
|
1104 |
| |
|
1105 |
| |
|
1106 |
| |
|
1107 |
38
| public DefinitionsEditorKit getEditorKit() { return _editorKit; }
|
|
1108 |
| |
|
1109 |
| |
|
1110 |
0
| public DefaultInteractionsModel getInteractionsModel() {
|
|
1111 |
0
| throw new UnsupportedOperationException("AbstractGlobalModel does not support interaction");
|
|
1112 |
| } |
|
1113 |
| |
|
1114 |
| |
|
1115 |
0
| public InteractionsDJDocument getSwingInteractionsDocument() {
|
|
1116 |
0
| throw new UnsupportedOperationException("AbstractGlobalModel does not support interaction");
|
|
1117 |
| } |
|
1118 |
| |
|
1119 |
| |
|
1120 |
0
| public InteractionsDocument getInteractionsDocument() {
|
|
1121 |
0
| throw new UnsupportedOperationException("AbstractGlobalModel does not support interaction");
|
|
1122 |
| } |
|
1123 |
| |
|
1124 |
40
| public ConsoleDocument getConsoleDocument() { return _consoleDoc; }
|
|
1125 |
| |
|
1126 |
38
| public InteractionsDJDocument getSwingConsoleDocument() { return _consoleDocAdapter; }
|
|
1127 |
| |
|
1128 |
0
| public PageFormat getPageFormat() { return _pageFormat; }
|
|
1129 |
| |
|
1130 |
0
| public void setPageFormat(PageFormat format) { _pageFormat = format; }
|
|
1131 |
| |
|
1132 |
0
| public CompilerModel getCompilerModel() {
|
|
1133 |
0
| throw new UnsupportedOperationException("AbstractGlobalModel does not support compilation");
|
|
1134 |
| } |
|
1135 |
| |
|
1136 |
| |
|
1137 |
0
| public int getNumCompErrors() {
|
|
1138 |
0
| throw new UnsupportedOperationException("AbstractGlobalModel does not support compilation");
|
|
1139 |
| } |
|
1140 |
| |
|
1141 |
| |
|
1142 |
0
| public void setNumCompErrors(int num) {
|
|
1143 |
0
| throw new UnsupportedOperationException("AbstractGlobalModel does not support compilation");
|
|
1144 |
| }; |
|
1145 |
| |
|
1146 |
| |
|
1147 |
0
| public JUnitModel getJUnitModel() {
|
|
1148 |
0
| throw new UnsupportedOperationException("AbstractGlobalModel does not support unit testing");
|
|
1149 |
| } |
|
1150 |
| |
|
1151 |
| |
|
1152 |
0
| public JavadocModel getJavadocModel() {
|
|
1153 |
0
| throw new UnsupportedOperationException("AbstractGlobalModel does not support javadoc");
|
|
1154 |
| } |
|
1155 |
| |
|
1156 |
205
| public IDocumentNavigator<OpenDefinitionsDocument> getDocumentNavigator() { return _documentNavigator; }
|
|
1157 |
| |
|
1158 |
5
| public void setDocumentNavigator(IDocumentNavigator<OpenDefinitionsDocument> newnav) { _documentNavigator = newnav; }
|
|
1159 |
| |
|
1160 |
| |
|
1161 |
| |
|
1162 |
| |
|
1163 |
8
| public void toggleBookmark(int pos1, int pos2) { _toggleBookmark(pos1, pos2); }
|
|
1164 |
| |
|
1165 |
| |
|
1166 |
| |
|
1167 |
| |
|
1168 |
8
| public void _toggleBookmark(int pos1, int pos2) {
|
|
1169 |
| |
|
1170 |
8
| assert EventQueue.isDispatchThread();
|
|
1171 |
| |
|
1172 |
8
| final OpenDefinitionsDocument doc = getActiveDocument();
|
|
1173 |
| |
|
1174 |
8
| int startSel = Math.min(pos1, pos2);
|
|
1175 |
8
| int endSel = Math.max(pos1, pos2);
|
|
1176 |
| |
|
1177 |
8
| RegionManager<MovingDocumentRegion> bm = _bookmarkManager;
|
|
1178 |
8
| if (startSel == endSel) {
|
|
1179 |
2
| endSel = doc._getLineEndPos(startSel);
|
|
1180 |
2
| startSel = doc._getLineStartPos(startSel);
|
|
1181 |
| } |
|
1182 |
| |
|
1183 |
8
| Collection<MovingDocumentRegion> conflictingRegions = bm.getRegionsOverlapping(doc, startSel, endSel);
|
|
1184 |
| |
|
1185 |
8
| if (conflictingRegions.size() > 0) {
|
|
1186 |
5
| for (MovingDocumentRegion cr: conflictingRegions) bm.removeRegion(cr);
|
|
1187 |
| } |
|
1188 |
| else { |
|
1189 |
5
| MovingDocumentRegion newR =
|
|
1190 |
| new MovingDocumentRegion(doc, startSel, endSel, doc._getLineStartPos(startSel), doc._getLineEndPos(endSel)); |
|
1191 |
5
| bm.addRegion(newR);
|
|
1192 |
| } |
|
1193 |
| } |
|
1194 |
| |
|
1195 |
| |
|
1196 |
| |
|
1197 |
| |
|
1198 |
| |
|
1199 |
| |
|
1200 |
253
| public OpenDefinitionsDocument newFile(File parentDir) { return newFile(parentDir, ""); }
|
|
1201 |
| |
|
1202 |
| |
|
1203 |
| |
|
1204 |
| |
|
1205 |
| |
|
1206 |
| |
|
1207 |
| |
|
1208 |
424
| public OpenDefinitionsDocument newFile(File parentDir, String text) {
|
|
1209 |
| |
|
1210 |
424
| final ConcreteOpenDefDoc doc = _createOpenDefinitionsDocument(new NullFile());
|
|
1211 |
424
| try {
|
|
1212 |
424
| if (text.length() > 0) {
|
|
1213 |
0
| doc.insertString(0, text, null);
|
|
1214 |
0
| doc.indentLines(0, text.length());
|
|
1215 |
| } |
|
1216 |
| } |
|
1217 |
| catch (BadLocationException ble) { |
|
1218 |
0
| throw new UnexpectedException(ble);
|
|
1219 |
| } |
|
1220 |
| finally { |
|
1221 |
424
| doc.setParentDirectory(parentDir);
|
|
1222 |
424
| addDocToNavigator(doc);
|
|
1223 |
424
| _notifier.newFileCreated(doc);
|
|
1224 |
| } |
|
1225 |
424
| return doc;
|
|
1226 |
| } |
|
1227 |
| |
|
1228 |
| |
|
1229 |
| |
|
1230 |
| |
|
1231 |
171
| public OpenDefinitionsDocument newFile(String text) {
|
|
1232 |
171
| File dir = _activeDirectory;
|
|
1233 |
0
| if (dir == null) dir = getMasterWorkingDirectory();
|
|
1234 |
171
| OpenDefinitionsDocument doc = newFile(dir, text);
|
|
1235 |
171
| setActiveDocument(doc);
|
|
1236 |
171
| return doc;
|
|
1237 |
| } |
|
1238 |
| |
|
1239 |
| |
|
1240 |
| |
|
1241 |
| |
|
1242 |
171
| public OpenDefinitionsDocument newFile() { return newFile(""); }
|
|
1243 |
| |
|
1244 |
| |
|
1245 |
| |
|
1246 |
| |
|
1247 |
| |
|
1248 |
| |
|
1249 |
| |
|
1250 |
0
| public OpenDefinitionsDocument newTestCase(String name, boolean makeSetUp, boolean makeTearDown) {
|
|
1251 |
0
| boolean elementary =
|
|
1252 |
| (DrJava.getConfig().getSetting(LANGUAGE_LEVEL) == OptionConstants.ELEMENTARY_LEVEL) || |
|
1253 |
| (DrJava.getConfig().getSetting(LANGUAGE_LEVEL) == OptionConstants.FUNCTIONAL_JAVA_LEVEL); |
|
1254 |
| |
|
1255 |
0
| final StringBuilder buf = new StringBuilder();
|
|
1256 |
0
| if (! elementary) buf.append("import junit.framework.TestCase;\n\n");
|
|
1257 |
0
| buf.append("/**\n");
|
|
1258 |
0
| buf.append("* A JUnit test case class.\n");
|
|
1259 |
0
| buf.append("* Every method starting with the word \"test\" will be called when running\n");
|
|
1260 |
0
| buf.append("* the test with JUnit.\n");
|
|
1261 |
0
| buf.append("*/\n");
|
|
1262 |
0
| if (! elementary) buf.append("public ");
|
|
1263 |
0
| buf.append("class ");
|
|
1264 |
0
| buf.append(name);
|
|
1265 |
0
| buf.append(" extends TestCase {\n\n");
|
|
1266 |
0
| if (makeSetUp) {
|
|
1267 |
0
| buf.append("/**\n");
|
|
1268 |
0
| buf.append("* This method is called before each test method, to perform any common\n");
|
|
1269 |
0
| buf.append("* setup if necessary.\n");
|
|
1270 |
0
| buf.append("*/\n");
|
|
1271 |
0
| if (! elementary) buf.append("public ");
|
|
1272 |
0
| buf.append("void setUp() throws Exception {\n}\n\n");
|
|
1273 |
| } |
|
1274 |
0
| if (makeTearDown) {
|
|
1275 |
0
| buf.append("/**\n");
|
|
1276 |
0
| buf.append("* This method is called after each test method, to perform any common\n");
|
|
1277 |
0
| buf.append("* clean-up if necessary.\n");
|
|
1278 |
0
| buf.append("*/\n");
|
|
1279 |
0
| if (! elementary) buf.append("public ");
|
|
1280 |
0
| buf.append("void tearDown() throws Exception {\n}\n\n");
|
|
1281 |
| } |
|
1282 |
0
| buf.append("/**\n");
|
|
1283 |
0
| buf.append("* A test method.\n");
|
|
1284 |
0
| buf.append("* (Replace \"X\" with a name describing the test. You may write as\n");
|
|
1285 |
0
| buf.append ("* many \"testSomething\" methods in this class as you wish, and each\n");
|
|
1286 |
0
| buf.append("* one will be called when running JUnit over this class.)\n");
|
|
1287 |
0
| buf.append("*/\n");
|
|
1288 |
0
| if (! elementary) buf.append("public ");
|
|
1289 |
0
| buf.append("void testX() {\n}\n\n");
|
|
1290 |
0
| buf.append("}\n");
|
|
1291 |
0
| String test = buf.toString();
|
|
1292 |
| |
|
1293 |
0
| OpenDefinitionsDocument openDoc = newFile();
|
|
1294 |
0
| try {
|
|
1295 |
0
| openDoc.insertString(0, test, null);
|
|
1296 |
0
| openDoc.indentLines(0, test.length());
|
|
1297 |
| } |
|
1298 |
| catch (BadLocationException ble) { |
|
1299 |
0
| throw new UnexpectedException(ble);
|
|
1300 |
| } |
|
1301 |
0
| return openDoc;
|
|
1302 |
| } |
|
1303 |
| |
|
1304 |
| |
|
1305 |
7
| public DocumentCache getDocumentCache() { return _cache; }
|
|
1306 |
| |
|
1307 |
| |
|
1308 |
| |
|
1309 |
| |
|
1310 |
| |
|
1311 |
| |
|
1312 |
| |
|
1313 |
| |
|
1314 |
| |
|
1315 |
| |
|
1316 |
| |
|
1317 |
| |
|
1318 |
41
| public OpenDefinitionsDocument openFile(FileOpenSelector com) throws
|
|
1319 |
| IOException, OperationCanceledException, AlreadyOpenException { |
|
1320 |
| |
|
1321 |
41
| boolean closeUntitled = _hasOneEmptyDocument();
|
|
1322 |
20
| if (! closeUntitled) addToBrowserHistory();
|
|
1323 |
| |
|
1324 |
41
| OpenDefinitionsDocument oldDoc = _activeDocument;
|
|
1325 |
41
| OpenDefinitionsDocument openedDoc = openFileHelper(com);
|
|
1326 |
19
| if (closeUntitled) closeFileHelper(oldDoc);
|
|
1327 |
| |
|
1328 |
| |
|
1329 |
29
| setActiveDocument(openedDoc);
|
|
1330 |
29
| setProjectChanged(true);
|
|
1331 |
| |
|
1332 |
29
| return openedDoc;
|
|
1333 |
| } |
|
1334 |
| |
|
1335 |
58
| protected OpenDefinitionsDocument openFileHelper(FileOpenSelector com) throws IOException,
|
|
1336 |
| OperationCanceledException, AlreadyOpenException { |
|
1337 |
| |
|
1338 |
| |
|
1339 |
58
| final File file = (com.getFiles())[0].getCanonicalFile();
|
|
1340 |
57
| OpenDefinitionsDocument odd = _openFile(file);
|
|
1341 |
| |
|
1342 |
| |
|
1343 |
46
| addDocToClassPath(odd);
|
|
1344 |
46
| setClassPathChanged(true);
|
|
1345 |
46
| return odd;
|
|
1346 |
| } |
|
1347 |
| |
|
1348 |
| |
|
1349 |
| |
|
1350 |
| |
|
1351 |
| |
|
1352 |
| |
|
1353 |
| |
|
1354 |
| |
|
1355 |
| |
|
1356 |
| |
|
1357 |
| |
|
1358 |
16
| public OpenDefinitionsDocument[] openFiles(FileOpenSelector com)
|
|
1359 |
| throws IOException, OperationCanceledException, AlreadyOpenException { |
|
1360 |
| |
|
1361 |
| |
|
1362 |
16
| boolean closeUntitled = _hasOneEmptyDocument();
|
|
1363 |
2
| if (! closeUntitled) addToBrowserHistory();
|
|
1364 |
16
| OpenDefinitionsDocument oldDoc = _activeDocument;
|
|
1365 |
| |
|
1366 |
16
| OpenDefinitionsDocument[] openedDocs = openFilesHelper(com);
|
|
1367 |
13
| if (openedDocs.length > 0) {
|
|
1368 |
12
| if (closeUntitled) closeFileHelper(oldDoc);
|
|
1369 |
| |
|
1370 |
13
| setActiveDocument(openedDocs[0]);
|
|
1371 |
| } |
|
1372 |
13
| return openedDocs;
|
|
1373 |
| } |
|
1374 |
| |
|
1375 |
16
| protected OpenDefinitionsDocument[] openFilesHelper(FileOpenSelector com)
|
|
1376 |
| throws IOException, OperationCanceledException, AlreadyOpenException { |
|
1377 |
| |
|
1378 |
16
| final File[] files = com.getFiles();
|
|
1379 |
1
| if (files == null) { throw new IOException("No Files returned from FileSelector"); }
|
|
1380 |
14
| OpenDefinitionsDocument[] docs = _openFiles(files);
|
|
1381 |
13
| return docs;
|
|
1382 |
| } |
|
1383 |
| |
|
1384 |
| |
|
1385 |
| |
|
1386 |
| |
|
1387 |
| |
|
1388 |
| |
|
1389 |
| |
|
1390 |
14
| private OpenDefinitionsDocument[] _openFiles(File[] files)
|
|
1391 |
| throws IOException, OperationCanceledException, AlreadyOpenException { |
|
1392 |
| |
|
1393 |
14
| ArrayList<OpenDefinitionsDocument> alreadyOpenDocuments = new ArrayList<OpenDefinitionsDocument>();
|
|
1394 |
14
| ArrayList<OpenDefinitionsDocument> retDocs = new ArrayList<OpenDefinitionsDocument>();
|
|
1395 |
| |
|
1396 |
| |
|
1397 |
| |
|
1398 |
14
| LinkedList<File> filesNotFound = new LinkedList<File>();
|
|
1399 |
14
| LinkedList<OpenDefinitionsDocument> filesOpened = new LinkedList<OpenDefinitionsDocument>();
|
|
1400 |
14
| for (final File f: files) {
|
|
1401 |
1
| if (f == null) throw new IOException("File name returned from FileSelector is null");
|
|
1402 |
30
| try {
|
|
1403 |
30
| OpenDefinitionsDocument d = _rawOpenFile(IOUtil.attemptCanonicalFile(f));
|
|
1404 |
| |
|
1405 |
29
| retDocs.add(d);
|
|
1406 |
29
| filesOpened.add(d);
|
|
1407 |
29
| if(_state.isExcludedFile(f))
|
|
1408 |
0
| _state.removeExcludedFile(f);
|
|
1409 |
| } |
|
1410 |
| catch (AlreadyOpenException aoe) { |
|
1411 |
0
| OpenDefinitionsDocument d = aoe.getOpenDocument();
|
|
1412 |
0
| retDocs.add(d);
|
|
1413 |
0
| alreadyOpenDocuments.add(d);
|
|
1414 |
| } |
|
1415 |
1
| catch(FileNotFoundException e) { filesNotFound.add(f); }
|
|
1416 |
| } |
|
1417 |
| |
|
1418 |
13
| for (final OpenDefinitionsDocument d: filesOpened) {
|
|
1419 |
29
| _completeOpenFile(d);
|
|
1420 |
| } |
|
1421 |
| |
|
1422 |
13
| if (filesNotFound.size() > 0)
|
|
1423 |
1
| _notifier.filesNotFound( filesNotFound.toArray( new File[filesNotFound.size()] ) );
|
|
1424 |
| |
|
1425 |
13
| if (! alreadyOpenDocuments.isEmpty()) {
|
|
1426 |
0
| for(OpenDefinitionsDocument d : alreadyOpenDocuments) {
|
|
1427 |
0
| _notifier.handleAlreadyOpenDocument(d);
|
|
1428 |
0
| _notifier.fileOpened(d);
|
|
1429 |
| } |
|
1430 |
| } |
|
1431 |
| |
|
1432 |
13
| if (retDocs != null) {
|
|
1433 |
13
| return retDocs.toArray(new OpenDefinitionsDocument[0]);
|
|
1434 |
| } |
|
1435 |
| else { |
|
1436 |
| |
|
1437 |
0
| throw new OperationCanceledException();
|
|
1438 |
| } |
|
1439 |
| } |
|
1440 |
| |
|
1441 |
| |
|
1442 |
| |
|
1443 |
| |
|
1444 |
| |
|
1445 |
| |
|
1446 |
| |
|
1447 |
0
| public void openFolder(File dir, boolean rec, String ext)
|
|
1448 |
| throws IOException, OperationCanceledException, AlreadyOpenException { |
|
1449 |
0
| debug.logStart();
|
|
1450 |
| |
|
1451 |
0
| final File[] sfiles = getFilesInFolder(dir, rec, ext);
|
|
1452 |
0
| if(sfiles == null) return;
|
|
1453 |
0
| openFiles(new FileOpenSelector() { public File[] getFiles() { return sfiles; } });
|
|
1454 |
| |
|
1455 |
0
| if (sfiles.length > 0 && _state.inProjectPath(dir)) setProjectChanged(true);
|
|
1456 |
| |
|
1457 |
0
| debug.logEnd();
|
|
1458 |
| } |
|
1459 |
| |
|
1460 |
| |
|
1461 |
0
| public String getOpenAllFilesInFolderExtension() {
|
|
1462 |
0
| CompilerModel cm = getCompilerModel();
|
|
1463 |
0
| if (cm==null) {
|
|
1464 |
0
| return OptionConstants.LANGUAGE_LEVEL_EXTENSIONS[DrJava.getConfig().getSetting(LANGUAGE_LEVEL)];
|
|
1465 |
| } |
|
1466 |
| else { |
|
1467 |
0
| return cm.getActiveCompiler().getOpenAllFilesInFolderExtension();
|
|
1468 |
| } |
|
1469 |
| } |
|
1470 |
| |
|
1471 |
0
| public File[] getFilesInFolder(File dir, boolean rec, String ext) throws IOException, OperationCanceledException,
|
|
1472 |
| AlreadyOpenException { |
|
1473 |
| |
|
1474 |
0
| if (dir == null || !dir.isDirectory()) return null;
|
|
1475 |
| |
|
1476 |
0
| Iterable<File> filesIterable;
|
|
1477 |
| |
|
1478 |
0
| String extension = ext.substring(1);
|
|
1479 |
| |
|
1480 |
0
| Predicate<File> match = LambdaUtil.and(IOUtil.IS_FILE, IOUtil.extensionFilePredicate(extension));
|
|
1481 |
0
| if (rec) { filesIterable = IOUtil.listFilesRecursively(dir, match); }
|
|
1482 |
0
| else { filesIterable = IOUtil.attemptListFilesAsIterable(dir, match); }
|
|
1483 |
0
| List<File> files = CollectUtil.makeList(filesIterable);
|
|
1484 |
| |
|
1485 |
0
| if (isProjectActive()) {
|
|
1486 |
0
| Collections.sort(files, new Comparator<File>() {
|
|
1487 |
0
| public int compare(File o1,File o2) {
|
|
1488 |
0
| return - o1.getAbsolutePath().compareTo(o2.getAbsolutePath());
|
|
1489 |
| } |
|
1490 |
| }); |
|
1491 |
| } |
|
1492 |
| else { |
|
1493 |
0
| Collections.sort(files, new Comparator<File>() {
|
|
1494 |
0
| public int compare(File o1,File o2) {
|
|
1495 |
0
| return - o1.getName().compareTo(o2.getName());
|
|
1496 |
| } |
|
1497 |
| }); |
|
1498 |
| } |
|
1499 |
0
| int ct = files.size();
|
|
1500 |
| |
|
1501 |
0
| return files.toArray(new File[ct]);
|
|
1502 |
| } |
|
1503 |
| |
|
1504 |
| |
|
1505 |
| |
|
1506 |
| |
|
1507 |
0
| public File[] getNewFilesInProject() {
|
|
1508 |
| |
|
1509 |
0
| ArrayList<File> files = new ArrayList<File>();
|
|
1510 |
0
| File projRoot = _state.getProjectRoot();
|
|
1511 |
0
| if(projRoot == null)
|
|
1512 |
0
| return null;
|
|
1513 |
0
| File[] allFiles;
|
|
1514 |
0
| try {
|
|
1515 |
0
| allFiles = getFilesInFolder(projRoot, true, getOpenAllFilesInFolderExtension());
|
|
1516 |
0
| } catch(IOException e) { return null; }
|
|
1517 |
0
| catch(OperationCanceledException e) { return null; }
|
|
1518 |
0
| catch(AlreadyOpenException e) { return null; }
|
|
1519 |
| |
|
1520 |
0
| for(File f : allFiles) {
|
|
1521 |
0
| if(!isAlreadyOpen(f) && !_state.isExcludedFile(f)) {
|
|
1522 |
0
| files.add(f);
|
|
1523 |
| } |
|
1524 |
| } |
|
1525 |
| |
|
1526 |
0
| return files.toArray(new File[files.size()]);
|
|
1527 |
| } |
|
1528 |
| |
|
1529 |
| |
|
1530 |
| |
|
1531 |
0
| public void openNewFilesInProject() {
|
|
1532 |
0
| File[] newFiles = getNewFilesInProject();
|
|
1533 |
0
| if (newFiles == null) return;
|
|
1534 |
0
| try { _openFiles(newFiles); }
|
|
1535 |
| catch(Exception e) { } |
|
1536 |
| } |
|
1537 |
| |
|
1538 |
| |
|
1539 |
| |
|
1540 |
| |
|
1541 |
| |
|
1542 |
| |
|
1543 |
| |
|
1544 |
4
| public void saveAllFiles(FileSaveSelector com) throws IOException {
|
|
1545 |
| |
|
1546 |
4
| saveAllFilesHelper(com);
|
|
1547 |
4
| refreshActiveDocument();
|
|
1548 |
| } |
|
1549 |
| |
|
1550 |
| |
|
1551 |
4
| protected void saveAllFilesHelper(FileSaveSelector com) throws IOException {
|
|
1552 |
4
| boolean first = true;
|
|
1553 |
4
| boolean isProjActive = isProjectActive();
|
|
1554 |
| |
|
1555 |
4
| List<OpenDefinitionsDocument> docsToWrite = getOpenDefinitionsDocuments();
|
|
1556 |
4
| while(docsToWrite.size() > 0) {
|
|
1557 |
4
| ArrayList<OpenDefinitionsDocument> readOnlyDocs = new ArrayList<OpenDefinitionsDocument>();
|
|
1558 |
4
| for (final OpenDefinitionsDocument doc: docsToWrite) {
|
|
1559 |
| |
|
1560 |
2
| if (doc.isUntitled() && (isProjActive || ! doc.isModifiedSinceSave())) continue;
|
|
1561 |
7
| try {
|
|
1562 |
7
| final File docFile = doc.getFile();
|
|
1563 |
7
| if (docFile == null || !docFile.exists() || docFile.canWrite()) {
|
|
1564 |
| |
|
1565 |
7
| aboutToSaveFromSaveAll(doc);
|
|
1566 |
7
| doc.saveFile(com);
|
|
1567 |
| } |
|
1568 |
0
| else if (first) {
|
|
1569 |
| |
|
1570 |
0
| readOnlyDocs.add(doc);
|
|
1571 |
| } |
|
1572 |
| } |
|
1573 |
| catch(FileMovedException fme) { |
|
1574 |
| |
|
1575 |
0
| aboutToSaveFromSaveAll(doc);
|
|
1576 |
0
| doc.saveFile(com);
|
|
1577 |
| } |
|
1578 |
| } |
|
1579 |
4
| docsToWrite.clear();
|
|
1580 |
4
| if (readOnlyDocs.size() > 0) {
|
|
1581 |
0
| ArrayList<File> files = new ArrayList<File>();
|
|
1582 |
0
| for(OpenDefinitionsDocument odd: readOnlyDocs) {
|
|
1583 |
0
| try {
|
|
1584 |
0
| File roFile = odd.getFile();
|
|
1585 |
0
| files.add(roFile);
|
|
1586 |
| } |
|
1587 |
| catch(FileMovedException fme) { } |
|
1588 |
| } |
|
1589 |
0
| File[] res = _notifier.filesReadOnly(files.toArray(new File[files.size()]));
|
|
1590 |
0
| HashSet<File> rewriteFiles = new HashSet<File>(java.util.Arrays.asList(res));
|
|
1591 |
0
| for(OpenDefinitionsDocument odd: readOnlyDocs) {
|
|
1592 |
0
| File roFile = odd.getFile();
|
|
1593 |
0
| if (rewriteFiles.contains(roFile)) {
|
|
1594 |
0
| docsToWrite.add(odd);
|
|
1595 |
0
| FileOps.makeWritable(roFile);
|
|
1596 |
| } |
|
1597 |
| } |
|
1598 |
| } |
|
1599 |
4
| first = false;
|
|
1600 |
| } |
|
1601 |
| } |
|
1602 |
| |
|
1603 |
| |
|
1604 |
| |
|
1605 |
| |
|
1606 |
0
| public void createNewProject(File projFile) { setFileGroupingState(new ProjectFileGroupingState(projFile)); }
|
|
1607 |
| |
|
1608 |
| |
|
1609 |
0
| public void configNewProject() throws IOException {
|
|
1610 |
| |
|
1611 |
0
| assert EventQueue.isDispatchThread();
|
|
1612 |
| |
|
1613 |
| |
|
1614 |
0
| File projFile = getProjectFile();
|
|
1615 |
| |
|
1616 |
0
| ProjectProfile builder = new ProjectProfile(projFile);
|
|
1617 |
| |
|
1618 |
| |
|
1619 |
0
| File projectRoot = builder.getProjectRoot();
|
|
1620 |
| |
|
1621 |
| |
|
1622 |
| |
|
1623 |
| |
|
1624 |
| |
|
1625 |
0
| for (OpenDefinitionsDocument doc: getOpenDefinitionsDocuments()) {
|
|
1626 |
| |
|
1627 |
0
| File f = doc.getFile();
|
|
1628 |
| |
|
1629 |
0
| if (!doc.isUntitled()) {
|
|
1630 |
0
| if (IOUtil.isMember(f, projectRoot)) {
|
|
1631 |
0
| DocFile file = new DocFile(f);
|
|
1632 |
0
| file.setPackage(doc.getPackageName());
|
|
1633 |
0
| builder.addSourceFile(file);
|
|
1634 |
| } |
|
1635 |
0
| else if ( doc.isAuxiliaryFile()) {
|
|
1636 |
0
| DocFile file = new DocFile(f);
|
|
1637 |
0
| file.setPackage(doc.getPackageName());
|
|
1638 |
0
| builder.addAuxiliaryFile(new DocFile(f));
|
|
1639 |
| } |
|
1640 |
| } |
|
1641 |
| } |
|
1642 |
| |
|
1643 |
| |
|
1644 |
0
| builder.write();
|
|
1645 |
| |
|
1646 |
0
| _loadProject(builder);
|
|
1647 |
| } |
|
1648 |
| |
|
1649 |
| |
|
1650 |
| |
|
1651 |
| |
|
1652 |
| |
|
1653 |
1
| @SuppressWarnings("unchecked")
|
|
1654 |
| public ProjectProfile _makeProjectProfile(File file, HashMap<OpenDefinitionsDocument, DocumentInfoGetter> info) |
|
1655 |
| throws IOException { |
|
1656 |
1
| ProjectProfile builder = new ProjectProfile(file);
|
|
1657 |
| |
|
1658 |
| |
|
1659 |
1
| File pr = getProjectRoot();
|
|
1660 |
1
| if (pr != null) builder.setProjectRoot(pr);
|
|
1661 |
| |
|
1662 |
| |
|
1663 |
1
| for (OpenDefinitionsDocument doc: getOpenDefinitionsDocuments()) {
|
|
1664 |
3
| if (doc.inProjectPath()) {
|
|
1665 |
2
| DocumentInfoGetter g = info.get(doc);
|
|
1666 |
2
| builder.addSourceFile(g);
|
|
1667 |
| } |
|
1668 |
1
| else if (doc.isAuxiliaryFile()) {
|
|
1669 |
1
| DocumentInfoGetter g = info.get(doc);
|
|
1670 |
1
| builder.addAuxiliaryFile(g);
|
|
1671 |
| } |
|
1672 |
| } |
|
1673 |
| |
|
1674 |
| |
|
1675 |
1
| if (_documentNavigator instanceof JTreeSortNavigator<?>) {
|
|
1676 |
1
| String[] paths = ((JTreeSortNavigator<?>)_documentNavigator).getCollapsedPaths();
|
|
1677 |
0
| for (String s : paths) { builder.addCollapsedPath(s); }
|
|
1678 |
| } |
|
1679 |
| |
|
1680 |
1
| Iterable<AbsRelFile> exCp = getExtraClassPath();
|
|
1681 |
1
| if (exCp != null) {
|
|
1682 |
0
| for (AbsRelFile f : exCp) { builder.addClassPathFile(f); }
|
|
1683 |
| } |
|
1684 |
| |
|
1685 |
| |
|
1686 |
| |
|
1687 |
1
| File bd = getBuildDirectory();
|
|
1688 |
0
| if (bd != FileOps.NULL_FILE) builder.setBuildDirectory(bd);
|
|
1689 |
| |
|
1690 |
| |
|
1691 |
1
| File wd = getWorkingDirectory();
|
|
1692 |
1
| if (wd != FileOps.NULL_FILE) builder.setWorkingDirectory(wd);
|
|
1693 |
| |
|
1694 |
| |
|
1695 |
1
| String mainClass = getMainClass();
|
|
1696 |
0
| if (mainClass != null) builder.setMainClass(mainClass);
|
|
1697 |
| |
|
1698 |
| |
|
1699 |
1
| File createJarFile = getCreateJarFile();
|
|
1700 |
1
| if (createJarFile != null) builder.setCreateJarFile(createJarFile);
|
|
1701 |
| |
|
1702 |
1
| int createJarFlags = getCreateJarFlags();
|
|
1703 |
0
| if (createJarFlags != 0) builder.setCreateJarFlags (createJarFlags);
|
|
1704 |
| |
|
1705 |
| |
|
1706 |
1
| ArrayList<DebugBreakpointData> l = new ArrayList<DebugBreakpointData>();
|
|
1707 |
1
| for (OpenDefinitionsDocument odd: _breakpointManager.getDocuments()) {
|
|
1708 |
0
| for(Breakpoint bp: _breakpointManager.getRegions(odd)) { l.add(bp); }
|
|
1709 |
| } |
|
1710 |
1
| builder.setBreakpoints(l);
|
|
1711 |
1
| try { builder.setWatches(getDebugger().getWatches()); }
|
|
1712 |
| catch(DebugException de) { } |
|
1713 |
| |
|
1714 |
| |
|
1715 |
1
| builder.setBookmarks(_bookmarkManager.getFileRegions());
|
|
1716 |
| |
|
1717 |
1
| builder.setAutoRefreshStatus(_state.getAutoRefreshStatus());
|
|
1718 |
| |
|
1719 |
| |
|
1720 |
0
| for(File f: _state.getExclFiles()) { builder.addExcludedFile(f); }
|
|
1721 |
| |
|
1722 |
| |
|
1723 |
1
| builder.setCustomManifest(_state.getCustomManifest());
|
|
1724 |
| |
|
1725 |
| |
|
1726 |
1
| Map<OptionParser<?>,String> sp = _state.getPreferencesStoredInProject();
|
|
1727 |
1
| for(OptionParser<?> key: sp.keySet()) {
|
|
1728 |
0
| sp.put(key, DrJava.getConfig().getOptionMap().getString(key));
|
|
1729 |
| } |
|
1730 |
1
| builder.setPreferencesStoredInProject(sp);
|
|
1731 |
1
| _state.setPreferencesStoredInProject(sp);
|
|
1732 |
| |
|
1733 |
1
| return builder;
|
|
1734 |
| } |
|
1735 |
| |
|
1736 |
| |
|
1737 |
| |
|
1738 |
| |
|
1739 |
1
| public void saveProject(File file, HashMap<OpenDefinitionsDocument, DocumentInfoGetter> info) throws IOException {
|
|
1740 |
| |
|
1741 |
1
| if (file.exists() && !file.canWrite()) {
|
|
1742 |
0
| File[] res = _notifier.filesReadOnly(new File[] {file});
|
|
1743 |
0
| for(File roFile: res) {
|
|
1744 |
0
| FileOps.makeWritable(roFile);
|
|
1745 |
| } |
|
1746 |
0
| if (res.length == 0) { return; }
|
|
1747 |
| } |
|
1748 |
| |
|
1749 |
1
| ProjectProfile builder = _makeProjectProfile(file, info);
|
|
1750 |
| |
|
1751 |
1
| builder.write();
|
|
1752 |
| |
|
1753 |
| |
|
1754 |
| |
|
1755 |
| |
|
1756 |
| |
|
1757 |
| |
|
1758 |
1
| setFileGroupingState(makeProjectFileGroupingState(builder.getProjectRoot(), builder.getMainClass(),
|
|
1759 |
| builder.getBuildDirectory(), builder.getWorkingDirectory(), file, |
|
1760 |
| builder.getSourceFiles(), builder.getAuxiliaryFiles(), |
|
1761 |
| builder.getExcludedFiles(), |
|
1762 |
| builder.getClassPaths(), builder.getCreateJarFile(), |
|
1763 |
| builder.getCreateJarFlags(), builder.getAutoRefreshStatus(), |
|
1764 |
| builder.getCustomManifest(), |
|
1765 |
| builder.getPreferencesStoredInProject())); |
|
1766 |
| } |
|
1767 |
| |
|
1768 |
| |
|
1769 |
| |
|
1770 |
| |
|
1771 |
0
| public void exportOldProject(File file, HashMap<OpenDefinitionsDocument,DocumentInfoGetter> info) throws IOException {
|
|
1772 |
0
| ProjectProfile builder = _makeProjectProfile(file, info);
|
|
1773 |
| |
|
1774 |
| |
|
1775 |
0
| builder.writeOld();
|
|
1776 |
| |
|
1777 |
| |
|
1778 |
| |
|
1779 |
| |
|
1780 |
| |
|
1781 |
| |
|
1782 |
0
| setFileGroupingState(makeProjectFileGroupingState(builder.getProjectRoot(), builder.getMainClass (),
|
|
1783 |
| builder.getBuildDirectory(), builder.getWorkingDirectory(), file, |
|
1784 |
| builder.getSourceFiles(), builder.getAuxiliaryFiles(), |
|
1785 |
| builder.getExcludedFiles(), |
|
1786 |
| builder.getClassPaths(), builder.getCreateJarFile(), |
|
1787 |
| builder.getCreateJarFlags(), builder.getAutoRefreshStatus(), |
|
1788 |
| builder.getCustomManifest(), |
|
1789 |
| builder.getPreferencesStoredInProject())); |
|
1790 |
| } |
|
1791 |
| |
|
1792 |
0
| public void reloadProject(File file, HashMap<OpenDefinitionsDocument, DocumentInfoGetter> info) throws IOException {
|
|
1793 |
0
| boolean projChanged = isProjectChanged();
|
|
1794 |
0
| ProjectProfile builder = _makeProjectProfile(file, info);
|
|
1795 |
0
| _loadProject(builder);
|
|
1796 |
0
| setProjectChanged(projChanged);
|
|
1797 |
| } |
|
1798 |
| |
|
1799 |
| |
|
1800 |
| |
|
1801 |
| |
|
1802 |
| |