Author: tfmorris
Date: 2007-11-02 02:58:01-0700
New Revision: 13697
Modified:
trunk/src_new/org/argouml/application/Main.java
Log:
Issue 4889 - add last chance exception handler to log error and force exit if main thread dies during startup
Modified: trunk/src_new/org/argouml/application/Main.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/application/Main.java?view=diff&rev=13697&p1=trunk/src_new/org/argouml/application/Main.java&p2=trunk/src_new/org/argouml/application/Main.java&r1=13696&r2=13697
==============================================================================
--- trunk/src_new/org/argouml/application/Main.java (original)
+++ trunk/src_new/org/argouml/application/Main.java 2007-11-02 02:58:01-0700
@@ -118,302 +118,322 @@
* @param args command line parameters
*/
public static void main(String[] args) {
- LOG.info("ArgoUML Started.");
-
- SimpleTimer st = new SimpleTimer();
- st.mark("begin");
-
- checkJVMVersion();
- checkHostsFile();
-
- // Force the configuration to load
- Configuration.load();
-
- // Synchronize the startup directory
- String directory = Argo.getDirectory();
- org.tigris.gef.base.Globals.setLastDirectory(directory);
-
- // Initialise the version of this application
- initVersion();
-
- // Set the i18n locale
- Translator.init(Configuration.getString(Argo.KEY_LOCALE));
-
- // create an anonymous class as a kind of adaptor for the cognitive
- // System to provide proper translation/i18n.
- org.argouml.cognitive.Translator.setTranslator(
- new AbstractCognitiveTranslator() {
- public String i18nlocalize(String key) {
- return Translator.localize(key);
- }
-
- public String i18nmessageFormat(String key, Object[] iArgs) {
- return Translator.messageFormat(key, iArgs);
- }
- });
+ try {
+ LOG.info("ArgoUML Started.");
- // then, print out some version info for debuggers...
- org.argouml.util.Tools.logVersionInfo();
+ SimpleTimer st = new SimpleTimer();
+ st.mark("begin");
- st.mark("arguments");
+ checkJVMVersion();
+ checkHostsFile();
- /* set properties for application behaviour */
- System.setProperty("gef.imageLocation", "/org/argouml/Images");
-
- System.setProperty("apple.laf.useScreenMenuBar", "true");
-
- /* FIX: set the application name for Mac OS X */
- System.setProperty("com.apple.mrj.application.apple.menu.about.name",
- "ArgoUML");
-
- boolean doSplash = Configuration.getBoolean(Argo.KEY_SPLASH, true);
- boolean reloadRecent =
- Configuration.getBoolean(Argo.KEY_RELOAD_RECENT_PROJECT, false);
- boolean batch = false;
- List<String> commands = new ArrayList<String>();
-
- String projectName = null;
-
- // Parse command line args:
- // The assumption is that all options precede
- // the name of a project file to load.
- String theTheme = null;
- for (int i = 0; i < args.length; i++) {
- if (args[i].startsWith("-")) {
- String themeName =
- LookAndFeelMgr.getInstance()
+ // Force the configuration to load
+ Configuration.load();
+
+ // Synchronize the startup directory
+ String directory = Argo.getDirectory();
+ org.tigris.gef.base.Globals.setLastDirectory(directory);
+
+ // Initialise the version of this application
+ initVersion();
+
+ // Set the i18n locale
+ Translator.init(Configuration.getString(Argo.KEY_LOCALE));
+
+ // create an anonymous class as a kind of adaptor for the cognitive
+ // System to provide proper translation/i18n.
+ org.argouml.cognitive.Translator.setTranslator(
+ new AbstractCognitiveTranslator() {
+ public String i18nlocalize(String key) {
+ return Translator.localize(key);
+ }
+
+ public String i18nmessageFormat(String key,
+ Object[] iArgs) {
+ return Translator.messageFormat(key, iArgs);
+ }
+ });
+
+ // then, print out some version info for debuggers...
+ org.argouml.util.Tools.logVersionInfo();
+
+ st.mark("arguments");
+
+ /* set properties for application behaviour */
+ System.setProperty("gef.imageLocation", "/org/argouml/Images");
+
+ System.setProperty("apple.laf.useScreenMenuBar", "true");
+
+ /* FIX: set the application name for Mac OS X */
+ System.setProperty(
+ "com.apple.mrj.application.apple.menu.about.name",
+ "ArgoUML");
+
+ boolean doSplash = Configuration.getBoolean(Argo.KEY_SPLASH, true);
+ boolean reloadRecent = Configuration.getBoolean(
+ Argo.KEY_RELOAD_RECENT_PROJECT, false);
+ boolean batch = false;
+ List<String> commands = new ArrayList<String>();
+
+ String projectName = null;
+
+ // Parse command line args:
+ // The assumption is that all options precede
+ // the name of a project file to load.
+ String theTheme = null;
+ for (int i = 0; i < args.length; i++) {
+ if (args[i].startsWith("-")) {
+ String themeName =
+ LookAndFeelMgr.getInstance()
.getThemeClassNameFromArg(args[i]);
- if (themeName != null) {
- theTheme = themeName;
- } else if (
- args[i].equalsIgnoreCase("-help")
- || args[i].equalsIgnoreCase("-h")
- || args[i].equalsIgnoreCase("--help")
- || args[i].equalsIgnoreCase("/?")) {
- printUsage();
- System.exit(0);
- } else if (args[i].equalsIgnoreCase("-nosplash")) {
- doSplash = false;
- } else if (args[i].equalsIgnoreCase("-norecentfile")) {
- reloadRecent = false;
- } else if (args[i].equalsIgnoreCase("-command")
- && i + 1 < args.length) {
- commands.add(args[i + 1]);
- i++;
- } else if (args[i].equalsIgnoreCase("-locale")
- && i + 1 < args.length) {
- Translator.setLocale(args[i + 1]);
- i++;
- } else if (args[i].equalsIgnoreCase("-batch")) {
- batch = true;
- } else if (args[i].equalsIgnoreCase("-open")
- && i + 1 < args.length) {
- projectName = args[++i];
- } else if (args[i].equalsIgnoreCase("-print")
- && i + 1 < args.length) {
- // let's load the project
- String projectToBePrinted =
- PersistenceManager.getInstance().fixExtension(
- args[++i]);
- URL urlToBePrinted = projectUrl(projectToBePrinted, null);
- ProjectBrowser.getInstance().loadProject(
- new File(urlToBePrinted.getFile()), true, null);
- // now, let's print it
- PrintManager.getInstance().print();
- // nothing else to do (?)
- System.exit(0);
+ if (themeName != null) {
+ theTheme = themeName;
+ } else if (
+ args[i].equalsIgnoreCase("-help")
+ || args[i].equalsIgnoreCase("-h")
+ || args[i].equalsIgnoreCase("--help")
+ || args[i].equalsIgnoreCase("/?")) {
+ printUsage();
+ System.exit(0);
+ } else if (args[i].equalsIgnoreCase("-nosplash")) {
+ doSplash = false;
+ } else if (args[i].equalsIgnoreCase("-norecentfile")) {
+ reloadRecent = false;
+ } else if (args[i].equalsIgnoreCase("-command")
+ && i + 1 < args.length) {
+ commands.add(args[i + 1]);
+ i++;
+ } else if (args[i].equalsIgnoreCase("-locale")
+ && i + 1 < args.length) {
+ Translator.setLocale(args[i + 1]);
+ i++;
+ } else if (args[i].equalsIgnoreCase("-batch")) {
+ batch = true;
+ } else if (args[i].equalsIgnoreCase("-open")
+ && i + 1 < args.length) {
+ projectName = args[++i];
+ } else if (args[i].equalsIgnoreCase("-print")
+ && i + 1 < args.length) {
+ // let's load the project
+ String projectToBePrinted =
+ PersistenceManager.getInstance().fixExtension(
+ args[++i]);
+ URL urlToBePrinted = projectUrl(projectToBePrinted,
+ null);
+ ProjectBrowser.getInstance().loadProject(
+ new File(urlToBePrinted.getFile()), true, null);
+ // now, let's print it
+ PrintManager.getInstance().print();
+ // nothing else to do (?)
+ System.exit(0);
+ } else {
+ System.err
+ .println("Ignoring unknown/incomplete option '"
+ + args[i] + "'");
+ }
} else {
- System.err.println(
- "Ignoring unknown/incomplete option '" + args[i] + "'");
- }
- } else {
- if (projectName == null) {
- System.out.println(
- "Setting projectName to '" + args[i] + "'");
- projectName = args[i];
+ if (projectName == null) {
+ System.out.println(
+ "Setting projectName to '" + args[i] + "'");
+ projectName = args[i];
+ }
}
}
- }
- // We have to do this to set the LAF for the splash screen
- st.mark("initialize laf");
- LookAndFeelMgr.getInstance().initializeLookAndFeel();
- if (theTheme != null) {
- LookAndFeelMgr.getInstance().setCurrentTheme(theTheme);
- }
-
- // Get the splash screen up as early as possible
- st.mark("create splash");
- SplashScreen splash = null;
- if (doSplash && !batch) {
- splash = initializeSplash();
- }
+ // We have to do this to set the LAF for the splash screen
+ st.mark("initialize laf");
+ LookAndFeelMgr.getInstance().initializeLookAndFeel();
+ if (theTheme != null) {
+ LookAndFeelMgr.getInstance().setCurrentTheme(theTheme);
+ }
- // Initialize the Model subsystem
- st.mark("initialize model subsystem");
+ // Get the splash screen up as early as possible
+ st.mark("create splash");
+ SplashScreen splash = null;
+ if (doSplash && !batch) {
+ splash = initializeSplash();
+ }
- initModel();
-
- updateProgress(splash, 5, "statusmsg.bar.model-subsystem");
+ // Initialize the Model subsystem
+ st.mark("initialize model subsystem");
- /*
- * Initialize the module loader. At least the plug-ins that provide
- * profiles need to be initialized before the project is loaded, because
- * some of these profile may have been set as default profiles and need
- * to be applied to the project as soon as it has been created or
- * loaded. the first instance of a Project is needed during the gui
- * initialization
- */
- st.mark("modules");
+ initModel();
- SubsystemUtility.initSubsystem(new InitModuleLoader());
-
- // Initialize the Java code generator.
- GeneratorJava.getInstance();
-
- // The reason the gui is initialized before the commands are run
- // is that some of the commands will use the projectbrowser.
- st.mark("initialize gui");
- initializeGUI(splash);
-
- SubsystemUtility.initSubsystem(new InitUiCmdSubsystem());
- SubsystemUtility.initSubsystem(new InitNotationUI());
- SubsystemUtility.initSubsystem(new InitNotation());
- SubsystemUtility.initSubsystem(new InitNotationUml());
- SubsystemUtility.initSubsystem(new InitNotationJava());
- SubsystemUtility.initSubsystem(new InitDiagramAppearanceUI());
-
- if (reloadRecent && projectName == null) {
- // If no project was entered on the command line,
- // try to reload the most recent project if that option is true
- String s =
- Configuration.getString(Argo.KEY_MOST_RECENT_PROJECT_FILE, "");
- if (!("".equals(s))) {
- File file = new File(s);
- if (file.exists()) {
- LOG.info("Re-opening project " + s);
- projectName = s;
- } else {
- LOG.warn(
- "Cannot re-open " + s + " because it does not exist");
+ updateProgress(splash, 5, "statusmsg.bar.model-subsystem");
+
+ /*
+ * Initialize the module loader. At least the plug-ins that provide
+ * profiles need to be initialized before the project is loaded,
+ * because some of these profile may have been set as default
+ * profiles and need to be applied to the project as soon as it has
+ * been created or loaded. the first instance of a Project is needed
+ * during the gui initialization
+ */
+ st.mark("modules");
+
+ SubsystemUtility.initSubsystem(new InitModuleLoader());
+
+ // Initialize the Java code generator.
+ GeneratorJava.getInstance();
+
+ // The reason the gui is initialized before the commands are run
+ // is that some of the commands will use the projectbrowser.
+ st.mark("initialize gui");
+ initializeGUI(splash);
+
+ SubsystemUtility.initSubsystem(new InitUiCmdSubsystem());
+ SubsystemUtility.initSubsystem(new InitNotationUI());
+ SubsystemUtility.initSubsystem(new InitNotation());
+ SubsystemUtility.initSubsystem(new InitNotationUml());
+ SubsystemUtility.initSubsystem(new InitNotationJava());
+ SubsystemUtility.initSubsystem(new InitDiagramAppearanceUI());
+
+ if (reloadRecent && projectName == null) {
+ // If no project was entered on the command line,
+ // try to reload the most recent project if that option is true
+ String s = Configuration.getString(
+ Argo.KEY_MOST_RECENT_PROJECT_FILE, "");
+ if (!("".equals(s))) {
+ File file = new File(s);
+ if (file.exists()) {
+ LOG.info("Re-opening project " + s);
+ projectName = s;
+ } else {
+ LOG.warn(
+ "Cannot re-open " + s
+ + " because it does not exist");
+ }
}
}
- }
- URL urlToOpen = null;
+ URL urlToOpen = null;
- if (projectName != null) {
- projectName =
- PersistenceManager.getInstance().fixExtension(projectName);
- urlToOpen = projectUrl(projectName, urlToOpen);
- }
+ if (projectName != null) {
+ projectName =
+ PersistenceManager.getInstance().fixExtension(projectName);
+ urlToOpen = projectUrl(projectName, urlToOpen);
+ }
- st.mark("initialize ProjectBrowser");
- ProjectBrowser pb = ProjectBrowser.getInstance();
+ st.mark("initialize ProjectBrowser");
+ ProjectBrowser pb = ProjectBrowser.getInstance();
- st.mark("perform commands");
- if (batch) {
- performCommands(commands);
- commands = null;
+ st.mark("perform commands");
+ if (batch) {
+ performCommands(commands);
+ commands = null;
+
+ System.out.println("Exiting because we are running in batch.");
+ new ActionExit().doCommand(null);
+ return;
+ }
- System.out.println("Exiting because we are running in batch.");
- new ActionExit().doCommand(null);
- return;
- }
+ if (splash != null) {
+ if (urlToOpen == null) {
+ splash.getStatusBar().showStatus(
+ Translator.localize(
+ "statusmsg.bar.defaultproject"));
+ } else {
+ Object[] msgArgs = {
+ projectName,
+ };
+ splash.getStatusBar().showStatus(
+ Translator.messageFormat(
+ "statusmsg.bar.readingproject",
+ msgArgs));
+ }
- if (splash != null) {
- if (urlToOpen == null) {
- splash.getStatusBar().showStatus(
- Translator.localize("statusmsg.bar.defaultproject"));
- } else {
- Object[] msgArgs = {
- projectName,
- };
- splash.getStatusBar().showStatus(
- Translator.messageFormat("statusmsg.bar.readingproject",
- msgArgs));
- }
-
- splash.getStatusBar().showProgress(40);
- }
-
- st.mark("make empty project");
-
- Designer.disableCritiquing();
- Designer.clearCritiquing();
-
- boolean projectLoaded = false;
- if (urlToOpen != null) {
- String filename = urlToOpen.getFile();
- File file = new File(filename);
- System.err.println("The url of the file to open is " + urlToOpen);
- System.err.println("The filename is " + filename);
- System.err.println("The file is " + file);
- System.err.println("File.exists = " + file.exists());
- projectLoaded = pb.loadProject(file, true, null);
- }
-
- if (!projectLoaded) {
- // Although this looks redundant, it's needed to get all
- // the initialization state set correctly.
- // Too many side effects as part of initialization!
- ProjectManager.getManager().setCurrentProject(
- ProjectManager.getManager().getCurrentProject());
- ProjectManager.getManager().setSaveEnabled(false);
- }
+ splash.getStatusBar().showProgress(40);
+ }
- st.mark("set project");
+ st.mark("make empty project");
- Designer.enableCritiquing();
+ Designer.disableCritiquing();
+ Designer.clearCritiquing();
- st.mark("perspectives");
+ boolean projectLoaded = false;
+ if (urlToOpen != null) {
+ String filename = urlToOpen.getFile();
+ File file = new File(filename);
+ System.err.println("The url of the file to open is "
+ + urlToOpen);
+ System.err.println("The filename is " + filename);
+ System.err.println("The file is " + file);
+ System.err.println("File.exists = " + file.exists());
+ projectLoaded = pb.loadProject(file, true, null);
+ }
- if (splash != null) {
- splash.getStatusBar().showProgress(75);
- }
+ if (!projectLoaded) {
+ // Although this looks redundant, it's needed to get all
+ // the initialization state set correctly.
+ // Too many side effects as part of initialization!
+ ProjectManager.getManager().setCurrentProject(
+ ProjectManager.getManager().getCurrentProject());
+ ProjectManager.getManager().setSaveEnabled(false);
+ }
- st.mark("open window");
+ st.mark("set project");
- updateProgress(splash, 95, "statusmsg.bar.open-project-browser");
+ Designer.enableCritiquing();
- ArgoFrame.getInstance().setVisible(true);
+ st.mark("perspectives");
- st.mark("close splash");
- if (splash != null) {
- splash.setVisible(false);
- splash.dispose();
- splash = null;
- }
+ if (splash != null) {
+ splash.getStatusBar().showProgress(75);
+ }
- performCommands(commands);
- commands = null;
+ st.mark("open window");
- st.mark("start critics");
- Runnable startCritics = new StartCritics();
- Main.addPostLoadAction(startCritics);
+ updateProgress(splash, 95, "statusmsg.bar.open-project-browser");
- st.mark("start loading modules");
- Runnable moduleLoader = new LoadModules();
- Main.addPostLoadAction(moduleLoader);
+ ArgoFrame.getInstance().setVisible(true);
- PostLoad pl = new PostLoad(postLoadActions);
- Thread postLoadThead = new Thread(pl);
- postLoadThead.start();
+ st.mark("close splash");
+ if (splash != null) {
+ splash.setVisible(false);
+ splash.dispose();
+ splash = null;
+ }
- LOG.info("");
- LOG.info("profile of load time ############");
- for (Enumeration i = st.result(); i.hasMoreElements();) {
- LOG.info(i.nextElement());
- }
- LOG.info("#################################");
- LOG.info("");
+ performCommands(commands);
+ commands = null;
- st = null;
- ArgoFrame.getInstance().setCursor(
- Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ st.mark("start critics");
+ Runnable startCritics = new StartCritics();
+ Main.addPostLoadAction(startCritics);
+
+ st.mark("start loading modules");
+ Runnable moduleLoader = new LoadModules();
+ Main.addPostLoadAction(moduleLoader);
+
+ PostLoad pl = new PostLoad(postLoadActions);
+ Thread postLoadThead = new Thread(pl);
+ postLoadThead.start();
+
+ LOG.info("");
+ LOG.info("profile of load time ############");
+ for (Enumeration i = st.result(); i.hasMoreElements();) {
+ LOG.info(i.nextElement());
+ }
+ LOG.info("#################################");
+ LOG.info("");
- //ToolTipManager.sharedInstance().setInitialDelay(500);
- ToolTipManager.sharedInstance().setDismissDelay(50000000);
+ st = null;
+ ArgoFrame.getInstance().setCursor(
+ Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+
+ //ToolTipManager.sharedInstance().setInitialDelay(500);
+ ToolTipManager.sharedInstance().setDismissDelay(50000000);
+ } catch (Throwable t) {
+ try {
+ LOG.fatal("Fatal error on startup. ArgoUML failed to start",
+ t);
+ } finally {
+ System.out.println("Fatal error on startup. "
+ + "ArgoUML failed to start.");
+ t.printStackTrace();
+ System.exit(1);
+ }
+ }
}
/**
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.