Search in sources :

Example 1 with PluginException

use of com.intellij.diagnostic.PluginException in project intellij-community by JetBrains.

the class ActionManagerImpl method error.

@NotNull
@Contract(pure = true)
private static RuntimeException error(@NotNull ActionStub stub, @NotNull Throwable original, @NotNull String template, @NotNull String className) {
    PluginId pluginId = stub.getPluginId();
    String text = MessageFormat.format(template, className);
    if (pluginId == null) {
        return new IllegalStateException(text);
    }
    return new PluginException(text, original, pluginId);
}
Also used : PluginException(com.intellij.diagnostic.PluginException) PluginId(com.intellij.openapi.extensions.PluginId) NotNull(org.jetbrains.annotations.NotNull) Contract(org.jetbrains.annotations.Contract)

Example 2 with PluginException

use of com.intellij.diagnostic.PluginException in project intellij-community by JetBrains.

the class ActionManagerImpl method processGroupElement.

private AnAction processGroupElement(Element element, final ClassLoader loader, PluginId pluginId) {
    final IdeaPluginDescriptor plugin = PluginManager.getPlugin(pluginId);
    ResourceBundle bundle = getActionsResourceBundle(loader, plugin);
    if (!GROUP_ELEMENT_NAME.equals(element.getName())) {
        reportActionError(pluginId, "unexpected name of element \"" + element.getName() + "\"");
        return null;
    }
    String className = element.getAttributeValue(CLASS_ATTR_NAME);
    if (className == null) {
        // use default group if class isn't specified
        if ("true".equals(element.getAttributeValue(COMPACT_ATTR_NAME))) {
            className = DefaultCompactActionGroup.class.getName();
        } else {
            className = DefaultActionGroup.class.getName();
        }
    }
    try {
        ActionGroup group;
        if (DefaultActionGroup.class.getName().equals(className)) {
            group = new DefaultActionGroup();
        } else if (DefaultCompactActionGroup.class.getName().equals(className)) {
            group = new DefaultCompactActionGroup();
        } else {
            Class aClass = Class.forName(className, true, loader);
            Object obj = new CachingConstructorInjectionComponentAdapter(className, aClass).getComponentInstance(ApplicationManager.getApplication().getPicoContainer());
            if (!(obj instanceof ActionGroup)) {
                reportActionError(pluginId, "class with name \"" + className + "\" should be instance of " + ActionGroup.class.getName());
                return null;
            }
            if (element.getChildren().size() != element.getChildren(ADD_TO_GROUP_ELEMENT_NAME).size()) {
                //
                if (!(obj instanceof DefaultActionGroup)) {
                    reportActionError(pluginId, "class with name \"" + className + "\" should be instance of " + DefaultActionGroup.class.getName() + " because there are children specified");
                    return null;
                }
            }
            group = (ActionGroup) obj;
        }
        // read ID and register loaded group
        String id = element.getAttributeValue(ID_ATTR_NAME);
        if (id != null && id.isEmpty()) {
            reportActionError(pluginId, "ID of the group cannot be an empty string");
            return null;
        }
        if (Boolean.valueOf(element.getAttributeValue(INTERNAL_ATTR_NAME)).booleanValue() && !ApplicationManagerEx.getApplicationEx().isInternal()) {
            myNotRegisteredInternalActionIds.add(id);
            return null;
        }
        if (id != null) {
            registerOrReplaceActionInner(element, id, group, pluginId);
        }
        Presentation presentation = group.getTemplatePresentation();
        // text
        String text = loadTextForElement(element, bundle, id, GROUP_ELEMENT_NAME);
        // don't override value which was set in API with empty value from xml descriptor
        if (!StringUtil.isEmpty(text) || presentation.getText() == null) {
            presentation.setText(text);
        }
        // description
        String description = loadDescriptionForElement(element, bundle, id, GROUP_ELEMENT_NAME);
        // don't override value which was set in API with empty value from xml descriptor
        if (!StringUtil.isEmpty(description) || presentation.getDescription() == null) {
            presentation.setDescription(description);
        }
        // icon
        setIcon(element.getAttributeValue(ICON_ATTR_NAME), className, loader, presentation, pluginId);
        // popup
        String popup = element.getAttributeValue(POPUP_ATTR_NAME);
        if (popup != null) {
            group.setPopup(Boolean.valueOf(popup).booleanValue());
        }
        // process all group's children. There are other groups, actions, references and links
        for (final Object o : element.getChildren()) {
            Element child = (Element) o;
            String name = child.getName();
            if (ACTION_ELEMENT_NAME.equals(name)) {
                AnAction action = processActionElement(child, loader, pluginId);
                if (action != null) {
                    assertActionIsGroupOrStub(action);
                    addToGroupInner(group, action, Constraints.LAST, isSecondary(child));
                }
            } else if (SEPARATOR_ELEMENT_NAME.equals(name)) {
                processSeparatorNode((DefaultActionGroup) group, child, pluginId);
            } else if (GROUP_ELEMENT_NAME.equals(name)) {
                AnAction action = processGroupElement(child, loader, pluginId);
                if (action != null) {
                    addToGroupInner(group, action, Constraints.LAST, false);
                }
            } else if (ADD_TO_GROUP_ELEMENT_NAME.equals(name)) {
                processAddToGroupNode(group, child, pluginId, isSecondary(child));
            } else if (REFERENCE_ELEMENT_NAME.equals(name)) {
                AnAction action = processReferenceElement(child, pluginId);
                if (action != null) {
                    addToGroupInner(group, action, Constraints.LAST, isSecondary(child));
                }
            } else {
                reportActionError(pluginId, "unexpected name of element \"" + name + "\n");
                return null;
            }
        }
        return group;
    } catch (ClassNotFoundException e) {
        reportActionError(pluginId, "class with name \"" + className + "\" not found");
        return null;
    } catch (NoClassDefFoundError e) {
        reportActionError(pluginId, "class with name \"" + e.getMessage() + "\" not found");
        return null;
    } catch (UnsupportedClassVersionError e) {
        reportActionError(pluginId, "unsupported class version for " + className);
        return null;
    } catch (Exception e) {
        final String message = "cannot create class \"" + className + "\"";
        if (pluginId == null) {
            LOG.error(message, e);
        } else {
            LOG.error(new PluginException(message, e, pluginId));
        }
        return null;
    }
}
Also used : Element(org.jdom.Element) PluginException(com.intellij.diagnostic.PluginException) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginException(com.intellij.diagnostic.PluginException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) CachingConstructorInjectionComponentAdapter(com.intellij.util.pico.CachingConstructorInjectionComponentAdapter)

