2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.errorreport
;
18 import com
.intellij
.diagnostic
.DiagnosticBundle
;
19 import com
.intellij
.errorreport
.bean
.ErrorBean
;
20 import com
.intellij
.errorreport
.bean
.ExceptionBean
;
21 import com
.intellij
.errorreport
.bean
.NotifierBean
;
22 import com
.intellij
.errorreport
.error
.InternalEAPException
;
23 import com
.intellij
.errorreport
.error
.NewBuildException
;
24 import com
.intellij
.errorreport
.error
.NoSuchEAPUserException
;
25 import com
.intellij
.errorreport
.itn
.ITNProxy
;
26 import com
.intellij
.ide
.reporter
.ConnectionException
;
27 import com
.intellij
.idea
.IdeaLogger
;
28 import com
.intellij
.openapi
.progress
.ProgressManager
;
29 import com
.intellij
.openapi
.project
.Project
;
30 import com
.intellij
.openapi
.updateSettings
.impl
.BuildInfo
;
31 import com
.intellij
.openapi
.updateSettings
.impl
.UpdateChannel
;
32 import com
.intellij
.openapi
.updateSettings
.impl
.UpdateChecker
;
33 import com
.intellij
.openapi
.util
.Ref
;
34 import com
.intellij
.util
.net
.HttpConfigurable
;
35 import org
.jetbrains
.annotations
.NonNls
;
37 import java
.io
.IOException
;
40 * Created by IntelliJ IDEA.
44 * To change this template use Options | File Templates.
46 public class ErrorReportSender
{
47 @NonNls public static final String PREPARE_URL
= "http://www.intellij.net/";
48 //public static String REPORT_URL = "http://unit-038:8080/error/report?sender=i";
50 @NonNls public static final String PRODUCT_CODE
= "idea";
51 @NonNls private static final String PARAM_EMAIL
= "EMAIL";
52 @NonNls private static final String PARAM_EAP
= "eap";
54 public static ErrorReportSender
getInstance () {
55 return new ErrorReportSender();
58 protected ErrorReportSender () {
62 private final Project myProject
;
63 private NotifierBean notifierBean
;
64 private ErrorBean errorBean
;
65 private final Throwable throwable
;
66 private ExceptionBean exceptionBean
;
68 public SendTask(final Project project
, Throwable throwable
) {
70 this.throwable
= throwable
;
73 public int getThreadId () {
74 return exceptionBean
.getItnThreadId();
77 public void setErrorBean(ErrorBean error
) {
81 public void setNotifierBean(NotifierBean notifierBean
) {
82 this.notifierBean
= notifierBean
;
85 public void checkNewBuild() throws NewBuildException
{
86 BuildInfo newVersion
= null;
88 UpdateChannel channel
= UpdateChecker
.checkForUpdates();
89 newVersion
= channel
!= null ? channel
.getLatestBuild() : null;
91 catch (ConnectionException e
) {
94 if (newVersion
!= null) {
95 throw new NewBuildException(newVersion
.getNumber().asString());
97 exceptionBean
= new ExceptionBean(throwable
);
100 public void sendReport() throws Exception
{
101 errorBean
.setExceptionHashCode(exceptionBean
.getHashCode());
103 final Ref
<Exception
> err
= new Ref
<Exception
>();
104 Runnable runnable
= new Runnable() {
107 HttpConfigurable
.getInstance().prepareURL(PREPARE_URL
);
109 if (notifierBean
.getItnLogin() != null && notifierBean
.getItnLogin().length() > 0) {
110 int threadId
= ITNProxy
.postNewThread(
111 notifierBean
.getItnLogin(),
112 notifierBean
.getItnPassword(),
113 errorBean
, exceptionBean
,
114 IdeaLogger
.getOurCompilationTimestamp());
115 exceptionBean
.setItnThreadId(threadId
);
118 catch (Exception ex
) {
123 if (myProject
== null) {
127 ProgressManager
.getInstance().runProcessWithProgressSynchronously(runnable
,
128 DiagnosticBundle
.message("title.submitting.error.report"),
137 private SendTask sendTask
;
139 public void prepareError(Project project
, Throwable exception
) throws IOException
, NewBuildException
{
141 sendTask
= new SendTask (project
, exception
);
144 sendTask
.checkNewBuild();
146 catch (NewBuildException e
) {
149 catch (Throwable e
) {
151 throw new RuntimeException(e
);
155 public int sendError (NotifierBean notifierBean
, ErrorBean error
)
156 throws IOException
, NoSuchEAPUserException
, InternalEAPException
{
158 sendTask
.setErrorBean (error
);
159 sendTask
.setNotifierBean (notifierBean
);
162 sendTask
.sendReport();
163 return sendTask
.getThreadId();
164 } catch (IOException e
) {
166 } catch (NoSuchEAPUserException e
) {
168 } catch (InternalEAPException e
) {
170 } catch (Throwable e
) {
172 throw new RuntimeException(e
);