diff options
Diffstat (limited to 'platform/platform-impl/src/com/intellij/diagnostic')
3 files changed, 86 insertions, 301 deletions
diff --git a/platform/platform-impl/src/com/intellij/diagnostic/ITNReporter.java b/platform/platform-impl/src/com/intellij/diagnostic/ITNReporter.java index e430f9fdb513..b951b59ed9dd 100644 --- a/platform/platform-impl/src/com/intellij/diagnostic/ITNReporter.java +++ b/platform/platform-impl/src/com/intellij/diagnostic/ITNReporter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -16,11 +16,11 @@ package com.intellij.diagnostic; import com.intellij.CommonBundle; -import com.intellij.errorreport.ErrorReportSender; import com.intellij.errorreport.bean.ErrorBean; import com.intellij.errorreport.error.InternalEAPException; import com.intellij.errorreport.error.NoSuchEAPUserException; import com.intellij.errorreport.error.UpdateAvailableException; +import com.intellij.errorreport.itn.ITNProxy; import com.intellij.ide.DataManager; import com.intellij.ide.plugins.IdeaPluginDescriptor; import com.intellij.ide.plugins.PluginManager; @@ -32,6 +32,7 @@ import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.ErrorReportSubmitter; import com.intellij.openapi.diagnostic.IdeaLoggingEvent; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.diagnostic.SubmittedReportInfo; import com.intellij.openapi.extensions.PluginId; import com.intellij.openapi.project.Project; @@ -39,7 +40,7 @@ import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.Consumer; import com.intellij.xml.util.XmlStringUtil; -import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; @@ -49,60 +50,39 @@ import java.awt.*; */ public class ITNReporter extends ErrorReportSubmitter { private static int previousExceptionThreadId = 0; - private static boolean wasException = false; - @NonNls private static final String URL_HEADER = "http://www.intellij.net/tracker/idea/viewSCR?publicId="; + @Override public String getReportActionText() { return DiagnosticBundle.message("error.report.to.jetbrains.action"); } - public SubmittedReportInfo submit(IdeaLoggingEvent[] events, Component parentComponent) { - // obsolete API - return new SubmittedReportInfo(null, "0", SubmittedReportInfo.SubmissionStatus.FAILED); - } - @Override - public boolean trySubmitAsync(IdeaLoggingEvent[] events, - String additionalInfo, - Component parentComponent, - Consumer<SubmittedReportInfo> consumer) { - return sendError(events[0], additionalInfo, parentComponent, consumer); + public boolean submit(@NotNull IdeaLoggingEvent[] events, + String additionalInfo, + @NotNull Component parentComponent, + @NotNull Consumer<SubmittedReportInfo> consumer) { + ErrorBean errorBean = new ErrorBean(events[0].getThrowable(), IdeaLogger.ourLastActionId); + return doSubmit(events[0], parentComponent, consumer, errorBean, additionalInfo); } /** - * Could be used to enable error reporting even in release versions from non-internal mode. - * @return false by default. + * Used to enable error reporting even in release versions. */ - @SuppressWarnings({"MethodMayBeStatic", "UnusedParameters"}) public boolean showErrorInRelease(IdeaLoggingEvent event) { return false; } - /** - * @noinspection ThrowablePrintStackTrace - */ - private static boolean sendError(IdeaLoggingEvent event, - String additionalInfo, - final Component parentComponent, - final Consumer<SubmittedReportInfo> callback) { - ErrorBean errorBean = new ErrorBean(event.getThrowable(), IdeaLogger.ourLastActionId); - - return doSubmit(event, parentComponent, callback, errorBean, additionalInfo); - } - private static boolean doSubmit(final IdeaLoggingEvent event, - final Component parentComponent, - final Consumer<SubmittedReportInfo> callback, - final ErrorBean errorBean, - final String description) { + final Component parentComponent, + final Consumer<SubmittedReportInfo> callback, + final ErrorBean errorBean, + final String description) { final DataContext dataContext = DataManager.getInstance().getDataContext(parentComponent); final Project project = CommonDataKeys.PROJECT.getData(dataContext); - final ErrorReportConfigurable errorReportConfigurable = ErrorReportConfigurable.getInstance(); - if (!errorReportConfigurable.KEEP_ITN_PASSWORD && - !StringUtil.isEmpty(errorReportConfigurable.ITN_LOGIN) && - StringUtil.isEmpty(errorReportConfigurable.getPlainItnPassword())) { - final JetBrainsAccountDialog dlg = new JetBrainsAccountDialog(parentComponent); + ErrorReportConfigurable settings = ErrorReportConfigurable.getInstance(); + if (!settings.KEEP_ITN_PASSWORD && !StringUtil.isEmpty(settings.ITN_LOGIN) && StringUtil.isEmpty(settings.getPlainItnPassword())) { + JetBrainsAccountDialog dlg = new JetBrainsAccountDialog(parentComponent); dlg.show(); if (!dlg.isOK()) { return false; @@ -129,55 +109,46 @@ public class ITNReporter extends ErrorReportSubmitter { } Object data = event.getData(); - if (data instanceof AbstractMessage) { errorBean.setAssigneeId(((AbstractMessage)data).getAssigneeId()); } - if (data instanceof LogMessageEx) { errorBean.setAttachments(((LogMessageEx)data).getAttachments()); } - @NonNls String login = errorReportConfigurable.ITN_LOGIN; - @NonNls String password = errorReportConfigurable.getPlainItnPassword(); - if (login.trim().length() == 0 && password.trim().length() == 0) { + String login = settings.ITN_LOGIN; + String password = settings.getPlainItnPassword(); + if (StringUtil.isEmptyOrSpaces(login) && StringUtil.isEmptyOrSpaces(password)) { login = "idea_anonymous"; password = "guest"; } - ErrorReportSender.sendError(project, login, password, errorBean, new Consumer<Integer>() { - @SuppressWarnings({"AssignmentToStaticFieldFromInstanceMethod"}) + ITNProxy.sendError(project, login, password, errorBean, new Consumer<Integer>() { @Override public void consume(Integer threadId) { - previousExceptionThreadId = threadId; - wasException = true; - final SubmittedReportInfo reportInfo = new SubmittedReportInfo(URL_HEADER + threadId, String.valueOf(threadId), - SubmittedReportInfo.SubmissionStatus.NEW_ISSUE); + updatePreviousThreadId(threadId); + String url = ITNProxy.getBrowseUrl(threadId); + String linkText = String.valueOf(threadId); + final SubmittedReportInfo reportInfo = new SubmittedReportInfo(url, linkText, SubmittedReportInfo.SubmissionStatus.NEW_ISSUE); callback.consume(reportInfo); ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { StringBuilder text = new StringBuilder(); - final String url = IdeErrorsDialog.getUrl(reportInfo, true); - IdeErrorsDialog.appendSubmissionInformation(reportInfo, text, url); - text.append("."); - if (reportInfo.getStatus() != SubmittedReportInfo.SubmissionStatus.FAILED) { - text.append("<br/>").append(DiagnosticBundle.message("error.report.gratitude")); - } - - NotificationType type = reportInfo.getStatus() == SubmittedReportInfo.SubmissionStatus.FAILED - ? NotificationType.ERROR - : NotificationType.INFORMATION; - NotificationListener listener = url != null ? new NotificationListener.UrlOpeningListener(true) : null; - ReportMessages.GROUP.createNotification(ReportMessages.ERROR_REPORT, - XmlStringUtil.wrapInHtml(text), - type, listener).setImportant(false).notify(project); + IdeErrorsDialog.appendSubmissionInformation(reportInfo, text); + text.append('.').append("<br/>").append(DiagnosticBundle.message("error.report.gratitude")); + String content = XmlStringUtil.wrapInHtml(text); + ReportMessages.GROUP + .createNotification(ReportMessages.ERROR_REPORT, content, NotificationType.INFORMATION, NotificationListener.URL_OPENING_LISTENER) + .setImportant(false) + .notify(project); } }); } }, new Consumer<Exception>() { @Override public void consume(final Exception e) { + Logger.getInstance(ITNReporter.class).info("reporting failed: " + e); ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { @@ -192,13 +163,12 @@ public class ITNReporter extends ErrorReportSubmitter { msg = DiagnosticBundle.message("error.report.sending.failure"); } if (e instanceof UpdateAvailableException) { - String message = DiagnosticBundle.message( - "error.report.new.eap.build.message", e.getMessage()); - showMessageDialog(parentComponent, project, message, CommonBundle.getWarningTitle(), Messages.getWarningIcon()); - callback.consume(new SubmittedReportInfo(null, "0", SubmittedReportInfo.SubmissionStatus.FAILED)); + String message = DiagnosticBundle.message("error.report.new.eap.build.message", e.getMessage()); + showMessageDialog(parentComponent, project, message, CommonBundle.getWarningTitle(), Messages.getWarningIcon()); + callback.consume(new SubmittedReportInfo(SubmittedReportInfo.SubmissionStatus.FAILED)); } else if (showYesNoDialog(parentComponent, project, msg, ReportMessages.ERROR_REPORT, Messages.getErrorIcon()) != Messages.YES) { - callback.consume(new SubmittedReportInfo(null, "0", SubmittedReportInfo.SubmissionStatus.FAILED)); + callback.consume(new SubmittedReportInfo(SubmittedReportInfo.SubmissionStatus.FAILED)); } else { if (e instanceof NoSuchEAPUserException) { @@ -225,10 +195,15 @@ public class ITNReporter extends ErrorReportSubmitter { return true; } + private static void updatePreviousThreadId(Integer threadId) { + previousExceptionThreadId = threadId; + } + private static void showMessageDialog(Component parentComponent, Project project, String message, String title, Icon icon) { if (parentComponent.isShowing()) { Messages.showMessageDialog(parentComponent, message, title, icon); - } else { + } + else { Messages.showMessageDialog(project, message, title, icon); } } @@ -237,7 +212,8 @@ public class ITNReporter extends ErrorReportSubmitter { private static int showYesNoDialog(Component parentComponent, Project project, String message, String title, Icon icon) { if (parentComponent.isShowing()) { return Messages.showYesNoDialog(parentComponent, message, title, icon); - } else { + } + else { return Messages.showYesNoDialog(project, message, title, icon); } } diff --git a/platform/platform-impl/src/com/intellij/diagnostic/IdeErrorsDialog.java b/platform/platform-impl/src/com/intellij/diagnostic/IdeErrorsDialog.java index ac296d677232..a0e96c5d674e 100644 --- a/platform/platform-impl/src/com/intellij/diagnostic/IdeErrorsDialog.java +++ b/platform/platform-impl/src/com/intellij/diagnostic/IdeErrorsDialog.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -563,9 +563,9 @@ public class IdeErrorsDialog extends DialogWrapper implements MessagePoolListene String url = null; if (message.isSubmitted()) { - final SubmittedReportInfo info = message.getSubmissionInfo(); - url = getUrl(info, getSubmitter(throwable) instanceof ITNReporter); - appendSubmissionInformation(info, text, url); + SubmittedReportInfo info = message.getSubmissionInfo(); + url = info.getURL(); + appendSubmissionInformation(info, text); text.append(". "); } else if (message.isSubmitting()) { @@ -578,33 +578,18 @@ public class IdeErrorsDialog extends DialogWrapper implements MessagePoolListene myInfoLabel.setHyperlinkTarget(url); } - public static void appendSubmissionInformation(SubmittedReportInfo info, StringBuilder out, @Nullable String url) { + public static void appendSubmissionInformation(SubmittedReportInfo info, StringBuilder out) { if (info.getStatus() == SubmittedReportInfo.SubmissionStatus.FAILED) { out.append(" ").append(DiagnosticBundle.message("error.list.message.submission.failed")); } - else { - if (info.getLinkText() != null) { - out.append(" ").append(DiagnosticBundle.message("error.list.message.submitted.as.link", url, info.getLinkText())); - if (info.getStatus() == SubmittedReportInfo.SubmissionStatus.DUPLICATE) { - out.append(" ").append(DiagnosticBundle.message("error.list.message.duplicate")); - } - } - else { - out.append(DiagnosticBundle.message("error.list.message.submitted")); + else if (info.getURL() != null && info.getLinkText() != null) { + out.append(" ").append(DiagnosticBundle.message("error.list.message.submitted.as.link", info.getURL(), info.getLinkText())); + if (info.getStatus() == SubmittedReportInfo.SubmissionStatus.DUPLICATE) { + out.append(" ").append(DiagnosticBundle.message("error.list.message.duplicate")); } } - } - - @Nullable - public static String getUrl(SubmittedReportInfo info, boolean reportedToJetbrains) { - if (info.getStatus() == SubmittedReportInfo.SubmissionStatus.FAILED || info.getLinkText() == null) { - return null; - } - if (reportedToJetbrains) { - return "http://ea.jetbrains.com/browser/ea_reports/" + info.getLinkText(); - } else { - return info.getURL(); + out.append(DiagnosticBundle.message("error.list.message.submitted")); } } @@ -919,38 +904,37 @@ public class IdeErrorsDialog extends DialogWrapper implements MessagePoolListene private boolean reportMessage(final AbstractMessage logMessage, final boolean dialogClosed) { final ErrorReportSubmitter submitter = getSubmitter(logMessage.getThrowable()); + if (submitter == null) return false; - if (submitter != null) { - logMessage.setSubmitting(true); - if (!dialogClosed) { - updateControls(); - } - Container parentComponent; - if (dialogClosed) { - IdeFrame ideFrame = UIUtil.getParentOfType(IdeFrame.class, getContentPane()); - parentComponent = ideFrame.getComponent(); - } - else { - parentComponent = getContentPane(); - } - return submitter.trySubmitAsync(getEvents(logMessage), logMessage.getAdditionalInfo(), parentComponent, - new Consumer<SubmittedReportInfo>() { - @Override - public void consume(final SubmittedReportInfo submittedReportInfo) { - logMessage.setSubmitting(false); - logMessage.setSubmitted(submittedReportInfo); - ApplicationManager.getApplication().invokeLater(new Runnable() { - @Override - public void run() { - if (!dialogClosed) { - updateOnSubmit(); - } - } - }); - } - }); + logMessage.setSubmitting(true); + if (!dialogClosed) { + updateControls(); } - return false; + Container parentComponent; + if (dialogClosed) { + IdeFrame ideFrame = UIUtil.getParentOfType(IdeFrame.class, getContentPane()); + parentComponent = ideFrame.getComponent(); + } + else { + parentComponent = getContentPane(); + } + + return submitter.submit( + getEvents(logMessage), logMessage.getAdditionalInfo(), parentComponent, new Consumer<SubmittedReportInfo>() { + @Override + public void consume(final SubmittedReportInfo submittedReportInfo) { + logMessage.setSubmitting(false); + logMessage.setSubmitted(submittedReportInfo); + ApplicationManager.getApplication().invokeLater(new Runnable() { + @Override + public void run() { + if (!dialogClosed) { + updateOnSubmit(); + } + } + }); + } + }); } private IdeaLoggingEvent[] getEvents(final AbstractMessage logMessage) { diff --git a/platform/platform-impl/src/com/intellij/diagnostic/SubmitPerformanceReportAction.java b/platform/platform-impl/src/com/intellij/diagnostic/SubmitPerformanceReportAction.java deleted file mode 100644 index 88798381f8a8..000000000000 --- a/platform/platform-impl/src/com/intellij/diagnostic/SubmitPerformanceReportAction.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright 2000-2013 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.diagnostic; - -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.application.ApplicationInfo; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.PathManager; -import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.progress.Task; -import com.intellij.openapi.project.DumbAware; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.util.SystemProperties; -import com.intellij.util.io.ZipUtil; -import org.apache.commons.net.ftp.FTPClient; -import org.apache.commons.net.ftp.FTPReply; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.*; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.zip.ZipOutputStream; - -/** - * @author yole - */ -public class SubmitPerformanceReportAction extends AnAction implements DumbAware { - private final DateFormat myDateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss"); - - private static final String MESSAGE_TITLE = "Submit Performance Report"; - - public void actionPerformed(final AnActionEvent e) { - String reportFileName = "perf_" + ApplicationInfo.getInstance().getBuild().asString() + "_" + - SystemProperties.getUserName() + "_" + myDateFormat.format(new Date()) + ".zip"; - final File reportPath = new File(SystemProperties.getUserHome(), reportFileName); - final File logDir = new File(PathManager.getLogPath()); - final Project project = e.getData(CommonDataKeys.PROJECT); - - final boolean[] archiveCreated = new boolean[1]; - final boolean completed = ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() { - public void run() { - try { - ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(reportPath)); - ZipUtil.addDirToZipRecursively(zip, reportPath, logDir, "", new FileFilter() { - public boolean accept(final File pathname) { - ProgressManager.checkCanceled(); - - if (logDir.equals(pathname.getParentFile())) { - return pathname.getPath().contains("threadDumps"); - } - return true; - } - }, null); - zip.close(); - archiveCreated[0] = true; - } - catch (final IOException ex) { - ApplicationManager.getApplication().invokeLater(new Runnable() { - public void run() { - Messages.showErrorDialog(project, "Failed to create performance report archive: " + ex.getMessage(), MESSAGE_TITLE); - } - }); - } - } - }, "Collecting Performance Report data", true, project); - - if (!completed || - !archiveCreated[0]) { - return; - } - - int rc = Messages.showYesNoDialog(project, "The performance report has been saved to\n" + reportPath + - "\n\nWould you like to submit it to JetBrains?", MESSAGE_TITLE, - Messages.getQuestionIcon()); - if (rc == Messages.YES) { - ProgressManager.getInstance().run(new Task.Backgroundable(project, "Uploading Performance Report") { - public void run(@NotNull final ProgressIndicator indicator) { - final String error = uploadFileToFTP(reportPath, "ftp.intellij.net", ".uploads", indicator); - if (error != null) { - ApplicationManager.getApplication().invokeLater(new Runnable() { - public void run() { - Messages.showErrorDialog(error, MESSAGE_TITLE); - } - }); - } - } - }); - } - } - - @Nullable - private static String uploadFileToFTP(final File reportPath, @NonNls final String ftpSite, @NonNls final String directory, - final ProgressIndicator indicator) { - FTPClient ftp = new FTPClient(); - ftp.setConnectTimeout(30 * 1000); - try { - indicator.setText("Connecting to server..."); - ftp.connect(ftpSite); - indicator.setText("Connected to server"); - - if (!ftp.login("anonymous", "anonymous@jetbrains.com")) { - return "Failed to login"; - } - indicator.setText("Logged in"); - - // After connection attempt, you should check the reply code to verify - // success. - int reply = ftp.getReplyCode(); - - if (!FTPReply.isPositiveCompletion(reply)) { - ftp.disconnect(); - return "FTP server refused connection: " + reply; - } - if (!ftp.changeWorkingDirectory(directory)) { - return "Failed to change directory"; - } - - // else won't work behind FW - ftp.enterLocalPassiveMode(); - - if (!ftp.setFileType(FTPClient.BINARY_FILE_TYPE)) { - return "Failed to switch to binary mode"; - } - - indicator.setText("Transferring (" + StringUtil.formatFileSize(reportPath.length()) + ")"); - FileInputStream readStream = new FileInputStream(reportPath); - try { - if (!ftp.storeFile(reportPath.getName(), readStream)) { - return "Failed to upload file"; - } - } catch (IOException e) { - return "Error during transfer: " + e.getMessage(); - } - finally { - readStream.close(); - } - ftp.logout(); - return null; - } - catch (IOException e) { - return "Failed to upload: " + e.getMessage(); - } - finally { - if (ftp.isConnected()) { - try { - ftp.disconnect(); - } - catch (IOException ioe) { - // do nothing - } - } - } - } -} |