Skip to content

Commit b814c7e

Browse files
author
dlsmith
committed
Set up Mac app to start in the DrJava class and restart when necessary, using the appropriate settings and icon; modified the restart process so that it only happens when necessary; removed unnecessary references to the application's working directory (user.dir).
git-svn-id: file:///tmp/test-svn/trunk@4070 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent 5767133 commit b814c7e

7 files changed

Lines changed: 104 additions & 82 deletions

File tree

drjava/packaging/DrJava.app/Contents/Info.plist

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
<key>JVMVersion</key>
2626
<string>1.4+</string>
2727
<key>MainClass</key>
28-
<string>edu.rice.cs.drjava.DrJavaRoot</string>
28+
<string>edu.rice.cs.drjava.DrJava</string>
2929
<key>Properties</key>
3030
<dict>
3131
<key>apple.laf.useScreenMenuBar</key>
3232
<string>true</string>
33+
<key>edu.rice.cs.drjava.icon</key>
34+
<string>$APP_PACKAGE/Contents/Resources/DrJava.icns</string>
3335
</dict>
3436
</dict>
3537
</dict>

drjava/src/edu/rice/cs/drjava/DrJava.java

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
* (i) the location of tools.jar in the Java JDK installed on this machine (so DrJava can invoke the javac compiler
6969
* stored in tools.jar)
7070
* (ii) the argument string for invoking the main JVM (notably -X options used to determine maximum heap size, etc.)
71-
* This version of DrJava no longer supports the transitional JSR-14 compilers or the GJ compiler.
7271
* @version $Id$
7372
*/
7473
public class DrJava {
@@ -93,9 +92,6 @@ public class DrJava {
9392
}
9493
}
9594

96-
/** Pause time for displaying DrJava banner on startUp (in milliseconds) */
97-
private static final int PAUSE_TIME = 2000;
98-
9995
private static final String DEFAULT_MAX_HEAP_SIZE_ARG = "-Xmx128M";
10096

