Search in sources :

Example 36 with IExtensionPoint

use of org.eclipse.core.runtime.IExtensionPoint in project jbosstools-hibernate by jbosstools.

the class HSearchServiceLookup method initializeServices.

private static void initializeServices() {
    services = new HashMap<String, IHSearchService>();
    IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
    IExtensionPoint extensionPoint = extensionRegistry.getExtensionPoint(SERVICES_EXTENSION_ID);
    for (IExtension extension : extensionPoint.getExtensions()) {
        for (IConfigurationElement configurationElement : extension.getConfigurationElements()) {
            try {
                Object object = configurationElement.createExecutableExtension("class");
                String name = configurationElement.getAttribute("name");
                if (object != null && name != null && object instanceof IHSearchService) {
                    services.put(name, (IHSearchService) object);
                }
            } catch (CoreException e) {
            }
        }
    }
    ArrayList<String> list = new ArrayList<String>(services.keySet());
    Collections.sort(list);
    versions = list.toArray(new String[list.size()]);
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) CoreException(org.eclipse.core.runtime.CoreException) IExtension(org.eclipse.core.runtime.IExtension) ArrayList(java.util.ArrayList) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 37 with IExtensionPoint

use of org.eclipse.core.runtime.IExtensionPoint in project mylyn.docs by eclipse.

the class WikiTextUiPlugin method getTemplates.

/**
 * get templates mapped by their markup language name
 *
 * @return the templates
 */
