|
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; |
|
38 |
| |
|
39 |
| import static edu.rice.cs.drjava.config.OptionConstants.*; |
|
40 |
| |
|
41 |
| import java.io.*; |
|
42 |
| import java.util.ArrayList; |
|
43 |
| import java.util.LinkedList; |
|
44 |
| import java.util.List; |
|
45 |
| |
|
46 |
| import javax.swing.JOptionPane; |
|
47 |
| |
|
48 |
| import edu.rice.cs.drjava.config.ResourceBundleConfiguration; |
|
49 |
| import edu.rice.cs.drjava.config.FileConfiguration; |
|
50 |
| import edu.rice.cs.drjava.config.OptionConstants; |
|
51 |
| import edu.rice.cs.drjava.platform.PlatformFactory; |
|
52 |
| import edu.rice.cs.drjava.ui.DrJavaErrorHandler; |
|
53 |
| import edu.rice.cs.plt.concurrent.DelayedInterrupter; |
|
54 |
| import edu.rice.cs.plt.concurrent.JVMBuilder; |
|
55 |
| import edu.rice.cs.plt.reflect.JavaVersion; |
|
56 |
| import edu.rice.cs.util.ArgumentTokenizer; |
|
57 |
| import edu.rice.cs.util.Log; |
|
58 |
| import edu.rice.cs.util.UnexpectedException; |
|
59 |
| import edu.rice.cs.util.FileOps; |
|
60 |
| import edu.rice.cs.drjava.model.DrJavaFileUtils; |
|
61 |
| |
|
62 |
| import static edu.rice.cs.plt.debug.DebugUtil.debug; |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
| |
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
| |
|
107 |
| public class DrJava { |
|
108 |
| public static volatile Log _log = new Log("DrJava.txt", false); |
|
109 |
| |
|
110 |
| private static final String DEFAULT_MAX_HEAP_SIZE_ARG = "-Xmx128M"; |
|
111 |
| |
|
112 |
| private static final ArrayList<String> _filesToOpen = new ArrayList<String>(); |
|
113 |
| private static final ArrayList<String> _jvmArgs = new ArrayList<String>(); |
|
114 |
| |
|
115 |
| static volatile boolean _showDebugConsole = false; |
|
116 |
| |
|
117 |
| |
|
118 |
| |
|
119 |
| static volatile boolean _forceNewInstance = false; |
|
120 |
| |
|
121 |
| |
|
122 |
| static volatile boolean _doRestart = false; |
|
123 |
| |
|
124 |
| |
|
125 |
| static volatile boolean _alreadyRestarted = false; |
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
| static volatile boolean _restartedDrJavaUsesRemoteControl = true; |
|
130 |
| |
|
131 |
| |
|
132 |
| private static final int WAIT_BEFORE_DECLARING_SUCCESS = 5000; |
|
133 |
| |
|
134 |
| |
|
135 |
| private static final int NUM_REMOTE_CONTROL_RETRIES = 15; |
|
136 |
| |
|
137 |
| |
|
138 |
| private static final int WAIT_BEFORE_REMOTE_CONTROL_RETRY = 500; |
|
139 |
| |
|
140 |
| |
|
141 |
| |
|
142 |
| |
|
143 |
| |
|
144 |
| |
|
145 |
| public static final File DEFAULT_PROPERTIES_FILE = new File(System.getProperty("user.home"), ".drjava"); |
|
146 |
| |
|
147 |
| |
|
148 |
| private static volatile File _propertiesFile = DEFAULT_PROPERTIES_FILE; |
|
149 |
| |
|
150 |
| |
|
151 |
| |
|
152 |
| private static volatile FileConfiguration _config; |
|
153 |
| |
|
154 |
| |
|
155 |
| public static final String RESOURCE_BUNDLE_NAME = "edu.rice.cs.drjava.config.options"; |
|
156 |
| |
|
157 |
| |
|
158 |
38
| public static File getPropertiesFile() { return _propertiesFile; }
|
|
159 |
| |
|
160 |
| |
|
161 |
274645
| public static synchronized FileConfiguration getConfig() {
|
|
162 |
274645
| if (_config == null) {
|
|
163 |
4
| _config = _initConfig();
|
|
164 |
| } |
|
165 |
274645
| return _config;
|
|
166 |
| } |
|
167 |
| |
|
168 |
| |
|
169 |
0
| public static synchronized String[] getFilesToOpen() { return _filesToOpen.toArray(new String[0]); }
|
|
170 |
| |
|
171 |
| |
|
172 |
0
| public static synchronized void addFileToOpen(String s) {
|
|
173 |
0
| _filesToOpen.add(s);
|
|
174 |
0
| boolean isProjectFile =
|
|
175 |
| s.endsWith(OptionConstants.PROJECT_FILE_EXTENSION) || |
|
176 |
| s.endsWith(OptionConstants.PROJECT_FILE_EXTENSION2) || |
|
177 |
| s.endsWith(OptionConstants.OLD_PROJECT_FILE_EXTENSION); |
|
178 |
0
| _forceNewInstance |= isProjectFile;
|
|
179 |
0
| if (_doRestart && _alreadyRestarted) {
|
|
180 |
0
| _log.log("addFileToOpen: already done the restart, trying to use remote control");
|
|
181 |
| |
|
182 |
0
| if (DrJava.getConfig().getSetting(OptionConstants.REMOTE_CONTROL_ENABLED)) {
|
|
183 |
0
| _log.log("\tremote control...");
|
|
184 |
0
| openWithRemoteControl(_filesToOpen,NUM_REMOTE_CONTROL_RETRIES );
|
|
185 |
0
| _log.log("\tclearing _filesToOpen");
|
|
186 |
0
| clearFilesToOpen();
|
|
187 |
| } |
|
188 |
| } |
|
189 |
| } |
|
190 |
| |
|
191 |
| |
|
192 |
833
| public static synchronized void clearFilesToOpen() {
|
|
193 |
833
| _filesToOpen.clear();
|
|
194 |
| } |
|
195 |
| |
|
196 |
| |
|
197 |
| |
|
198 |
| |
|
199 |
| |
|
200 |
| |
|
201 |
| |
|
202 |
| |
|
203 |
0
| public static synchronized boolean openWithRemoteControl(ArrayList<String> files, int numAttempts) {
|
|
204 |
0
| if (! DrJava.getConfig().getSetting(OptionConstants.REMOTE_CONTROL_ENABLED) ||
|
|
205 |
| ! _restartedDrJavaUsesRemoteControl || |
|
206 |
0
| files.size() == 0) return false;
|
|
207 |
| |
|
208 |
0
| ArrayList<String> fs = new ArrayList<String>(files);
|
|
209 |
0
| int failCount = 0;
|
|
210 |
0
| while(failCount<numAttempts) {
|
|
211 |
0
| try {
|
|
212 |
0
| RemoteControlClient.openFile(null);
|
|
213 |
0
| if (RemoteControlClient.isServerRunning()) {
|
|
214 |
| |
|
215 |
0
| for (int i = 0; i < fs.size(); ++i) {
|
|
216 |
0
| _log.log("opening with remote control "+fs.get(i));
|
|
217 |
0
| RemoteControlClient.openFile(new File(fs.get(i)));
|
|
218 |
0
| files.remove(fs.get(i));
|
|
219 |
| } |
|
220 |
0
| return true;
|
|
221 |
| } |
|
222 |
| else { |
|
223 |
0
| ++failCount;
|
|
224 |
0
| _log.log("Failed to open with remote control, attempt "+failCount+" of "+NUM_REMOTE_CONTROL_RETRIES);
|
|
225 |
0
| if (failCount>=numAttempts) return false;
|
|
226 |
0
| try { Thread.sleep(WAIT_BEFORE_REMOTE_CONTROL_RETRY); }
|
|
227 |
| catch(InterruptedException ie) { } |
|
228 |
| } |
|
229 |
| } |
|
230 |
0
| catch(IOException ioe) { ioe.printStackTrace(); }
|
|
231 |
| } |
|
232 |
0
| return false;
|
|
233 |
| } |
|
234 |
| |
|
235 |
| |
|
236 |
0
| public static boolean getShowDebugConsole() { return _showDebugConsole; }
|
|
237 |
| |
|
238 |
| |
|
239 |
| |
|
240 |
| |
|
241 |
0
| public static void main(final String[] args) {
|
|
242 |
| |
|
243 |
0
| if (handleCommandLineArgs(args)) {
|
|
244 |
| |
|
245 |
0
| PlatformFactory.ONLY.beforeUISetup();
|
|
246 |
| |
|
247 |
| |
|
248 |
0
| configureAndLoadDrJavaRoot(args);
|
|
249 |
| } |
|
250 |
| } |
|
251 |
| |
|
252 |
0
| public static void configureAndLoadDrJavaRoot(String[] args) {
|
|
253 |
0
| try {
|
|
254 |
| |
|
255 |
| |
|
256 |
0
| if (!_forceNewInstance &&
|
|
257 |
| DrJava.getConfig().getSetting(OptionConstants.REMOTE_CONTROL_ENABLED) && |
|
258 |
| (_filesToOpen.size() > 0)) { |
|
259 |
0
| if (openWithRemoteControl(_filesToOpen,1)) System.exit(0);
|
|
260 |
| } |
|
261 |
| |
|
262 |
| |
|
263 |
| |
|
264 |
| |
|
265 |
| |
|
266 |
0
| int failCount = 0;
|
|
267 |
0
| while(failCount < 2) {
|
|
268 |
| |
|
269 |
0
| String masterMemory = getConfig().getSetting(MASTER_JVM_XMX).trim();
|
|
270 |
0
| boolean _doRestart = (getConfig().getSetting(MASTER_JVM_ARGS).length() > 0)
|
|
271 |
| || (!"".equals(masterMemory) && !OptionConstants.heapSizeChoices.get(0).equals(masterMemory)); |
|
272 |
0
| _log.log("_doRestart: "+_doRestart);
|
|
273 |
| |
|
274 |
0
| LinkedList<String> classArgs = new LinkedList<String>();
|
|
275 |
| |
|
276 |
| |
|
277 |
0
| if (_showDebugConsole) { classArgs.addFirst("-debugConsole"); }
|
|
278 |
| |
|
279 |
0
| if (! _propertiesFile.equals(DEFAULT_PROPERTIES_FILE)) {
|
|
280 |
| |
|
281 |
0
| classArgs.addFirst(_propertiesFile.getAbsolutePath());
|
|
282 |
0
| classArgs.addFirst("-config");
|
|
283 |
| } |
|
284 |
| |
|
285 |
0
| synchronized(DrJava.class) {
|
|
286 |
0
| classArgs.addAll(_filesToOpen);
|
|
287 |
0
| clearFilesToOpen();
|
|
288 |
0
| _log.log("_filesToOpen copied into class arguments, clearing _filesToOpen");
|
|
289 |
| } |
|
290 |
| |
|
291 |
0
| if (_doRestart) {
|
|
292 |
0
| if (DrJava.getConfig().getSetting(OptionConstants.REMOTE_CONTROL_ENABLED)) {
|
|
293 |
| |
|
294 |
| |
|
295 |
0
| _restartedDrJavaUsesRemoteControl = !RemoteControlClient.isServerRunning();
|
|
296 |
| } else { |
|
297 |
| |
|
298 |
0
| _restartedDrJavaUsesRemoteControl = false;
|
|
299 |
| } |
|
300 |
| |
|
301 |
| |
|
302 |
0
| try {
|
|
303 |
0
| boolean failed = false;
|
|
304 |
0
| JVMBuilder jvmb = JVMBuilder.DEFAULT.jvmArguments(_jvmArgs);
|
|
305 |
| |
|
306 |
| |
|
307 |
0
| _log.log("JVMBuilder: classPath = "+jvmb.classPath());
|
|
308 |
0
| ArrayList<File> extendedClassPath = new ArrayList<File>();
|
|
309 |
0
| for(File f: jvmb.classPath()) { extendedClassPath.add(f); }
|
|
310 |
0
| _log.log("JVMBuilder: extendedClassPath = "+extendedClassPath);
|
|
311 |
0
| jvmb = jvmb.classPath(edu.rice.cs.plt.iter.IterUtil.asSizedIterable(extendedClassPath));
|
|
312 |
0
| _log.log("JVMBuilder: jvmArguments = "+jvmb.jvmArguments());
|
|
313 |
0
| _log.log("JVMBuilder: classPath = "+jvmb.classPath());
|
|
314 |
0
| _log.log("JVMBuilder: mainParams = "+classArgs);
|
|
315 |
| |
|
316 |
| |
|
317 |
0
| Process p = jvmb.start(DrJavaRoot.class.getName(), classArgs);
|
|
318 |
0
| _alreadyRestarted = true;
|
|
319 |
0
| _log.log("_alreadyRestarted = true");
|
|
320 |
0
| DelayedInterrupter timeout = new DelayedInterrupter(WAIT_BEFORE_DECLARING_SUCCESS);
|
|
321 |
0
| try {
|
|
322 |
0
| int exitValue = p.waitFor();
|
|
323 |
0
| timeout.abort();
|
|
324 |
0
| failed = (exitValue != 0);
|
|
325 |
| } |
|
326 |
| catch(InterruptedException e) { } |
|
327 |
0
| _log.log("failed = "+failed);
|
|
328 |
0
| if (failed) {
|
|
329 |
0
| if (failCount > 0) {
|
|
330 |
| |
|
331 |
0
| JOptionPane.showMessageDialog(null,
|
|
332 |
| "DrJava was unable to start, and resetting your configuration\n" + |
|
333 |
| "did not help. Please file a support request at\n" + |
|
334 |
| "https://sourceforge.net/projects/drjava/", |
|
335 |
| "Could Not Start DrJava", |
|
336 |
| JOptionPane.ERROR_MESSAGE); |
|
337 |
0
| System.exit(1);
|
|
338 |
| } |
|
339 |
| else { |
|
340 |
| |
|
341 |
0
| int result = JOptionPane.showConfirmDialog(null,
|
|
342 |
| "DrJava was unable to start. Your configuration file (.drjava)\n" + |
|
343 |
| "might be corrupt. Do you want to reset your configuration?", |
|
344 |
| "Could Not Start DrJava", |
|
345 |
| JOptionPane.YES_NO_OPTION); |
|
346 |
0
| if (result != JOptionPane.YES_OPTION) { System.exit(0); }
|
|
347 |
| |
|
348 |
0
| getConfig().resetToDefaults();
|
|
349 |
0
| getConfig().saveConfiguration();
|
|
350 |
0
| if (!handleCommandLineArgs(args)) { System.exit(0); }
|
|
351 |
0
| ++failCount;
|
|
352 |
0
| continue;
|
|
353 |
| } |
|
354 |
| } |
|
355 |
| else { |
|
356 |
| |
|
357 |
0
| _log.log("not failed, send remaining files via remote control: "+_filesToOpen);
|
|
358 |
0
| openWithRemoteControl(_filesToOpen, NUM_REMOTE_CONTROL_RETRIES);
|
|
359 |
| } |
|
360 |
| } |
|
361 |
| catch (IOException ioe) { |
|
362 |
| |
|
363 |
0
| final String[] text = {
|
|
364 |
| "DrJava was unable to load its compiler and debugger. Would you ", |
|
365 |
| "like to start DrJava without a compiler and debugger?", "\nReason: " + ioe.toString() |
|
366 |
| }; |
|
367 |
0
| int result = JOptionPane.showConfirmDialog(null, text, "Could Not Load Compiler and Debugger",
|
|
368 |
| JOptionPane.YES_NO_OPTION); |
|
369 |
0
| if (result != JOptionPane.YES_OPTION) { System.exit(0); }
|
|
370 |
| } |
|
371 |
| } |
|
372 |
| |
|
373 |
| else { |
|
374 |
| |
|
375 |
0
| DrJavaRoot.main(classArgs.toArray(new String[0]));
|
|
376 |
| |
|
377 |
| |
|
378 |
| |
|
379 |
0
| ArrayList<String> fs = new ArrayList<String>(_filesToOpen);
|
|
380 |
0
| for(String f: fs) {
|
|
381 |
0
| DrJavaRoot.handleRemoteOpenFile(new File(f), -1);
|
|
382 |
| } |
|
383 |
| } |
|
384 |
0
| break;
|
|
385 |
| } |
|
386 |
| } |
|
387 |
| catch(Throwable t) { |
|
388 |
| |
|
389 |
0
| System.out.println(t.getClass().getName() + ": " + t.getMessage());
|
|
390 |
0
| t.printStackTrace(System.err);System.out.println("error thrown");
|
|
391 |
0
| DrJavaErrorHandler.record(t);
|
|
392 |
| } |
|
393 |
| } |
|
394 |
| |
|
395 |
| |
|
396 |
| |
|
397 |
| |
|
398 |
0
| static boolean handleCommandLineArgs(String[] args) {
|
|
399 |
0
| boolean heapSizeGiven = false;
|
|
400 |
| |
|
401 |
| |
|
402 |
0
| int argIndex = 0;
|
|
403 |
0
| int len = args.length;
|
|
404 |
0
| _log.log("handleCommandLineArgs. _filesToOpen: " + _filesToOpen);
|
|
405 |
| |
|
406 |
0
| while(argIndex < len) {
|
|
407 |
0
| String arg = args[argIndex++];
|
|
408 |
| |
|
409 |
0
| if (arg.equals("-config")) {
|
|
410 |
0
| if (len == argIndex) {
|
|
411 |
| |
|
412 |
0
| return true;
|
|
413 |
| } |
|
414 |
| |
|
415 |
0
| setPropertiesFile(args[argIndex++]);
|
|
416 |
| } |
|
417 |
| |
|
418 |
0
| else if (arg.startsWith("-X") || arg.startsWith("-D")) {
|
|
419 |
0
| if (arg.startsWith("-Xmx")) { heapSizeGiven = true; }
|
|
420 |
0
| _jvmArgs.add(arg);
|
|
421 |
| } |
|
422 |
| |
|
423 |
0
| else if (arg.equals("-debugConsole")) _showDebugConsole = true;
|
|
424 |
| |
|
425 |
0
| else if (arg.equals("-new")) _forceNewInstance = true;
|
|
426 |
| |
|
427 |
0
| else if (arg.equals("-delete-after-restart")) {
|
|
428 |
0
| File deleteAfterRestart = new File(args[argIndex++]);
|
|
429 |
0
| deleteAfterRestart.delete();
|
|
430 |
| } |
|
431 |
| |
|
432 |
0
| else if (arg.equals("-jll")) {
|
|
433 |
0
| String[] argsForJLL = new String[args.length-argIndex];
|
|
434 |
0
| System.arraycopy(args, argIndex, argsForJLL, 0, argsForJLL.length);
|
|
435 |
0
| edu.rice.cs.javalanglevels.LanguageLevelConverter.main(argsForJLL);
|
|
436 |
0
| System.exit(0);
|
|
437 |
| } |
|
438 |
| |
|
439 |
0
| else if (arg.equals("-help") || arg.equals("-?")) {
|
|
440 |
0
| displayUsage();
|
|
441 |
0
| return false;
|
|
442 |
| } |
|
443 |
| else { |
|
444 |
| |
|
445 |
0
| --argIndex;
|
|
446 |
0
| break;
|
|
447 |
| } |
|
448 |
| } |
|
449 |
| |
|
450 |
0
| synchronized(DrJava.class) {
|
|
451 |
0
| _config = _initConfig();
|
|
452 |
| } |
|
453 |
| |
|
454 |
0
| if ((!("".equals(getConfig().getSetting(MASTER_JVM_XMX)))) &&
|
|
455 |
| (!(OptionConstants.heapSizeChoices.get(0).equals(getConfig().getSetting(MASTER_JVM_XMX))))) { |
|
456 |
0
| _jvmArgs.add("-Xmx" + getConfig().getSetting(MASTER_JVM_XMX).trim() + "M");
|
|
457 |
0
| heapSizeGiven = true;
|
|
458 |
| } |
|
459 |
0
| List<String> configArgs = ArgumentTokenizer.tokenize(getConfig().getSetting(MASTER_JVM_ARGS));
|
|
460 |
0
| for (String arg : configArgs) {
|
|
461 |
0
| if (arg.startsWith("-Xmx")) { heapSizeGiven = true; }
|
|
462 |
0
| _jvmArgs.add(arg);
|
|
463 |
| } |
|
464 |
| |
|
465 |
0
| if (PlatformFactory.ONLY.isMacPlatform()) {
|
|
466 |
0
| String iconLoc = System.getProperty("edu.rice.cs.drjava.icon");
|
|
467 |
0
| if (iconLoc != null) {
|
|
468 |
0
| _jvmArgs.add("-Xdock:name=DrJava");
|
|
469 |
0
| _jvmArgs.add("-Xdock:icon=" + iconLoc);
|
|
470 |
| } |
|
471 |
| } |
|
472 |
| |
|
473 |
0
| if (!heapSizeGiven) { _jvmArgs.add(DEFAULT_MAX_HEAP_SIZE_ARG); }
|
|
474 |
| |
|
475 |
0
| _log.log("_jvmArgs = " + _jvmArgs);
|
|
476 |
| |
|
477 |
| |
|
478 |
| |
|
479 |
0
| for (int i = argIndex; i < len; i++) { addFileToOpen(args[i]); }
|
|
480 |
0
| _log.log("\t _filesToOpen now contains: " + _filesToOpen);
|
|
481 |
| |
|
482 |
0
| return true;
|
|
483 |
| } |
|
484 |
| |
|
485 |
| |
|
486 |
0
| static void displayUsage() {
|
|
487 |
0
| System.out.println("Usage: java -jar drjava.jar [OPTIONS] [FILES]\n");
|
|
488 |
0
| System.out.println("where options include:");
|
|
489 |
0
| System.out.println(" -config [FILE] use a custom config file");
|
|
490 |
0
| System.out.println(" -new force the creation of a new DrJava instance;");
|
|
491 |
0
| System.out.println(" do not connect to existing instance");
|
|
492 |
0
| System.out.println(" -help | -? print this help message");
|
|
493 |
0
| System.out.println(" -X<jvmOption> specify a JVM configuration option for the master DrJava JVM");
|
|
494 |
0
| System.out.println(" -D<name>[=<value>] set a Java property for the master DrJava JVM");
|
|
495 |
0
| System.out.println(" -jll [ARGS] invoke the Java Language Level converter, specify files in ARGS");
|
|
496 |
| } |
|
497 |
| |
|
498 |
| |
|
499 |
| |
|
500 |
| |
|
501 |
820
| static void setPropertiesFile(String fileName) {
|
|
502 |
820
| if (!DrJavaFileUtils.isSourceFile(fileName)) _propertiesFile = new File(fileName);
|
|
503 |
| } |
|
504 |
| |
|
505 |
| |
|
506 |
| |
|
507 |
| |
|
508 |
824
| static FileConfiguration _initConfig() throws IllegalStateException {
|
|
509 |
| |
|
510 |
| |
|
511 |
| |
|
512 |
824
| FileConfiguration config;
|
|
513 |
| |
|
514 |
824
| final File propFile = _propertiesFile;
|
|
515 |
| |
|
516 |
824
| try { propFile.createNewFile(); }
|
|
517 |
| catch (IOException e) { } |
|
518 |
| |
|
519 |
824
| config = new FileConfiguration(propFile);
|
|
520 |
824
| try { config.loadConfiguration(); }
|
|
521 |
| catch (Exception e) { |
|
522 |
| |
|
523 |
0
| config.storeStartupException(e);
|
|
524 |
| } |
|
525 |
824
| _config = new ResourceBundleConfiguration(RESOURCE_BUNDLE_NAME,config);
|
|
526 |
824
| return _config;
|
|
527 |
| } |
|
528 |
| |
|
529 |
| |
|
530 |
0
| protected static void _saveConfig() {
|
|
531 |
0
| try { getConfig().saveConfiguration(); }
|
|
532 |
| catch(IOException e) { |
|
533 |
0
| JOptionPane.showMessageDialog(null,
|
|
534 |
| "Could not save the location of tools.jar in \n" + |
|
535 |
| "the '.drjava' file in your home directory. \n" + |
|
536 |
| "Another process may be using the file.\n\n" + e, |
|
537 |
| "Could Not Save Changes", |
|
538 |
| JOptionPane.ERROR_MESSAGE); |
|
539 |
| |
|
540 |
0
| DrJavaErrorHandler.record(new UnexpectedException(e, "Could not save the location of tools.jar in \n" +
|
|
541 |
| "the '.drjava' file in your home directory. \n" + |
|
542 |
| "Another process may be using the file.\n\n")); |
|
543 |
| } |
|
544 |
| } |
|
545 |
| |
|
546 |
| |
|
547 |
| |
|
548 |
| |
|
549 |
| |
|
550 |
| |
|
551 |
| |
|
552 |
| |
|
553 |
| |
|
554 |
| |
|
555 |
| |
|
556 |
| |
|
557 |
| |
|
558 |
| |
|
559 |
| |
|
560 |
| |
|
561 |
| |
|
562 |
| |
|
563 |
| |
|
564 |
| |
|
565 |
| |
|
566 |
| |
|
567 |
| |
|
568 |
| |
|
569 |
| |
|
570 |
| |
|
571 |
| |
|
572 |
| |
|
573 |
| |
|
574 |
| |
|
575 |
| |
|
576 |
| |
|
577 |
| |
|
578 |
| |
|
579 |
| |
|
580 |
| |
|
581 |
| |
|
582 |
| |
|
583 |
| |
|
584 |
| |
|
585 |
| |
|
586 |
| |
|
587 |
| |
|
588 |
833
| public static void cleanUp() {
|
|
589 |
833
| _log.log("cleanUp. _filesToOpen: " + _filesToOpen);
|
|
590 |
833
| clearFilesToOpen();
|
|
591 |
833
| _log.log("\t_filesToOpen cleared");
|
|
592 |
833
| _jvmArgs.clear();
|
|
593 |
| |
|
594 |
| } |
|
595 |
| |
|
596 |
| |
|
597 |
0
| public static boolean warnIfLinuxWithCompiz() {
|
|
598 |
0
| try {
|
|
599 |
0
| if (!System.getProperty("os.name").equals("Linux")) return false;
|
|
600 |
0
| if (!DrJava.getConfig().getSetting(OptionConstants.WARN_IF_COMPIZ)) return false;
|
|
601 |
| |
|
602 |
| |
|
603 |
0
| File ps = new File("/bin/ps");
|
|
604 |
| |
|
605 |
| |
|
606 |
0
| ProcessBuilder pb = new ProcessBuilder(ps.getAbsolutePath(), "-A");
|
|
607 |
0
| Process psProc = pb.start();
|
|
608 |
0
| psProc.waitFor();
|
|
609 |
| |
|
610 |
| |
|
611 |
0
| BufferedReader br = new BufferedReader(new InputStreamReader(psProc.getInputStream()));
|
|
612 |
0
| boolean compiz = false;
|
|
613 |
0
| String line = null;
|
|
614 |
0
| while((line=br.readLine()) != null) {
|
|
615 |
| |
|
616 |
0
| if ((line.endsWith("compiz")) ||
|
|
617 |
| (line.endsWith("compiz.real"))) { |
|
618 |
0
| compiz = true;
|
|
619 |
0
| break;
|
|
620 |
| } |
|
621 |
| } |
|
622 |
0
| if (!compiz) return false;
|
|
623 |
| |
|
624 |
0
| final JavaVersion.FullVersion ver160_20 = JavaVersion.parseFullVersion("1.6.0_20");
|
|
625 |
0
| if (JavaVersion.CURRENT_FULL.compareTo(ver160_20)>=0) return false;
|
|
626 |
| |
|
627 |
0
| String[] options = new String[] { "Yes", "Yes, and ignore from now on", "No" };
|
|
628 |
0
| int res = javax.swing.JOptionPane.
|
|
629 |
| showOptionDialog(null, |
|
630 |
| "<html>DrJava has detected that you are using Compiz with a version<br>" + |
|
631 |
| "of Java that is older than " + ver160_20 + ".<br>" + |
|
632 |
| "<br>" + |
|
633 |
| "Compiz and older versions of Java are incompatible and can cause<br>" + |
|
634 |
| "DrJava or your computer to crash.<br>" + |
|
635 |
| "<br>" + |
|
636 |
| "We recommend that you <b>update to " + ver160_20 + " or newer</b>,<br>" + |
|
637 |
| "or that you disable Compiz if you still experience problems.<br>" + |
|
638 |
| "On Ubuntu, go to System->Preferences->Appearence, display the<br>" + |
|
639 |
| "Visual Effects tab, and select 'None'.<br>" + |
|
640 |
| "<br>" + |
|
641 |
| "For more information, please go to http://drjava.org/compiz<br>" + |
|
642 |
| "<br>" + |
|
643 |
| "Do you want to start DrJava anyway?</html>", |
|
644 |
| "Compiz detected", |
|
645 |
| JOptionPane.DEFAULT_OPTION, |
|
646 |
| javax.swing.JOptionPane.WARNING_MESSAGE, |
|
647 |
| null, |
|
648 |
| options, |
|
649 |
| options[0]); |
|
650 |
0
| switch(res) {
|
|
651 |
0
| case 1:
|
|
652 |
| |
|
653 |
0
| DrJava.getConfig().setSetting(OptionConstants.WARN_IF_COMPIZ, false);
|
|
654 |
0
| break;
|
|
655 |
0
| case 2:
|
|
656 |
0
| System.exit(0);
|
|
657 |
0
| break;
|
|
658 |
| } |
|
659 |
0
| return compiz;
|
|
660 |
| } |
|
661 |
| catch(IOException ioe) { |
|
662 |
0
| return false;
|
|
663 |
| } |
|
664 |
| catch(InterruptedException ie) { |
|
665 |
0
| return false;
|
|
666 |
| } |
|
667 |
| } |
|
668 |
| } |