Search in sources :

Example 26 with PluginId

use of com.intellij.openapi.extensions.PluginId in project flutter-intellij by flutter.

the class FlutterErrorReportSubmitter method submitAsync.

@SuppressWarnings("deprecation")
@Override
public void submitAsync(@NotNull IdeaLoggingEvent[] events, @Nullable String additionalInfo, @NotNull Component parentComponent, @NotNull Consumer<SubmittedReportInfo> consumer) {
    if (events.length == 0) {
        consumer.consume(new SubmittedReportInfo(null, null, SubmittedReportInfo.SubmissionStatus.FAILED));
        return;
    }
    final DataContext dataContext = DataManager.getInstance().getDataContext(parentComponent);
    Project project = PlatformDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
        project = ProjectManager.getInstance().getDefaultProject();
    }
    final StringBuilder builder = new StringBuilder();
    builder.append("Please file this bug report at https://github.com/flutter/flutter-intellij/issues/new.\n");
    builder.append("\n");
    builder.append("---\n");
    builder.append("\n");
    builder.append("## What happened\n");
    builder.append("\n");
    if (additionalInfo != null) {
        builder.append(additionalInfo.trim()).append("\n");
    } else {
        builder.append("(please describe what you were doing when this exception occurred)\n");
    }
    builder.append("\n");
    builder.append("## Version information\n");
    builder.append("\n");
    // IntelliJ version
    final ApplicationInfo info = ApplicationInfo.getInstance();
    builder.append(info.getVersionName()).append(" `").append(info.getFullVersion()).append("`");
    final PluginId pid = FlutterUtils.getPluginId();
    final IdeaPluginDescriptor flutterPlugin = PluginManager.getPlugin(pid);
    // noinspection ConstantConditions
    builder.append(" • Flutter plugin `").append(pid.getIdString()).append(' ').append(flutterPlugin.getVersion()).append("`");
    final IdeaPluginDescriptor dartPlugin = PluginManager.getPlugin(PluginId.getId("Dart"));
    if (dartPlugin != null) {
        // noinspection ConstantConditions
        builder.append(" • Dart plugin `").append(dartPlugin.getVersion()).append("`");
    }
    builder.append("\n\n");
    final FlutterSdk sdk = FlutterSdk.getFlutterSdk(project);
    if (sdk == null) {
        builder.append("No Flutter sdk configured.\n");
    } else {
        final String flutterVersion = getFlutterVersion(sdk);
        if (flutterVersion != null) {
            builder.append(flutterVersion.trim()).append("\n");
        } else {
            builder.append("Error getting Flutter sdk information.\n");
        }
    }
    builder.append("\n");
    for (IdeaLoggingEvent event : events) {
        builder.append("## Exception\n");
        builder.append("\n");
        builder.append(event.getMessage()).append("\n");
        builder.append("\n");
        if (event.getThrowable() != null) {
            builder.append("```\n");
            builder.append(event.getThrowableText().trim()).append("\n");
            builder.append("```\n");
            builder.append("\n");
            FlutterInitializer.getAnalytics().sendException(event.getThrowable(), false);
        }
    }
    final String text = builder.toString().trim() + "\n";
    // Create scratch file.
    final ScratchRootType scratchRoot = ScratchRootType.getInstance();
    final VirtualFile file = scratchRoot.createScratchFile(project, "bug-report.md", Language.ANY, text);
    if (file != null) {
        // Open the file.
        new OpenFileDescriptor(project, file).navigate(true);
    } else {
        consumer.consume(new SubmittedReportInfo(null, null, SubmittedReportInfo.SubmissionStatus.FAILED));
    }
    consumer.consume(new SubmittedReportInfo(null, "", SubmittedReportInfo.SubmissionStatus.NEW_ISSUE));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ApplicationInfo(com.intellij.openapi.application.ApplicationInfo) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginId(com.intellij.openapi.extensions.PluginId) IdeaLoggingEvent(com.intellij.openapi.diagnostic.IdeaLoggingEvent) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) FlutterSdk(io.flutter.sdk.FlutterSdk) ScratchRootType(com.intellij.ide.scratch.ScratchRootType) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) SubmittedReportInfo(com.intellij.openapi.diagnostic.SubmittedReportInfo)

Example 27 with PluginId

use of com.intellij.openapi.extensions.PluginId in project android by JetBrains.

the class ErrorReporter method submit.