Example 3 with PluginException

use of com.intellij.diagnostic.PluginException in project intellij-community by JetBrains.

the class KeyedExtensionCollector method getPoint.

@Nullable
private ExtensionPoint<KeyedLazyInstance<T>> getPoint() {
    ExtensionPoint<KeyedLazyInstance<T>> point = myPoint;
    if (point == null && Extensions.getRootArea().hasExtensionPoint(myEpName)) {
        ExtensionPointName<KeyedLazyInstance<T>> typesafe = ExtensionPointName.create(myEpName);
        myPoint = point = Extensions.getRootArea().getExtensionPoint(typesafe);
        myListener = new ExtensionPointAndAreaListener<KeyedLazyInstance<T>>() {

            @Override
            public void extensionAdded(@NotNull final KeyedLazyInstance<T> bean, @Nullable final PluginDescriptor pluginDescriptor) {
                synchronized (lock) {
                    if (bean.getKey() == null) {
                        if (pluginDescriptor != null) {
                            throw new PluginException("No key specified for extension of class " + bean.getInstance().getClass(), pluginDescriptor.getPluginId());
                        }
                        LOG.error("No key specified for extension of class " + bean.getInstance().getClass());
                        return;
                    }
                    myCache.remove(bean.getKey());
                    for (ExtensionPointListener<T> listener : myListeners) {
                        listener.extensionAdded(bean.getInstance(), null);
                    }
                }
            }

            @Override
            public void extensionRemoved(@NotNull final KeyedLazyInstance<T> bean, @Nullable final PluginDescriptor pluginDescriptor) {
                synchronized (lock) {
                    myCache.remove(bean.getKey());
                    for (ExtensionPointListener<T> listener : myListeners) {
                        listener.extensionRemoved(bean.getInstance(), null);
                    }
                }
            }

            @Override
            public void areaReplaced(final ExtensionsArea area) {
                resetAreaListener();
            }
        };
        point.addExtensionPointListener(myListener);
    }
    return point;
}
Also used : KeyedLazyInstance(com.intellij.util.KeyedLazyInstance) PluginException(com.intellij.diagnostic.PluginException) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with PluginException

