package floobits.common;

import java.io.PrintWriter;
import java.io.Serializable;
import java.io.StringWriter;
import java.util.Date;
import java.util.HashMap;

public class CrashDump implements Serializable {
    public String owner;
    public String workspace;
    public String dir;
    public String subject;
    public String username;
    public static String userAgent;
    public HashMap<String, String> message = new HashMap<String, String>();
    private static String editor = "";

    public static void setUA(String userAgent, String editor) {
        CrashDump.userAgent = userAgent;
        CrashDump.editor = editor;
    }
    public CrashDump(Throwable e, String owner, String workspace, String dir, String username) {
        this.owner = owner;
        this.workspace = workspace;
        this.dir = dir;
        this.username = username;
        message.put("sendingAt", String.format("%s", new Date().getTime()));
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        message.put("stack", sw.toString());
        message.put("description", e.getMessage());
        setContextInfo("%s died%s!");
    }

    public CrashDump(String description, String username) {
        this.username = username;
        message.put("sendingAt", String.format("%s", new Date().getTime()));
        message.put("description", description);
        setContextInfo("%s submitted an issues%s!");
    }

    protected void setContextInfo(String subjectText) {
        subject = String.format(subjectText, editor, username != null ? " for " + username : "");
    }
}

@@ -19,16 +19,167 @@
 ommon;%0A%0A
+import com.intellij.ide.plugins.IdeaPluginDescriptor;%0Aimport com.intellij.ide.plugins.PluginManager;%0Aimport com.intellij.openapi.extensions.PluginId;%0A%0A
 import j
@@ -190,32 +190,32 @@
 io.PrintWriter;%0A
-
 import java.io.S
@@ -785,16 +785,160 @@
 ;%0A    %7D%0A
+%0A    private IdeaPluginDescriptor getPlugin() %7B%0A        return PluginManager.getPlugin(PluginId.getId(%22com.floobits.unique.plugin.id%22));%0A    %7D%0A%0A
     publ
@@ -1152,85 +1152,8 @@
 me;%0A
-        message.put(%22sendingAt%22, String.format(%22%25s%22, new Date().getTime()));%0A
     
@@ -1267,24 +1267,57 @@
 kTrace(pw);%0A
+        addVersionInfo(message);%0A
         mess
@@ -1552,74 +1552,30 @@
     
-message.put(%22sendingAt%22, String.format(%22%25s%22, new Date().getTime())
+addVersionInfo(message
 );%0A 
@@ -1734,24 +1734,24 @@
 jectText) %7B%0A
-
         subj
@@ -1841,11 +1841,407 @@
 );%0A    %7D
+%0A%0A    private void addVersionInfo(HashMap%3CString, String%3E message) %7B%0A        IdeaPluginDescriptor p = getPlugin();%0A        if (p != null) %7B%0A            message.put(%22floobits_plugin_version%22, p.getVersion());%0A        %7D else %7B%0A            message.put(%22floobits_plugin_version%22, %22No version information.%22);%0A        %7D%0A        message.put(%22sendingAt%22, String.format(%22%25s%22, new Date().getTime()));%0A    %7D
 %0A%7D%0A

Add plugin version info to crash reports.