@Override
public boolean submit(@NotNull IdeaLoggingEvent[] events, @Nullable String description, @Nullable Component parentComponent, @NotNull Consumer<SubmittedReportInfo> callback) {
    IdeaLoggingEvent event = events[0];
    ErrorBean bean = new ErrorBean(event.getThrowable(), IdeaLogger.ourLastActionId);
    final DataContext dataContext = DataManager.getInstance().getDataContext(parentComponent);
    bean.setDescription(description);
    bean.setMessage(event.getMessage());
    Throwable t = event.getThrowable();
    if (t != null) {
        final PluginId pluginId = IdeErrorsDialog.findPluginId(t);
        if (pluginId != null) {
            final IdeaPluginDescriptor ideaPluginDescriptor = PluginManager.getPlugin(pluginId);
            if (ideaPluginDescriptor != null && (!ideaPluginDescriptor.isBundled() || ideaPluginDescriptor.allowBundledUpdate())) {
                bean.setPluginName(ideaPluginDescriptor.getName());
                bean.setPluginVersion(ideaPluginDescriptor.getVersion());
            }
        }
    }
    Object data = event.getData();
    // Early escape (and no UI impact) if these are analytics events being pushed from the platform
    if (handleAnalyticsReports(t, data)) {
        return true;
    }
    if (data instanceof AbstractMessage) {
        bean.setAttachments(((AbstractMessage) data).getIncludedAttachments());
    }
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    Consumer<String> successCallback = token -> {
        final SubmittedReportInfo reportInfo = new SubmittedReportInfo(null, "Issue " + token, SubmittedReportInfo.SubmissionStatus.NEW_ISSUE);
        callback.consume(reportInfo);
        ReportMessages.GROUP.createNotification(ReportMessages.ERROR_REPORT, "Submitted", NotificationType.INFORMATION, null).setImportant(false).notify(project);
    };
    Consumer<Exception> errorCallback = e -> {
        String message = AndroidBundle.message("error.report.at.b.android", e.getMessage());
        ReportMessages.GROUP.createNotification(ReportMessages.ERROR_REPORT, message, NotificationType.ERROR, NotificationListener.URL_OPENING_LISTENER).setImportant(false).notify(project);
    };
    Task.Backgroundable feedbackTask;
    if (data instanceof ErrorReportCustomizer) {
        feedbackTask = ((ErrorReportCustomizer) data).makeReportingTask(project, FEEDBACK_TASK_TITLE, true, bean, successCallback, errorCallback);
    } else {
        List<Pair<String, String>> kv = IdeaITNProxy.getKeyValuePairs(null, null, bean, IdeaLogger.getOurCompilationTimestamp(), ApplicationManager.getApplication(), (ApplicationInfoEx) ApplicationInfo.getInstance(), ApplicationNamesInfo.getInstance(), UpdateSettings.getInstance());
        feedbackTask = new SubmitCrashReportTask(project, FEEDBACK_TASK_TITLE, true, t, pair2map(kv), successCallback, errorCallback);
    }
    if (project == null) {
        feedbackTask.run(new EmptyProgressIndicator());
    } else {
        ProgressManager.getInstance().run(feedbackTask);
    }
    return true;
}
Also used : SubmittedReportInfo(com.intellij.openapi.diagnostic.SubmittedReportInfo) DataContext(com.intellij.openapi.actionSystem.DataContext) IdeErrorsDialog(com.intellij.diagnostic.IdeErrorsDialog) ReportMessages(com.intellij.diagnostic.ReportMessages) Task(com.intellij.openapi.progress.Task) CrashReport(com.android.tools.idea.diagnostics.crash.CrashReport) ApplicationInfo(com.intellij.openapi.application.ApplicationInfo) Map(java.util.Map) ApplicationNamesInfo(com.intellij.openapi.application.ApplicationNamesInfo) Project(com.intellij.openapi.project.Project) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) ApplicationInfoEx(com.intellij.openapi.application.ex.ApplicationInfoEx) ErrorReportSubmitter(com.intellij.openapi.diagnostic.ErrorReportSubmitter) DataManager(com.intellij.ide.DataManager) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginManager(com.intellij.ide.plugins.PluginManager) ProgressManager(com.intellij.openapi.progress.ProgressManager) AndroidBundle(org.jetbrains.android.util.AndroidBundle) IdeaLogger(com.intellij.idea.IdeaLogger) IdeaLoggingEvent(com.intellij.openapi.diagnostic.IdeaLoggingEvent) Nullable(com.android.annotations.Nullable) Maps(com.google.common.collect.Maps) NotificationListener(com.intellij.notification.NotificationListener) NotificationType(com.intellij.notification.NotificationType) java.awt(java.awt) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ErrorBean(com.intellij.errorreport.bean.ErrorBean) List(java.util.List) AbstractMessage(com.intellij.diagnostic.AbstractMessage) CrashReporter(com.android.tools.idea.diagnostics.crash.CrashReporter) UpdateSettings(com.intellij.openapi.updateSettings.impl.UpdateSettings) Pair(com.intellij.openapi.util.Pair) ApplicationManager(com.intellij.openapi.application.ApplicationManager) IdeaITNProxy(org.jetbrains.android.diagnostics.error.IdeaITNProxy) NotNull(org.jetbrains.annotations.NotNull) PluginId(com.intellij.openapi.extensions.PluginId) Consumer(com.intellij.util.Consumer) Task(com.intellij.openapi.progress.Task) AbstractMessage(com.intellij.diagnostic.AbstractMessage) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginId(com.intellij.openapi.extensions.PluginId) IdeaLoggingEvent(com.intellij.openapi.diagnostic.IdeaLoggingEvent) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) ErrorBean(com.intellij.errorreport.bean.ErrorBean) SubmittedReportInfo(com.intellij.openapi.diagnostic.SubmittedReportInfo) Pair(com.intellij.openapi.util.Pair)