public Map<String, Templates> getTemplates() {
    if (templates == null) {
        Map<String, Templates> templates = new HashMap<>();
        IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(getPluginId(), EXTENSION_POINT_CONTENT_ASSIST);
        if (extensionPoint != null) {
            IConfigurationElement[] configurationElements = extensionPoint.getConfigurationElements();
            for (IConfigurationElement element : configurationElements) {
                String declaringPluginId = element.getDeclaringExtension().getContributor().getName();
                if (EXTENSION_POINT_TEMPLATES.equals(element.getName())) {
                    try {
                        // $NON-NLS-1$
                        String markupLanguage = element.getAttribute("markupLanguage");
                        if (markupLanguage == null) {
                            throw new Exception(Messages.WikiTextUiPlugin_markupLanguageRequired);
                        } else if (!WikiText.getMarkupLanguageNames().contains(markupLanguage)) {
                            throw new Exception(NLS.bind(Messages.WikiTextUiPlugin_invalidMarkupLanguage, new Object[] { markupLanguage }));
                        }
                        Templates markupLanguageTemplates = new Templates();
                        markupLanguageTemplates.setMarkupLanguageName(markupLanguage);
                        for (IConfigurationElement templatesChild : element.getChildren()) {
                            if (EXTENSION_POINT_TEMPLATE.equals(templatesChild.getName())) {
                                try {
                                    // process the template
                                    // $NON-NLS-1$
                                    String name = templatesChild.getAttribute("name");
                                    // $NON-NLS-1$
                                    String description = templatesChild.getAttribute("description");
                                    // $NON-NLS-1$
                                    String content = templatesChild.getAttribute("content");
                                    // $NON-NLS-1$
                                    String autoInsert = templatesChild.getAttribute("autoInsert");
                                    // $NON-NLS-1$
                                    String block = templatesChild.getAttribute("block");
                                    if (name == null || name.length() == 0) {
                                        throw new Exception(NLS.bind(Messages.WikiTextUiPlugin_nameRequired, new Object[] { EXTENSION_POINT_TEMPLATE }));
                                    }
                                    if (description == null || description.length() == 0) {
                                        throw new Exception(NLS.bind(Messages.WikiTextUiPlugin_descriptionRequired, new Object[] { EXTENSION_POINT_TEMPLATE }));
                                    }
                                    if (content == null || content.length() == 0) {
                                        throw new Exception(NLS.bind(Messages.WikiTextUiPlugin_contentRequired, new Object[] { EXTENSION_POINT_TEMPLATE }));
                                    }
                                    // $NON-NLS-1$//$NON-NLS-2$
                                    content = content.replace("\\t", "\t");
                                    content = // $NON-NLS-1$
                                    content.replace("\\r\\n", Text.DELIMITER).replace(// $NON-NLS-1$
                                    "\\r", Text.DELIMITER).replace("\\n", // $NON-NLS-1$
                                    Text.DELIMITER).replace("\\\\", // $NON-NLS-1$ //$NON-NLS-2$
                                    "\\");
                                    if (// $NON-NLS-1$
                                    content.endsWith("$") && !(content.endsWith("\\$") || content.endsWith("$$"))) {
                                        // $NON-NLS-1$ //$NON-NLS-2$
                                        content = content.substring(0, content.length() - 1);
                                    }
                                    if (content.startsWith("^")) {
                                        // $NON-NLS-1$
                                        content = content.substring(1);
                                    }
                                    // $NON-NLS-1$ //$NON-NLS-2$
                                    content = content.replace("\\$", "$$");
                                    markupLanguageTemplates.addTemplate(new Template(name, description, MarkupTemplateCompletionProcessor.CONTEXT_ID, content, autoInsert == null || // $NON-NLS-1$
                                    !"false".equalsIgnoreCase(autoInsert)), // $NON-NLS-1$
                                    block != null && "true".equalsIgnoreCase(block));
                                } catch (Exception e) {
                                    log(IStatus.ERROR, NLS.bind(Messages.WikiTextUiPlugin_invalidExtension, new Object[] { declaringPluginId, EXTENSION_POINT_CONTENT_ASSIST, e.getMessage() }), e);
                                }
                            } else {
                                log(IStatus.ERROR, NLS.bind(Messages.WikiTextUiPlugin_unexpectedExtensionElement, new Object[] { declaringPluginId, EXTENSION_POINT_CONTENT_ASSIST, templatesChild.getName() }), null);
                            }
                        }
                        Templates previous = templates.put(markupLanguageTemplates.getMarkupLanguageName(), markupLanguageTemplates);
                        if (previous != null) {
                            markupLanguageTemplates.addAll(previous);
                        }
                    } catch (Exception e) {
                        log(IStatus.ERROR, NLS.bind(Messages.WikiTextUiPlugin_invalidExtension, new Object[] { declaringPluginId, EXTENSION_POINT_TEMPLATES, e.getMessage() }), e);
                    }
                } else {
                    log(IStatus.ERROR, NLS.bind(Messages.WikiTextUiPlugin_unexpectedExtensionElement, new Object[] { declaringPluginId, EXTENSION_POINT_CONTENT_ASSIST, element.getName() }), null);
                }
            }
        }
        // now that we have the basic templates, check for language extensions and connect the hierarchy
        // first ensure that all language names have templates defined
        Set<String> languageNames = WikiText.getMarkupLanguageNames();
        for (String languageName : languageNames) {
            Templates languageTemplates = templates.get(languageName);
            if (languageTemplates == null) {
                languageTemplates = new Templates();
                templates.put(languageName, languageTemplates);
            }
        }
        // next connect the hierarchy
        for (String languageName : languageNames) {
            MarkupLanguage markupLanguage = WikiText.getMarkupLanguage(languageName);
            if (markupLanguage != null && markupLanguage.getExtendsLanguage() != null) {
                Templates languageTemplates = templates.get(languageName);
                Templates parentLanguageTemplates = templates.get(markupLanguage.getExtendsLanguage());
                languageTemplates.setParent(parentLanguageTemplates);
            }
        }
        this.templates = Collections.unmodifiableMap(templates);
    }
    return templates;
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) HashMap(java.util.HashMap) Templates(org.eclipse.mylyn.internal.wikitext.ui.editor.assist.Templates) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) CoreException(org.eclipse.core.runtime.CoreException) Template(org.eclipse.jface.text.templates.Template)

Example 38 with IExtensionPoint

use of org.eclipse.core.runtime.IExtensionPoint in project mylyn.docs by eclipse.

the class WikiTextUiPlugin method getHyperlinkDectectorFileRefRegexes.

