From a496b3ca4b407c0135832a6837ae4eb10e949e84 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 25 Feb 2015 20:10:09 +0100 Subject: [PATCH] ZD-52550 (better startup diagnostic) --- bin/scripts/unix/idea.sh | 3 +- .../bootstrap/src/com/intellij/idea/Main.java | 37 ++++++++++--------- .../com/intellij/idea/IdeaApplication.java | 4 +- .../src/com/intellij/idea/StartupUtil.java | 12 ++++-- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/bin/scripts/unix/idea.sh b/bin/scripts/unix/idea.sh index 28b37bd39950..2778a8c353f8 100755 --- a/bin/scripts/unix/idea.sh +++ b/bin/scripts/unix/idea.sh @@ -178,5 +178,6 @@ while true ; do $REQUIRED_JVM_ARGS \ $MAIN_CLASS_NAME \ "$@" - test $? -ne 88 && break + EC=$? + test $EC -ne 88 && exit $EC done diff --git a/platform/bootstrap/src/com/intellij/idea/Main.java b/platform/bootstrap/src/com/intellij/idea/Main.java index c6451b19e215..828821713576 100644 --- a/platform/bootstrap/src/com/intellij/idea/Main.java +++ b/platform/bootstrap/src/com/intellij/idea/Main.java @@ -35,11 +35,14 @@ import java.util.Locale; @SuppressWarnings({"UseOfSystemOutOrSystemErr", "MethodNamesDifferingOnlyByCase"}) public class Main { - public static final int UPDATE_FAILED = 1; - public static final int STARTUP_EXCEPTION = 2; - public static final int STARTUP_IMPOSSIBLE = 3; - public static final int LICENSE_ERROR = 4; - public static final int PLUGIN_ERROR = 5; + public static final int NO_GRAPHICS = 1; + public static final int UPDATE_FAILED = 2; + public static final int STARTUP_EXCEPTION = 3; + public static final int JDK_CHECK_FAILED = 4; + public static final int DIR_CHECK_FAILED = 5; + public static final int INSTANCE_CHECK_FAILED = 6; + public static final int LICENSE_ERROR = 7; + public static final int PLUGIN_ERROR = 8; private static final String AWT_HEADLESS = "java.awt.headless"; private static final String PLATFORM_PREFIX_PROPERTY = "idea.platform.prefix"; @@ -60,19 +63,17 @@ public class Main { if (isHeadless()) { System.setProperty(AWT_HEADLESS, Boolean.TRUE.toString()); } - else { - if (GraphicsEnvironment.isHeadless()) { - throw new HeadlessException("Unable to detect graphics environment"); + else if (GraphicsEnvironment.isHeadless()) { + showMessage("Startup Error", "Unable to detect graphics environment", true); + System.exit(NO_GRAPHICS); + } + else if (args.length == 0) { + try { + installPatch(); } - - if (args.length == 0) { - try { - installPatch(); - } - catch (Throwable t) { - showMessage("Update Failed", t); - System.exit(UPDATE_FAILED); - } + catch (Throwable t) { + showMessage("Update Failed", t); + System.exit(UPDATE_FAILED); } } @@ -216,7 +217,7 @@ public class Main { @SuppressWarnings({"UseJBColor", "UndesirableClassUsage"}) public static void showMessage(String title, String message, boolean error) { - if (isCommandLine()) { + if (isCommandLine() || GraphicsEnvironment.isHeadless()) { PrintStream stream = error ? System.err : System.out; stream.println("\n" + title + ": " + message); } diff --git a/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java b/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java index 6f6cfaaeb9eb..cb1a4bf32fb2 100644 --- a/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java +++ b/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -118,7 +118,7 @@ public class IdeaApplication { if (headless && myStarter instanceof ApplicationStarterEx && !((ApplicationStarterEx)myStarter).isHeadless()) { Main.showMessage("Startup Error", "Application cannot start in headless mode", true); - System.exit(Main.STARTUP_IMPOSSIBLE); + System.exit(Main.NO_GRAPHICS); } myStarter.premain(args); diff --git a/platform/platform-impl/src/com/intellij/idea/StartupUtil.java b/platform/platform-impl/src/com/intellij/idea/StartupUtil.java index f930ad6535d6..e4805a1efff8 100644 --- a/platform/platform-impl/src/com/intellij/idea/StartupUtil.java +++ b/platform/platform-impl/src/com/intellij/idea/StartupUtil.java @@ -88,9 +88,15 @@ public class StartupUtil { newConfigFolder = !new File(PathManager.getConfigPath()).exists(); } - boolean canStart = checkJdkVersion() && checkSystemFolders() && lockSystemFolders(args); // note: uses config folder! - if (!canStart) { - System.exit(Main.STARTUP_IMPOSSIBLE); + if (!checkJdkVersion()) { + System.exit(Main.JDK_CHECK_FAILED); + } + // note: uses config folder! + if (!checkSystemFolders()) { + System.exit(Main.DIR_CHECK_FAILED); + } + if (!lockSystemFolders(args)) { + System.exit(Main.INSTANCE_CHECK_FAILED); } if (newConfigFolder) { -- 2.32.0