Example 28 with PluginId

use of com.intellij.openapi.extensions.PluginId in project intellij-community by JetBrains.

the class IdeErrorsDialog method updateForeignPluginLabel.

private void updateForeignPluginLabel(AbstractMessage message) {
    if (message != null) {
        final Throwable throwable = message.getThrowable();
        ErrorReportSubmitter submitter = getSubmitter(throwable);
        if (submitter == null) {
            PluginId pluginId = findPluginId(throwable);
            IdeaPluginDescriptor plugin = PluginManager.getPlugin(pluginId);
            if (plugin == null || PluginManagerMain.isDevelopedByJetBrains(plugin)) {
                myForeignPluginWarningPanel.setVisible(false);
                return;
            }
            myForeignPluginWarningPanel.setVisible(true);
            String vendor = plugin.getVendor();
            String contactInfo = plugin.getVendorUrl();
            if (StringUtil.isEmpty(contactInfo)) {
                contactInfo = plugin.getVendorEmail();
            }
            if (StringUtil.isEmpty(vendor)) {
                if (StringUtil.isEmpty(contactInfo)) {
                    myForeignPluginWarningLabel.setText(DiagnosticBundle.message("error.dialog.foreign.plugin.warning.text"));
                } else {
                    myForeignPluginWarningLabel.setHyperlinkText(DiagnosticBundle.message("error.dialog.foreign.plugin.warning.text.vendor") + " ", contactInfo, ".");
                    myForeignPluginWarningLabel.setHyperlinkTarget(contactInfo);
                }
            } else {
                if (StringUtil.isEmpty(contactInfo)) {
                    myForeignPluginWarningLabel.setText(DiagnosticBundle.message("error.dialog.foreign.plugin.warning.text.vendor") + " " + vendor + ".");
                } else {
                    myForeignPluginWarningLabel.setHyperlinkText(DiagnosticBundle.message("error.dialog.foreign.plugin.warning.text.vendor") + " " + vendor + " (", contactInfo, ").");
                    final String target = (StringUtil.equals(contactInfo, plugin.getVendorEmail()) ? "mailto:" : "") + contactInfo;
                    myForeignPluginWarningLabel.setHyperlinkTarget(target);
                }
            }
            myForeignPluginWarningPanel.setVisible(true);
            return;
        }
    }
    myForeignPluginWarningPanel.setVisible(false);
}
Also used : IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginId(com.intellij.openapi.extensions.PluginId)

Example 29 with PluginId

use of com.intellij.openapi.extensions.PluginId in project intellij-community by JetBrains.

the class IdeErrorsDialog method findPluginId.

