edu.rice.cs.drjava
Class DrJava

java.lang.Object
  extended by edu.rice.cs.drjava.DrJava

public class DrJava
extends Object

Startup class for DrJava consisting entirely of static members. The main method reads the .drjava file (creating one if none exists) to get the critical information required to start the main JVM for DrJava: (i) the location of tools.jar in the Java JDK installed on this machine (so DrJava can invoke the javac compiler stored in tools.jar) (ii) the argument string for invoking the main JVM (notably -X options used to determine maximum heap size, etc.) Here is a summary of the launch mechanism of DrJava: 1. DrJava.main will be started. 2. DrJava.handleCommandLineArgs scans the command line arguments. 2.1. This involves determining if the -new parameter forces a new instance. 3. DrJava.configureAndLoadDrJavaRoot determines if remote control should be used: 3.1. If -new doesn't force a new instance 3.2. and REMOTE_CONTROL_ENABLED 3.3. and files have been specified on the command line 3.4. and the remote control server can be contacted 3.5. then DrJava will open the files in an existing instance and quit 4. DrJava.configureAndLoadDrJavaRoot determines if a restart is necessary: 4.1. If MASTER_JVM_XMX is set 4.2. or MASTER_JVM_ARGS is set 4.3. then DrJava will attempt to restart itself with the specified JVM arguments 4.4. Files that have arrived via Mac OS X's handleOpenFile event up to this point are included in the main arguments for the restarted DrJava. 4.5. If that fails, DrJava will ask if the user wants to delete the settings in the .drjava file 4.5.1. If the user says "yes", DrJava will attempt another restart. If that fails, DrJava gives up. 4.5.2. If the user says "no", DrJava gives up. 4.6. If additional files arrive via the handleOpenFile event, DrJava will attempt to use the remote control to open the files in the restarted DrJava. 4.6.1. DrJava will perform NUM_REMOTE_CONTROL_RETRIES attempts to contact the remote control server, with WAIT_BEFORE_REMOTE_CONTROL_RETRY ms of sleep time in between. 5. If neither the remote control was used nor a restart was necessary, DrJava will call DrJavaRoot.main. 5.1. Files that have arrived via Mac OS X's handleOpenFile event up to this point are included in the arguments for DrJavaRoot.main. 5.2. If additional files arrive via the handleOpenFile event, DrJava will MainFrame.handleRemoteOpenFile.

Version:
$Id: DrJava.java 5553 2012-05-01 17:28:45Z rcartwright $

Field Summary
(package private) static boolean _alreadyRestarted
          true if DrJava has already launched the new instance.
private static FileConfiguration _config
          Configuration object with all customized and default values.
(package private) static boolean _doRestart
          true if a new DrJava needs to be restarted to adjust parameters.
private static ArrayList<String> _filesToOpen
           
(package private) static boolean _forceNewInstance
          true if a new instance of DrJava should be started instead of connecting to an already running instance.
private static ArrayList<String> _jvmArgs
           
static Log _log
           
private static File _propertiesFile
          Properties file used by the configuration object.
(package private) static boolean _restartedDrJavaUsesRemoteControl
          true if the restarted DrJava will use remote control, and we can try to pass along files to open that arrived too late.
(package private) static boolean _showDebugConsole
           
private static String DEFAULT_MAX_HEAP_SIZE_ARG
           
static File DEFAULT_PROPERTIES_FILE
          Default properties file used by the configuration object, i.e.
private static int NUM_REMOTE_CONTROL_RETRIES
          Number of times we retry opening with the remote control.
static String RESOURCE_BUNDLE_NAME
          Name of the resource bundle that controls whether options are editable or not.
private static int WAIT_BEFORE_DECLARING_SUCCESS
          Time in millisecond before restarting DrJava to change the heap size, etc.
private static int WAIT_BEFORE_REMOTE_CONTROL_RETRY
          Time in millisecond that we wait before making another remote control attempt.
 
Constructor Summary
DrJava()
           
 
Method Summary
(package private) static FileConfiguration _initConfig()
          Initializes the configuration object with the current notion of the properties file.
protected static void _saveConfig()
          Saves the contents of the config file.
static void addFileToOpen(String s)
          Add a file to the list of files to open.
static void cleanUp()
           
static void clearFilesToOpen()
          Clear the list of files to open.
static void configureAndLoadDrJavaRoot(String[] args)
           
(package private) static void displayUsage()
          Displays a usage message about the available options.
static FileConfiguration getConfig()
          Returns the configuration object with all customized and default values.
static String[] getFilesToOpen()
           
static File getPropertiesFile()
          Returns the properties file used by the configuration object.
static boolean getShowDebugConsole()
           
(package private) static boolean handleCommandLineArgs(String[] args)
          Handles any command line arguments that have been specified.