public Map<String, List<String>> getHyperlinkDectectorFileRefRegexes() {
    if (fileRefRegexes == null) {
        com.google.common.collect.ImmutableMap.Builder<String, List<String>> markupLanguageToFileRefRegexes = ImmutableMap.builder();
        IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(getPluginId(), EXTENSION_POINT_RELATIVE_FILE_PATH_HYPERLINK_DECTOR);
        if (extensionPoint != null) {
            IConfigurationElement[] configurationElements = extensionPoint.getConfigurationElements();
            for (IConfigurationElement element : configurationElements) {
                String declaringPluginId = element.getDeclaringExtension().getContributor().getName();
                if (EXTENSION_POINT_RELATIVE_FILE_PATH_HYPERLINK_DECTOR.equals(element.getName())) {
                    try {
                        String markupLanguage = validateAndGetMarkupLanguage(element);
                        List<String> regexes = createFielRefRegexes(element, declaringPluginId);
                        markupLanguageToFileRefRegexes.put(markupLanguage, regexes);
                    } catch (Exception e) {
                        log(IStatus.ERROR, NLS.bind(Messages.WikiTextUiPlugin_invalidExtension, new Object[] { declaringPluginId, EXTENSION_POINT_RELATIVE_FILE_PATH_HYPERLINK_DECTOR, e.getMessage() }), e);
                    }
                } else {
                    log(IStatus.ERROR, NLS.bind(Messages.WikiTextUiPlugin_unexpectedExtensionElement, new Object[] { declaringPluginId, EXTENSION_POINT_RELATIVE_FILE_PATH_HYPERLINK_DECTOR, element.getName() }), null);
                }
            }
        }
        fileRefRegexes = markupLanguageToFileRefRegexes.build();
    }
    return fileRefRegexes;
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) ImmutableMap(com.google.common.collect.ImmutableMap) CoreException(org.eclipse.core.runtime.CoreException)

Example 39 with IExtensionPoint

use of org.eclipse.core.runtime.IExtensionPoint in project mylyn.docs by eclipse.

the class WikiTextUiPlugin method getCheatSheets.

public SortedMap<String, HelpContent> getCheatSheets() {
    if (cheatSheets == null) {
        SortedMap<String, HelpContent> cheatSheets = new TreeMap<>();
        IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(getPluginId(), EXTENSION_POINT_CHEAT_SHEET);
        if (extensionPoint != null) {
            IConfigurationElement[] configurationElements = extensionPoint.getConfigurationElements();
            for (IConfigurationElement element : configurationElements) {
                String declaringPluginId = element.getDeclaringExtension().getContributor().getName();
                Bundle bundle = Platform.getBundle(declaringPluginId);
                // $NON-NLS-1$
                String markupLanguage = element.getAttribute("markupLanguage");
                // $NON-NLS-1$
                String contentLanguage = element.getAttribute("contentLanguage");
                // $NON-NLS-1$
                String resource = element.getAttribute("resource");
                try {
                    if (markupLanguage == null) {
                        throw new Exception(Messages.WikiTextUiPlugin_markupLanguageRequired);
                    } else if (!WikiText.getMarkupLanguageNames().contains(markupLanguage)) {
                        throw new Exception(NLS.bind(Messages.WikiTextUiPlugin_invalidMarkupLanguage, new Object[] { markupLanguage }));
                    }
                    if (resource == null || resource.length() == 0) {
                        throw new Exception(Messages.WikiTextUiPlugin_resourceRequired);
                    }
                    HelpContent cheatSheet = new CheatSheetContent(bundle, resource, contentLanguage, markupLanguage);
                    HelpContent previous = cheatSheets.put(cheatSheet.getMarkupLanguageName(), cheatSheet);
                    if (previous != null) {
                        cheatSheets.put(previous.getMarkupLanguageName(), previous);
                        throw new Exception(NLS.bind(Messages.WikiTextUiPlugin_markupLanguageContentAlreadyDeclared, new Object[] { previous.getMarkupLanguageName(), previous.getProvider().getSymbolicName() }));
                    }
                } catch (Exception e) {
                    log(IStatus.ERROR, NLS.bind(Messages.WikiTextUiPlugin_invalidExtension, new Object[] { declaringPluginId, EXTENSION_POINT_CHEAT_SHEET, e.getMessage() }), e);
                }
            }
        }
        this.cheatSheets = Collections.unmodifiableSortedMap(cheatSheets);
    }
    return cheatSheets;
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) HelpContent(org.eclipse.mylyn.internal.wikitext.ui.editor.help.HelpContent) Bundle(org.osgi.framework.Bundle) TreeMap(java.util.TreeMap) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) CoreException(org.eclipse.core.runtime.CoreException) CheatSheetContent(org.eclipse.mylyn.internal.wikitext.ui.editor.help.CheatSheetContent)

Example 40 with IExtensionPoint

use of org.eclipse.core.runtime.IExtensionPoint in project mylyn.docs by eclipse.

the class WikiTextExtensionPointReader method initializeMarkupLanguages.

