Search in sources :

Example 1 with IContributor

use of org.eclipse.core.runtime.IContributor in project bndtools by bndtools.

the class ExtensionRegistryTemplateLoader method findTemplates.

@Override
public Promise<List<Template>> findTemplates(String type, Reporter reporter) {
    List<Template> templates;
    String extPoint = typeToExtPoint.get(type);
    if (extPoint != null) {
        IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(Plugin.PLUGIN_ID, extPoint);
        if (elements == null)
            elements = new IConfigurationElement[0];
        templates = new ArrayList<>(elements.length);
        float total = elements.length;
        float worked = 0f;
        for (IConfigurationElement element : elements) {
            String elementName = element.getName();
            IContributor contributor = element.getContributor();
            try {
                Template extTemplate = (Template) element.createExecutableExtension("class");
                templates.add(extTemplate);
            } catch (CoreException e) {
                Plugin.getDefault().getLog().log(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, String.format("Error loading template '%s' from bundle %s", elementName, contributor.getName()), e));
            } finally {
                worked += 1f;
                reporter.progress(total / worked, "Loading templates");
            }
        }
    } else {
        templates = Collections.emptyList();
    }
    return Promises.resolved(templates);
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) IContributor(org.eclipse.core.runtime.IContributor) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) Template(org.bndtools.templating.Template)

Aggregations

Template (org.bndtools.templating.Template)1 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IContributor (org.eclipse.core.runtime.IContributor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1