Search in sources :

Example 1 with LanguageInjectionConfigBean

use of org.intellij.plugins.intelliLang.inject.LanguageInjectionConfigBean in project intellij-community by JetBrains.

the class Configuration method loadDefaultInjections.

private static List<BaseInjection> loadDefaultInjections() {
    final List<Configuration> cfgList = new ArrayList<>();
    final Set<Object> visited = new THashSet<>();
    for (LanguageInjectionConfigBean configBean : Extensions.getExtensions(LanguageInjectionSupport.CONFIG_EP_NAME)) {
        PluginDescriptor descriptor = configBean.getPluginDescriptor();
        final ClassLoader loader = descriptor.getPluginClassLoader();
        try {
            final Enumeration<URL> enumeration = loader.getResources(configBean.getConfigUrl());
            if (enumeration == null || !enumeration.hasMoreElements()) {
                LOG.warn(descriptor.getPluginId() + ": " + configBean.getConfigUrl() + " was not found");
            } else {
                while (enumeration.hasMoreElements()) {
                    URL url = enumeration.nextElement();
                    // for DEBUG mode
                    if (!visited.add(url.getFile()))
                        continue;
                    InputStream stream = null;
                    try {
                        stream = url.openStream();
                        cfgList.add(load(stream));
                    } catch (Exception e) {
                        LOG.warn(e);
                    } finally {
                        if (stream != null) {
                            stream.close();
                        }
                    }
                }
            }
        } catch (Exception e) {
            LOG.warn(e);
        }
    }
    final List<BaseInjection> defaultInjections = new ArrayList<>();
    for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) {
        for (Configuration cfg : cfgList) {
            final List<BaseInjection> imported = cfg.getInjections(supportId);
            defaultInjections.addAll(imported);
        }
    }
    return defaultInjections;
}
Also used : InputStream(java.io.InputStream) THashSet(gnu.trove.THashSet) URL(java.net.URL) JDOMException(org.jdom.JDOMException) IOException(java.io.IOException) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection) PluginDescriptor(com.intellij.openapi.extensions.PluginDescriptor) LanguageInjectionConfigBean(org.intellij.plugins.intelliLang.inject.LanguageInjectionConfigBean)

Aggregations

PluginDescriptor (com.intellij.openapi.extensions.PluginDescriptor)1 THashSet (gnu.trove.THashSet)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 LanguageInjectionConfigBean (org.intellij.plugins.intelliLang.inject.LanguageInjectionConfigBean)1 BaseInjection (org.intellij.plugins.intelliLang.inject.config.BaseInjection)1 JDOMException (org.jdom.JDOMException)1