summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorRaphael Moll <ralf@android.com>2013-11-18 15:33:09 -0800
committerRaphael Moll <ralf@android.com>2013-11-21 11:33:28 -0800
commit41f187478b6f40dc2fe4fbe15bd413e0067cad83 (patch)
treeff3fd008daa30ea96efe0837535685431e6c4006 /platform
parent3a50b93293211f3aa28d5b3dc0ca5b17c3757ef5 (diff)
downloadidea-41f187478b6f40dc2fe4fbe15bd413e0067cad83.tar.gz
Add basic logging to patch/updater.
Change-Id: Iec5636e904ae153c8e54bfbb1a1a80b97fca9af6
Diffstat (limited to 'platform')
-rwxr-xr-x[-rw-r--r--]platform/bootstrap/src/com/intellij/idea/Main.java90
-rwxr-xr-x[-rw-r--r--]platform/platform-impl/src/com/intellij/idea/StartupUtil.java1
-rwxr-xr-x[-rw-r--r--]platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java2
3 files changed, 88 insertions, 5 deletions
diff --git a/platform/bootstrap/src/com/intellij/idea/Main.java b/platform/bootstrap/src/com/intellij/idea/Main.java
index c9a3f8e68004..25ef04226791 100644..100755
--- a/platform/bootstrap/src/com/intellij/idea/Main.java
+++ b/platform/bootstrap/src/com/intellij/idea/Main.java
@@ -17,6 +17,7 @@ package com.intellij.idea;
import com.intellij.ide.Bootstrap;
import com.intellij.openapi.application.PathManager;
+import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.SystemInfoRt;
import com.intellij.openapi.util.io.FileUtilRt;
@@ -26,10 +27,12 @@ import com.intellij.util.Restarter;
import javax.swing.*;
import java.awt.*;
import java.io.*;
-import java.util.ArrayList;
-import java.util.Collections;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.*;
import java.util.List;
+
@SuppressWarnings({"UseOfSystemOutOrSystemErr", "MethodNamesDifferingOnlyByCase"})
public class Main {
public static final int UPDATE_FAILED = 1;
@@ -42,6 +45,8 @@ public class Main {
private static final String PLATFORM_PREFIX_PROPERTY = "idea.platform.prefix";
private static final String[] NO_ARGS = {};
+ private static final String MAIN_LOG_PROPERTY = "com.intellij.idea.Main.DelayedLog";
+
private static boolean isHeadless;
private static boolean isCommandLine;
@@ -67,8 +72,9 @@ public class Main {
installPatch();
}
catch (Throwable t) {
+ appendLog("Exception: " + t.toString() + '\n');
showMessage("Update Failed", t);
- System.exit(UPDATE_FAILED);
+ exit(UPDATE_FAILED);
}
}
}
@@ -78,10 +84,15 @@ public class Main {
}
catch (Throwable t) {
showMessage("Start Failed", t);
- System.exit(STARTUP_EXCEPTION);
+ exit(STARTUP_EXCEPTION);
}
}
+ private static void exit(int code) {
+ dumpDelayedLogging();
+ System.exit(code);
+ }
+
public static boolean isHeadless() {
return isHeadless;
}
@@ -131,11 +142,15 @@ public class Main {
throw new IOException("Cannot create temporary patch file");
}
+ appendLog("[Patch] Original patch %s: %s\n", originalPatchFile.exists() ? "exists" : "does not exist",
+ originalPatchFile.getAbsolutePath());
+
if (!originalPatchFile.exists()) {
return;
}
if (!originalPatchFile.renameTo(copyPatchFile) || !FileUtilRt.delete(originalPatchFile)) {
+ appendLog("[Patch] Cannot create temporary patch file\n");
throw new IOException("Cannot create temporary patch file");
}
@@ -158,13 +173,16 @@ public class Main {
PathManager.getHomePath());
status = Restarter.scheduleRestart(ArrayUtilRt.toStringArray(args));
+
+ appendLog("[Patch] Restarted status: %d, cmd: %s\n", status, args.toString());
}
else {
+ appendLog("[Patch] Restart is not supported\n");
String message = "Patch update is not supported - please do it manually";
showMessage("Update Error", message, true);
}
- System.exit(status);
+ exit(status);
}
public static void showMessage(String title, Throwable t) {
@@ -174,6 +192,12 @@ public class Main {
message.append(studio ? "code.google.com/p/android/issues" : "youtrack.jetbrains.com");
message.append("\n\n");
t.printStackTrace(new PrintWriter(message));
+
+ String p = System.getProperty(MAIN_LOG_PROPERTY);
+ if (p != null) {
+ message.append('\n').append(p);
+ }
+
showMessage(title, message.toString(), true);
}
@@ -207,4 +231,60 @@ public class Main {
JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), scrollPane, title, type);
}
}
+
+
+ /**
+ * Appends the non-null string to an internal log property because at
+ * this point when the updater runs the main logger hasn't been setup yet.
+ *
+ * We use a system property rather than a global static variable because
+ * both codes do not run in the same ClassLoader and don't have the same
+ * globals.
+ */
+ private static void appendLog(String message, Object...params) {
+ String p = System.getProperty(MAIN_LOG_PROPERTY);
+ DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ");
+ String s = dateFormat.format(new Date()) + String.format(message, params);
+ if (p == null) {
+ p = s;
+ } else {
+ p += s;
+ }
+ System.setProperty(MAIN_LOG_PROPERTY, p);
+ }
+
+ /** Invoked by Main to dump the log when the Main is exiting right away.
+ * The normal IDE log will not be used. */
+ public static void dumpDelayedLogging() {
+ String p = System.getProperty(MAIN_LOG_PROPERTY);
+ if (p != null) {
+ System.clearProperty(MAIN_LOG_PROPERTY);
+ File log = new File(PathManager.getLogPath());
+ //noinspection ResultOfMethodCallIgnored
+ log.mkdirs();
+ log = new File(log, "idea_patch.log");
+ FileOutputStream fos = null;
+ try {
+ //noinspection IOResourceOpenedButNotSafelyClosed
+ fos = new FileOutputStream(log, true /*append*/);
+ fos.write(p.getBytes("UTF-8"));
+ } catch (IOException ignore) {
+ } finally {
+ if (fos != null) {
+ try { fos.close(); } catch (IOException ignored) {}
+ }
+ }
+ }
+ }
+
+ /** Invoked by StartupUtil once the main logger is setup. */
+ public static void dumpDelayedLogging(Logger log) {
+ if (log != null) {
+ String p = System.getProperty(MAIN_LOG_PROPERTY);
+ if (p != null) {
+ log.info(p);
+ System.clearProperty(MAIN_LOG_PROPERTY);
+ }
+ }
+ }
}
diff --git a/platform/platform-impl/src/com/intellij/idea/StartupUtil.java b/platform/platform-impl/src/com/intellij/idea/StartupUtil.java
index 823187461f55..90d36d8f497c 100644..100755
--- a/platform/platform-impl/src/com/intellij/idea/StartupUtil.java
+++ b/platform/platform-impl/src/com/intellij/idea/StartupUtil.java
@@ -105,6 +105,7 @@ public class StartupUtil {
Logger log = Logger.getInstance(Main.class);
startLogging(log);
loadSystemLibraries(log);
+ Main.dumpDelayedLogging(log);
fixProcessEnvironment(log);
if (!Main.isHeadless()) {
diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java
index 32d6e41e447e..6ef2497d29d2 100644..100755
--- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java
+++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java
@@ -739,6 +739,7 @@ public final class UpdateChecker {
String platform = PlatformUtils.getPlatformPrefix();
File tempFile = FileUtil.createTempFile(platform, "patch", true);
+ LOG.info(String.format("[Patch] Download %s to %s", fileName, tempFile.getAbsolutePath()));
OutputStream out = new BufferedOutputStream(new FileOutputStream(tempFile));
try {
@@ -804,6 +805,7 @@ public final class UpdateChecker {
File patchFile = new File(FileUtil.getTempDirectory(), patchFileName);
FileUtil.copy(tempFile, patchFile);
FileUtil.delete(tempFile);
+ LOG.info(String.format("[Patch] moved to %s", patchFile.getAbsolutePath()));
}
public static Set<String> getDisabledToUpdatePlugins() {