static void main(String[] args)
          Starts running DrJava.
static boolean openWithRemoteControl(ArrayList<String> files, int numAttempts)
          Open the specified files using the remote control.
(package private) static void setPropertiesFile(String fileName)
          Switches the config object to use a custom config file.
static boolean warnIfLinuxWithCompiz()
          Warn if this system is Linux with Compiz.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_log

public static volatile Log _log

DEFAULT_MAX_HEAP_SIZE_ARG

private static final String DEFAULT_MAX_HEAP_SIZE_ARG
See Also:
Constant Field Values

_filesToOpen

private static final ArrayList<String> _filesToOpen

_jvmArgs

private static final ArrayList<String> _jvmArgs

_showDebugConsole

static volatile boolean _showDebugConsole

_forceNewInstance

static volatile boolean _forceNewInstance
true if a new instance of DrJava should be started instead of connecting to an already running instance.


_doRestart

static volatile boolean _doRestart
true if a new DrJava needs to be restarted to adjust parameters.


_alreadyRestarted

static volatile boolean _alreadyRestarted
true if DrJava has already launched the new instance.


_restartedDrJavaUsesRemoteControl

static volatile boolean _restartedDrJavaUsesRemoteControl
true if the restarted DrJava will use remote control, and we can try to pass along files to open that arrived too late.


WAIT_BEFORE_DECLARING_SUCCESS

private static final int WAIT_BEFORE_DECLARING_SUCCESS
Time in millisecond before restarting DrJava to change the heap size, etc. is deemed a success.

See Also:
Constant Field Values

NUM_REMOTE_CONTROL_RETRIES

private static final int NUM_REMOTE_CONTROL_RETRIES
Number of times we retry opening with the remote control.

See Also:
Constant Field Values

WAIT_BEFORE_REMOTE_CONTROL_RETRY

private static final int WAIT_BEFORE_REMOTE_CONTROL_RETRY
Time in millisecond that we wait before making another remote control attempt.

See Also:
Constant Field Values

DEFAULT_PROPERTIES_FILE

public static final File DEFAULT_PROPERTIES_FILE
Default properties file used by the configuration object, i.e. ".drjava" in the user's home directory.


_propertiesFile

private static volatile File _propertiesFile
Properties file used by the configuration object. Defaults to DEFAULT_PROPERTIES_FILE.


_config

private static volatile FileConfiguration _config
Configuration object with all customized and default values. Lazily initialized from _propertiesFile in getConfig() or handleCommandLineArgs().


RESOURCE_BUNDLE_NAME

public static final String RESOURCE_BUNDLE_NAME
Name of the resource bundle that controls whether options are editable or not.

See Also:
Constant Field Values
Constructor Detail

DrJava

public DrJava()
Method Detail

getPropertiesFile

public static File getPropertiesFile()
Returns the properties file used by the configuration object.


getConfig

public static FileConfiguration getConfig()
Returns the configuration object with all customized and default values.


getFilesToOpen

public static String[] getFilesToOpen()
Returns:
an array of the files that were passed on the command line.

addFileToOpen

public static void addFileToOpen(String s)
Add a file to the list of files to open.


clearFilesToOpen

public static void clearFilesToOpen()
Clear the list of files to open.


openWithRemoteControl

public static boolean openWithRemoteControl(ArrayList<String> files,
                                            int numAttempts)
Open the specified files using the remote control. If the remote control server is not running, numAttempts attempts will be made, with WAIT_BEFORE_REMOTE_CONTROL_RETRY ms of sleep time in between.

Parameters:
files - files to open with remote control
numAttempts - of attempts to be made
Returns:
true if successful

getShowDebugConsole

public static boolean getShowDebugConsole()
Returns:
true if the debug console should be enabled

main

public static void main(String[] args)
Starts running DrJava.

Parameters:
args - Command line argument array

configureAndLoadDrJavaRoot

public static void configureAndLoadDrJavaRoot(String[] args)

handleCommandLineArgs

static boolean handleCommandLineArgs(String[] args)
Handles any command line arguments that have been specified.

Returns:
true if DrJava should load, false if not

displayUsage

static void displayUsage()
Displays a usage message about the available options.


setPropertiesFile

static void setPropertiesFile(String fileName)
Switches the config object to use a custom config file. Ensures that Java source files aren't accidentally used.


_initConfig

static FileConfiguration _initConfig()
                              throws IllegalStateException
Initializes the configuration object with the current notion of the properties file.

Throws:
IllegalStateException - if config has already been assigned

_saveConfig

protected static void _saveConfig()
Saves the contents of the config file. TO DO: log any IOExceptions that occur.


cleanUp

public static void cleanUp()

warnIfLinuxWithCompiz

public static boolean warnIfLinuxWithCompiz()
Warn if this system is Linux with Compiz.