10197
private static final ArrayList<String> _filesToOpen = new ArrayList<String>();
@@ -135,20 +131,12 @@ public class DrJava {
135131
* @param args Command line argument array
136132
*/
137133
public static void main(final String[] args) {
134+
// Platform-specific UI setup.
135+
PlatformFactory.ONLY.beforeUISetup();
138136

139-
final SplashScreen splash = new SplashScreen();
140-
splash.setVisible(true);
141-
splash.repaint();
137+
new SplashScreen().flash();
142138
// Utilities.showDebug("Calling configureAndLoadDrJavaRoot with args = " + args);
143139
configureAndLoadDrJavaRoot(args);
144-
145-
// This obviously only runs in the main thread, not the UI thread, so use SwingUtilities rather than Utilities.
146-
SwingUtilities.invokeLater(new Runnable() {
147-
public void run() {
148-
try { Thread.sleep(PAUSE_TIME); }
149-
catch(InterruptedException e) { }
150-
splash.dispose();
151-
}});
152140
}
153141

154142
public static void configureAndLoadDrJavaRoot(String[] args) {
@@ -157,50 +145,55 @@ public static void configureAndLoadDrJavaRoot(String[] args) {
157145
if (handleCommandLineArgs(args)) {
158146

159147
// Check that compiler and debugger are available on classpath (including tools.jar location)
160-
checkForCompilersAndDebugger(args);
161-
162-
// Start the DrJava master JVM
163-
String pathSep = System.getProperty("path.separator");
164-
String classPath = edu.rice.cs.util.FileOps.convertToAbsolutePathEntries(System.getProperty("java.class.path"));
148+
boolean restart = !checkForCompilersAndDebugger(args);
165149

166-
// Include both the javac location stored in .drjava prefences and the path proposed by ToolsJarClassLoader
167-
File toolsFromConfig = getConfig().getSetting(JAVAC_LOCATION);
168-
classPath += pathSep + ToolsJarClassLoader.getToolsJarClassPath(toolsFromConfig);
169-
170-
File workDir = new File(System.getProperty("user.home"));
150+
// Restart if there are custom JVM args
151+
restart |= getConfig().getSetting(MASTER_JVM_ARGS).length() > 0;
171152

172153
LinkedList<String> classArgsList = new LinkedList<String>();
173-
// need to make the paths absolute since the working directory might change
174-
for(String fn: _filesToOpen) {
175-
classArgsList.add(new File(fn).getAbsolutePath());
176-
}
154+
classArgsList.addAll(_filesToOpen);
177155

178156
// Add the parameters "-debugConsole" to classArgsList if _showDebugConsole is true
179-
if (_showDebugConsole) classArgsList.add(0,"-debugConsole");
157+
if (_showDebugConsole) { classArgsList.addFirst("-debugConsole"); }
180158

181-
String[] jvmArgs = _jvmArgs.toArray(new String[0]);
182159
if (!_propertiesFile.equals(DEFAULT_PROPERTIES_FILE)) {
183-
classArgsList.add(0,"-config");
184-
// need to make the paths absolute since the working directory might change
185-
classArgsList.add(1,_propertiesFile.getAbsolutePath());
160+
// Placed in reversed order to get "-config filename"
161+
classArgsList.addFirst(_propertiesFile.getAbsolutePath());
162+
classArgsList.addFirst("-config");
186163
}
164+
187165
String[] classArgs = classArgsList.toArray(new String[0]);
188166

189-
// Run a new copy of DrJava and exit
190-
try {
167+
if (restart) {
168+
// Determine classpath
169+
String pathSep = System.getProperty("path.separator");
170+
String classPath = FileOps.convertToAbsolutePathEntries(System.getProperty("java.class.path"));
171+
172+
// Include both the javac location stored in .drjava prefences and the path proposed by ToolsJarClassLoader
173+
File toolsFromConfig = getConfig().getSetting(JAVAC_LOCATION);
174+
classPath += pathSep + ToolsJarClassLoader.getToolsJarClassPath(toolsFromConfig);
175+
176+
// Run a new copy of DrJava and exit
177+
try {
191178
// Utilities.showDebug("Starting DrJavaRoot with classArgs = " + Arrays.toString(classArgs) + "; classPath = " + classPath +
192-
// "; jvmArgs = " + Arrays.toString(jvmArgs) + "; workDir = " + workDir);
193-
ExecJVM.runJVM("edu.rice.cs.drjava.DrJavaRoot", classArgs, classPath, jvmArgs, workDir);
179+
// "; jvmArgs = " + _jvmArgs + "; workDir = " + workDir);
180+
ExecJVM.runJVM("edu.rice.cs.drjava.DrJavaRoot", classArgs, classPath, _jvmArgs.toArray(new String[0]), null);
181+
}
182+
catch (IOException ioe) {
183+
// Display error
184+
final String[] text = {
185+
"DrJava was unable to load its compiler and debugger. Would you ",
186+
"like to start DrJava without a compiler and debugger?", "\nReason: " + ioe.toString()
187+
};
188+
int result = JOptionPane.showConfirmDialog(null, text, "Could Not Load Compiler and Debugger",
189+
JOptionPane.YES_NO_OPTION);
190+
if (result != JOptionPane.YES_OPTION) { System.exit(0); }
191+
}
194192
}
195-
catch (IOException ioe) {
196-
// Display error
197-
final String[] text = {
198-
"DrJava was unable to load its compiler and debugger. Would you ",
199-
"like to start DrJava without a compiler and debugger?", "\nReason: " + ioe.toString()
200-
};
201-
int result = JOptionPane.showConfirmDialog(null, text, "Could Not Load Compiler and Debugger",
202-
JOptionPane.YES_NO_OPTION);
203-
if (result != JOptionPane.YES_OPTION) { System.exit(0); }
193+
194+
else {
195+
// No restart -- just invoke DrJavaRoot.main.
196+
DrJavaRoot.main(classArgs);
204197
}
205198
}
206199
}
@@ -237,12 +230,8 @@ static boolean handleCommandLineArgs(String[] args) {
237230
_toolsLoader = new ToolsJarClassLoader(getConfig().getSetting(JAVAC_LOCATION));
238231
}
239232

240-
else if ((arg.length() > 1) && (arg.substring(0,2).equals("-X"))) {
241-
if (arg.substring(0,4).equals("-Xmx")) heapSizeGiven = true;
242-
_jvmArgs.add(arg);
243-
}
244-
245-
else if ((arg.length() > 1) && (arg.substring(0,2).equals("-D"))) {
233+
else if (arg.startsWith("-X") || arg.startsWith("-D")) {
234+
if (arg.startsWith("-Xmx")) { heapSizeGiven = true; }
246235
_jvmArgs.add(arg);
247236
}
248237

@@ -259,16 +248,21 @@ else if (arg.equals("-help") || arg.equals("-?")) {
259248
}
260249
}
261250

262-
String jvmArgString = getConfig().getSetting(MASTER_JVM_ARGS);
263-
List<String> jvmArgs = ArgumentTokenizer.tokenize(jvmArgString);
264-
if (jvmArgs != null && jvmArgs.size() != 0) _jvmArgs.addAll(jvmArgs);
251+
List<String> configArgs = ArgumentTokenizer.tokenize(getConfig().getSetting(MASTER_JVM_ARGS));
252+
for (String arg : configArgs) {
253+
if (arg.startsWith("-Xmx")) { heapSizeGiven = true; }
254+
_jvmArgs.add(arg);
255+
}
256+
265257
if (PlatformFactory.ONLY.isMacPlatform()) {
266-
_jvmArgs.add("-Dcom.apple.macos.useScreenMenuBar=true");
267-
_jvmArgs.add("-Xdock:name=DrJava");
268-
_jvmArgs.add("-Xdock:icon=/Applications/DrJava.app/Contents/Resources/DrJava.icns");
258+
String iconLoc = System.getProperty("edu.rice.cs.drjava.icon");
259+
if (iconLoc != null) { // we are running inside the Mac app wrapper
260+
_jvmArgs.add("-Xdock:name=DrJava");
261+
_jvmArgs.add("-Xdock:icon=" + iconLoc);
262+
}
269263
}
270264

271-
if (! heapSizeGiven && jvmArgString.indexOf("-Xmx")<0) _jvmArgs.add(DEFAULT_MAX_HEAP_SIZE_ARG);
265+
if (!heapSizeGiven) { _jvmArgs.add(DEFAULT_MAX_HEAP_SIZE_ARG); }
272266

273267
_log.log("_jvmArgs = " + _jvmArgs);
274268

@@ -290,17 +284,23 @@ static void displayUsage() {
290284
System.out.print(buf.toString());
291285
}
292286

293-
/** Check to see if a compiler and the debugger are available in a tools.jar file. If it can't find them, it prompts
294-
* the user to optionally specify the location of a propert tools.jar file.
287+
/** Check to see if a compiler and the debugger are available in a tools.jar file. If it can't find them, it
288+
* prompts the user to optionally specify the location of a propert tools.jar file.
295289
* @param args Command line argument array, in case we need to restart
296-
*/
297-
static void checkForCompilersAndDebugger(String[] args) {
298-
299-
boolean needCompiler = ! hasAvailableCompiler();
300-
boolean needDebugger = ! hasAvailableDebugger();
301-
302-
// Try to make sure both compiler and debugger are available
303-
if (needCompiler || needDebugger) promptForToolsJar(needCompiler, needDebugger);
290+
* @return {@code true} iff the compiler and debugger are available without restarting
291+
*/
292+
static boolean checkForCompilersAndDebugger(String[] args) {
293+
if (canLoad(_thisLoader, TEST_COMPILER_CLASS) && canLoad(_thisLoader, TEST_DEBUGGER_CLASS)) {
294+
return true;
295+
}
296+
else {
297+
boolean haveCompiler = canLoad(_thisLoader, TEST_COMPILER_CLASS) ||
298+
canLoad(_toolsLoader, TEST_COMPILER_CLASS);
299+
boolean haveDebugger = canLoad(_thisLoader, TEST_DEBUGGER_CLASS) ||
300+
canLoad(_toolsLoader, TEST_DEBUGGER_CLASS);
301+
if (!haveCompiler || !haveDebugger) { promptForToolsJar(!haveCompiler, !haveDebugger); }
302+
return false;
303+
}
304304
}
305305

306306
/** Returns whether the debugger will be able to load successfully. Checks for the ability to load the

drjava/src/edu/rice/cs/drjava/DrJavaRoot.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import edu.rice.cs.drjava.ui.SimpleInteractionsWindow;
5959
import edu.rice.cs.drjava.model.*;
6060
import edu.rice.cs.drjava.model.compiler.*;
61+
import edu.rice.cs.drjava.platform.PlatformFactory;
6162
import edu.rice.cs.drjava.config.FileConfiguration;
6263
import edu.rice.cs.drjava.config.*;
6364

@@ -92,6 +93,9 @@ public class DrJavaRoot {
9293
* prevent others from assigning new values. */
9394

9495
public static void main(final String[] args) {
96+
// Platform-specific UI setup.
97+
PlatformFactory.ONLY.beforeUISetup();
98+
9599
// Utilities.show("DrJavaRoot started with args = " + Arrays.toString(args));
96100
// let DrJava class handle command line arguments
97101
if (!DrJava.handleCommandLineArgs(args)) {
@@ -131,7 +135,7 @@ public static void main(final String[] args) {
131135

132136
/* This call on invokeLater only runs in the main thread, so we use SwingUtilities rather than Utilities.
133137
* We use invokeLater here ensure all files have finished loading and added to the fileview before the MainFrame
134-
* is set visible. When this was not done, we occasionally encountered a NullPointerExceptio on startUp when
138+
* is set visible. When this was not done, we occasionally encountered a NullPointerException on start up when
135139
* specifying a file (ex: java -jar drjava.jar somefile.java)
136140
*/
137141
SwingUtilities.invokeLater(new Runnable(){ public void run(){ mf.setVisible(true); } });

drjava/src/edu/rice/cs/drjava/model/AbstractGlobalModel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -949,8 +949,8 @@ public File getWorkingDirectory() {
949949
return roots[0].getCanonicalFile();
950950
}
951951
catch(IOException e) { /* fall through */ }
952-
// _log.log("Returning " + System.getProperty("user.dir") + " as working directory");
953-
return new File(System.getProperty("user.dir")); // a flat file configuration should have exactly one source root
952+
// _log.log("Returning " + System.getProperty("user.home") + " as working directory");
953+
return new File(System.getProperty("user.home")); // a flat file configuration should have exactly one source root
954954
}
955955
public boolean isProjectActive() { return false; }
956956
public boolean inProjectPath(OpenDefinitionsDocument doc) { return false; }

drjava/src/edu/rice/cs/drjava/ui/MainFrame.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2538,8 +2538,6 @@ public MainFrame() {
25382538
// Cache the config object, since we use it many, many times.
25392539
final Configuration config = DrJava.getConfig();
25402540

2541-
// Platform-specific UI setup.
2542-
PlatformFactory.ONLY.beforeUISetup();
25432541

25442542
// Utilities.show("MainFrame starting");
25452543

@@ -2643,7 +2641,7 @@ public void actionPerformed(ActionEvent e) {
26432641
});
26442642
_debugStepTimer.setRepeats(false);
26452643

2646-
// Working directory is default place to start, else use user.dir (bug #895998).
2644+
// Working directory is default place to start (bug #895998).
26472645
File workDir = _model.getMasterWorkingDirectory();
26482646

26492647
// Overrides JFileChooser to display the full path of the directory
@@ -2910,7 +2908,7 @@ public void optionChanged(OptionEvent<String> oe) {
29102908
int result = JOptionPane.
29112909
showConfirmDialog(_configFrame,
29122910
"Specifying Main JVM Args is an advanced option. Invalid arguments may cause\n" +
2913-
"DrJava to fail on startUp. You may need to edit or delete your .drjava preferences file\n" +
2911+
"DrJava to fail on start up. You may need to edit or delete your .drjava preferences file\n" +
29142912
"to recover.\n Are you sure you want to set this option?\n" +
29152913
"(You will have to restart Drjava before changes take effect.)",
29162914
"Confirm Main JVM Arguments", JOptionPane.YES_NO_OPTION);
@@ -6216,7 +6214,6 @@ private void _setCurrentDirectory(File file) {
62166214
file = _getFullFile(file);
62176215
_openChooser.setCurrentDirectory(file);
62186216
_saveChooser.setCurrentDirectory(file);
6219-
// System.setProperty("user.dir", file.getAbsolutePath()); // Changed system property is ignored by JVM
62206217
DrJava.getConfig().setSetting(LAST_DIRECTORY, file);
62216218
}
62226219
catch (IOException ioe) {

drjava/src/edu/rice/cs/drjava/ui/SplashScreen.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,16 @@
3535

3636
import javax.swing.*;
3737
import java.awt.*;
38+
import java.awt.event.*;
3839

3940
/**
4041
* A splash screen window to be displayed as DrJava is first starting up.
4142
* @version $Id$
4243
*/
4344
public class SplashScreen extends JWindow {
44-
public static final String SPLASH_ICON = "splash.png";
45+
private static final String SPLASH_ICON = "splash.png";
46+
private static final int PAUSE_TIME = 4000; // in milliseconds
47+
4548
private ImageIcon _icon;
4649

4750
/** Creates a new splash screen, but does not display it. Display the splash screen using show() and close it
@@ -61,4 +64,20 @@ public SplashScreen() {
6164
setLocation(ownerLoc.x + (ownerSize.width - frameSize.width) / 2,
6265
ownerLoc.y + (ownerSize.height - frameSize.height) / 2);
6366
}
67+
68+
/** Display the splash screen, and schedule it to be removed after a delay. This does not
69+
* need to run on the event thread.
70+
*/
71+
public void flash() {
72+
setVisible(true);
73+
repaint();
74+
Timer cleanup = new Timer(PAUSE_TIME, new ActionListener() {
75+
public void actionPerformed(ActionEvent e) {
76+
dispose();
77+
}
78+
});
79+
cleanup.setRepeats(false);
80+
cleanup.start();
81+
}
82+
6483
}

drjava/src/edu/rice/cs/drjava/ui/config/ConfigFrame.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,8 @@ private void _setupResourceLocPanel(ConfigPanel panel) {
401401
"<html>Any directories or jar files to add to the classpath<br>"+
402402
"of the Compiler and Interactions Pane.</html>"));
403403
addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.STICKY_INTERACTIONS_DIRECTORY,
404-
"Restore last working directory of the Interactions pane on startUp", this,
405-
"<html>Whether to restore the last working directory of the Interaction pane on startUp,<br>"+
404+
"Restore last working directory of the Interactions pane on start up", this,
405+
"<html>Whether to restore the last working directory of the Interaction pane on start up,<br>"+
406406
"or to always use the value of the \"user.home\" Java property<br>"+
407407
"(currently "+System.getProperty("user.home")+")."));
408408

0 commit comments

Comments
 (0)