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 */
7473public 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?" , "\n Reason: " + 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?" , "\n Reason: " + 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
0 commit comments