use of com.intellij.diagnostic.PluginException in project intellij-community by JetBrains.

the class StoreUtil method getStateSpecOrError.

@NotNull
public static State getStateSpecOrError(@NotNull Class<? extends PersistentStateComponent> componentClass) {
    State spec = getStateSpec(componentClass);
    if (spec != null) {
        return spec;
    }
    PluginId pluginId = PluginManagerCore.getPluginByClassName(componentClass.getName());
    if (pluginId == null) {
        throw new RuntimeException("No @State annotation found in " + componentClass);
    } else {
        throw new PluginException("No @State annotation found in " + componentClass, pluginId);
    }
}
Also used : State(com.intellij.openapi.components.State) PluginException(com.intellij.diagnostic.PluginException) PluginId(com.intellij.openapi.extensions.PluginId) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with PluginException

use of com.intellij.diagnostic.PluginException in project intellij-community by JetBrains.

the class PluginManager method processException.

public static void processException(Throwable t) {
    if (!IdeaApplication.isLoaded()) {
        @SuppressWarnings("ThrowableResultOfMethodCallIgnored") StartupAbortedException se = findCause(t, StartupAbortedException.class);
        if (se == null)
            se = new StartupAbortedException(t);
        @SuppressWarnings("ThrowableResultOfMethodCallIgnored") PluginException pe = findCause(t, PluginException.class);
        PluginId pluginId = pe != null ? pe.getPluginId() : null;
        if (Logger.isInitialized() && !(t instanceof ProcessCanceledException)) {
            try {
                getLogger().error(t);
            } catch (Throwable ignore) {
            }
        }
        final ImplementationConflictException conflictException = findCause(t, ImplementationConflictException.class);
        if (conflictException != null) {
            PluginConflictReporter.INSTANCE.reportConflictByClasses(conflictException.getConflictingClasses());
        }
        if (pluginId != null && !CORE_PLUGIN_ID.equals(pluginId.getIdString())) {
            disablePlugin(pluginId.getIdString());
            StringWriter message = new StringWriter();
            message.append("Plugin '").append(pluginId.getIdString()).append("' failed to initialize and will be disabled. ");
            message.append(" Please restart ").append(ApplicationNamesInfo.getInstance().getFullProductName()).append('.');
            message.append("\n\n");
            pe.getCause().printStackTrace(new PrintWriter(message));
            Main.showMessage("Plugin Error", message.toString(), false);
            System.exit(Main.PLUGIN_ERROR);
        } else {
            Main.showMessage("Start Failed", t);
            System.exit(se.exitCode());
        }
    } else if (!(t instanceof ProcessCanceledException)) {
        getLogger().error(t);
    }
}
Also used : StringWriter(java.io.StringWriter) PluginException(com.intellij.diagnostic.PluginException) PluginId(com.intellij.openapi.extensions.PluginId) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ImplementationConflictException(com.intellij.diagnostic.ImplementationConflictException) PrintWriter(java.io.PrintWriter)

Aggregations

PluginException (com.intellij.diagnostic.PluginException)6 PluginId (com.intellij.openapi.extensions.PluginId)4 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 Element (org.jdom.Element)2 NotNull (org.jetbrains.annotations.NotNull)2 ImplementationConflictException (com.intellij.diagnostic.ImplementationConflictException)1 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)1 State (com.intellij.openapi.components.State)1 KeyedLazyInstance (com.intellij.util.KeyedLazyInstance)1 StringInterner (com.intellij.util.containers.StringInterner)1 CachingConstructorInjectionComponentAdapter (com.intellij.util.pico.CachingConstructorInjectionComponentAdapter)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Contract (org.jetbrains.annotations.Contract)1 Nullable (org.jetbrains.annotations.Nullable)1