private void initializeMarkupLanguages() {
    synchronized (this) {
        if (this.languageByName == null) {
            SortedMap<String, Class<? extends MarkupLanguage>> markupLanguageByName = new TreeMap<>();
            Map<String, Class<? extends MarkupLanguage>> languageByFileExtension = new HashMap<>();
            Map<String, String> languageExtensionByLanguage = new HashMap<>();
            Map<Class<? extends MarkupLanguage>, String> languageNameByLanguage = new HashMap<>();
            IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(getExtensionPointNamespace(), EXTENSION_MARKUP_LANGUAGE);
            if (extensionPoint != null) {
                IConfigurationElement[] configurationElements = extensionPoint.getConfigurationElements();
                for (IConfigurationElement element : configurationElements) {
                    // $NON-NLS-1$
                    String name = element.getAttribute("name");
                    if (name == null || name.length() == 0) {
                        log(IStatus.ERROR, MessageFormat.format(EXTENSION_MARKUP_LANGUAGE + // $NON-NLS-1$
                        Messages.getString("WikiTextExtensionPointReader.10"), element.getDeclaringExtension().getContributor().getName()));
                        continue;
                    }
                    // $NON-NLS-1$
                    String extendsLanguage = element.getAttribute("extends");
                    Object markupLanguage;
                    try {
                        // $NON-NLS-1$
                        markupLanguage = element.createExecutableExtension("class");
                    } catch (CoreException e) {
                        getLog().log(e.getStatus());
                        continue;
                    }
                    if (!(markupLanguage instanceof MarkupLanguage)) {
                        log(IStatus.ERROR, // $NON-NLS-1$
                        MessageFormat.format(// $NON-NLS-1$
                        Messages.getString("WikiTextExtensionPointReader.13"), markupLanguage.getClass().getName()));
                        continue;
                    }
                    MarkupLanguage d = (MarkupLanguage) markupLanguage;
                    {
                        Class<? extends MarkupLanguage> previous = markupLanguageByName.put(name, d.getClass());
                        if (previous != null) {
                            log(IStatus.ERROR, MessageFormat.format(EXTENSION_MARKUP_LANGUAGE + // $NON-NLS-1$
                            Messages.getString("WikiTextExtensionPointReader.14"), name, element.getDeclaringExtension().getContributor().getName(), name));
                            markupLanguageByName.put(name, previous);
                            continue;
                        } else {
                            languageNameByLanguage.put(d.getClass(), name);
                        }
                    }
                    if (extendsLanguage != null) {
                        languageExtensionByLanguage.put(name, extendsLanguage);
                    }
                    // $NON-NLS-1$
                    String fileExtensions = element.getAttribute("fileExtensions");
                    if (fileExtensions != null) {
                        // $NON-NLS-1$
                        String[] parts = fileExtensions.split("\\s*,\\s*");
                        for (String part : parts) {
                            if (part.length() != 0) {
                                part = part.toLowerCase();
                                Class<? extends MarkupLanguage> previous = languageByFileExtension.put(part, d.getClass());
                                if (previous != null) {
                                    log(IStatus.ERROR, MessageFormat.format(EXTENSION_MARKUP_LANGUAGE + // $NON-NLS-1$
                                    Messages.getString("WikiTextExtensionPointReader.17"), part, element.getDeclaringExtension().getContributor().getName(), part));
                                    languageByFileExtension.put(part, previous);
                                    continue;
                                }
                            }
                        }
                    }
                }
            }
            this.languageByFileExtension = languageByFileExtension;
            this.languageByName = markupLanguageByName;
            this.languageExtensionByLanguage = languageExtensionByLanguage;
            this.languageNameByLanguage = languageNameByLanguage;
        }
    }
}
Also used : HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) CoreException(org.eclipse.core.runtime.CoreException) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage)

Aggregations

IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)187 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)160 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)107 IExtension (org.eclipse.core.runtime.IExtension)92 CoreException (org.eclipse.core.runtime.CoreException)70 ArrayList (java.util.ArrayList)29 HashMap (java.util.HashMap)17 Platform (org.eclipse.core.runtime.Platform)17 Stream (java.util.stream.Stream)16 List (java.util.List)15 NodeLogger (org.knime.core.node.NodeLogger)15 Map (java.util.Map)14 Optional (java.util.Optional)14 Collection (java.util.Collection)9 Bundle (org.osgi.framework.Bundle)9 Collectors (java.util.stream.Collectors)8 IOException (java.io.IOException)6 Collections (java.util.Collections)6 LinkedList (java.util.LinkedList)6 Objects (java.util.Objects)6