@Nullable
public static PluginId findPluginId(Throwable t) {
    if (t instanceof PluginException) {
        return ((PluginException) t).getPluginId();
    }
    Set<String> visitedClassNames = ContainerUtil.newHashSet();
    for (StackTraceElement element : t.getStackTrace()) {
        if (element != null) {
            String className = element.getClassName();
            if (visitedClassNames.add(className) && PluginManagerCore.isPluginClass(className)) {
                PluginId id = PluginManagerCore.getPluginByClassName(className);
                if (LOG.isDebugEnabled()) {
                    LOG.debug(diagnosePluginDetection(className, id));
                }
                return id;
            }
        }
    }
    if (t instanceof NoSuchMethodException) {
        // check is method called from plugin classes
        if (t.getMessage() != null) {
            String className = "";
            StringTokenizer tok = new StringTokenizer(t.getMessage(), ".");
            while (tok.hasMoreTokens()) {
                String token = tok.nextToken();
                if (token.length() > 0 && Character.isJavaIdentifierStart(token.charAt(0))) {
                    className += token;
                }
            }
            if (PluginManagerCore.isPluginClass(className)) {
                return PluginManagerCore.getPluginByClassName(className);
            }
        }
    } else if (t instanceof ClassNotFoundException) {
        // check is class from plugin classes
        if (t.getMessage() != null) {
            String className = t.getMessage();
            if (PluginManagerCore.isPluginClass(className)) {
                return PluginManagerCore.getPluginByClassName(className);
            }
        }
    } else if (t instanceof AbstractMethodError && t.getMessage() != null) {
        String s = t.getMessage();
        // org.antlr.works.plugin.intellij.PIFileType.getHighlighter(Lcom/intellij/openapi/project/Project;Lcom/intellij/openapi/vfs/VirtualFile;)Lcom/intellij/openapi/fileTypes/SyntaxHighlighter;
        int pos = s.indexOf('(');
        if (pos >= 0) {
            s = s.substring(0, pos);
            pos = s.lastIndexOf('.');
            if (pos >= 0) {
                s = s.substring(0, pos);
                if (PluginManagerCore.isPluginClass(s)) {
                    return PluginManagerCore.getPluginByClassName(s);
                }
            }
        }
    } else if (t instanceof ExtensionException) {
        String className = ((ExtensionException) t).getExtensionClass().getName();
        if (PluginManagerCore.isPluginClass(className)) {
            return PluginManagerCore.getPluginByClassName(className);
        }
    }
    return null;
}
Also used : ExtensionException(com.intellij.openapi.extensions.ExtensionException) PluginId(com.intellij.openapi.extensions.PluginId) Nullable(org.jetbrains.annotations.Nullable)

Example 30 with PluginId

use of com.intellij.openapi.extensions.PluginId in project intellij-community by JetBrains.

the class ActionsTreeUtil method createPluginActionsMap.

public static Map<String, String> createPluginActionsMap() {
    Set<PluginId> visited = ContainerUtil.newHashSet();
    Map<String, String> result = ContainerUtil.newHashMap();
    for (IdeaPluginDescriptor descriptor : PluginManagerCore.getPlugins()) {
        PluginId id = descriptor.getPluginId();
        visited.add(id);
        if (PluginManagerCore.CORE_PLUGIN_ID.equals(id.getIdString()))
            continue;
        for (String actionId : ActionManagerEx.getInstanceEx().getPluginActions(id)) {
            result.put(actionId, descriptor.getName());
        }
    }
    for (PluginId id : PluginId.getRegisteredIds().values()) {
        if (visited.contains(id))
            continue;
        for (String actionId : ActionManagerEx.getInstanceEx().getPluginActions(id)) {
            result.put(actionId, id.getIdString());
        }
    }
    return result;
}
Also used : IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginId(com.intellij.openapi.extensions.PluginId)

Aggregations

PluginId (com.intellij.openapi.extensions.PluginId)54 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)25 NotNull (org.jetbrains.annotations.NotNull)10 IOException (java.io.IOException)8 IdeaLoggingEvent (com.intellij.openapi.diagnostic.IdeaLoggingEvent)6 Project (com.intellij.openapi.project.Project)6 Nullable (org.jetbrains.annotations.Nullable)6 SubmittedReportInfo (com.intellij.openapi.diagnostic.SubmittedReportInfo)5 PluginException (com.intellij.diagnostic.PluginException)4 DataContext (com.intellij.openapi.actionSystem.DataContext)4 NonNls (org.jetbrains.annotations.NonNls)4 ErrorBean (com.intellij.errorreport.bean.ErrorBean)3 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)3 PluginDownloader (com.intellij.openapi.updateSettings.impl.PluginDownloader)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 File (java.io.File)3 AbstractMessage (com.intellij.diagnostic.AbstractMessage)2 LogMessageEx (com.intellij.diagnostic.LogMessageEx)2 CantRunException (com.intellij.execution.CantRunException)2 DataManager (com.intellij.ide.DataManager)2