Search in sources :

Example 71 with IExtensionPoint

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

the class RpcTransportRegistry method collectRpcMessageTransportFactory.

/**
 * @return the factory provided by org.knime.core.ui (delegating message transport to NodeContainerUI#doRpc)
 */
private static RpcTransportFactory collectRpcMessageTransportFactory() {
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint point = registry.getExtensionPoint(EXT_POINT_ID);
    // find all extensions implementing the RpcTransportFactory extension point
    List<RpcTransportFactory> factoryList = Stream.of(point.getExtensions()).flatMap(ext -> Stream.of(ext.getConfigurationElements())).map(RpcTransportRegistry::readFactory).filter(Objects::nonNull).collect(Collectors.toList());
    if (factoryList.isEmpty() || factoryList.size() > 1) {
        throw new IllegalStateException(String.format("%s factories registered via RpcTransportFactory extension point, should be exactly 1.\n" + "Factory list: %s", factoryList.size(), factoryList));
    }
    return factoryList.get(0);
}
Also used : Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) NodeLogger(org.knime.core.node.NodeLogger) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) Platform(org.eclipse.core.runtime.Platform) CoreException(org.eclipse.core.runtime.CoreException) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) Collectors(java.util.stream.Collectors) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 72 with IExtensionPoint

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

the class TestrunJanitor method getJanitors.

/**
 * Returns a list with all registered testrun janitors. Each call will create new instances.
 *
 * @return a (possibly empty) collection with testrun janitors
 */
public static Collection<TestrunJanitor> getJanitors() {
    List<TestrunJanitor> janitors = new ArrayList<>();
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint point = registry.getExtensionPoint("org.knime.testing.TestrunJanitor");
    for (IExtension ext : point.getExtensions()) {
        IConfigurationElement[] elements = ext.getConfigurationElements();
        for (IConfigurationElement janitorElement : elements) {
            try {
                janitors.add((TestrunJanitor) janitorElement.createExecutableExtension("class"));
            } catch (CoreException ex) {
                NodeLogger.getLogger(TestrunJanitor.class).error("Could not create testrun janitor " + janitorElement.getAttribute("class") + " from plug-in " + janitorElement.getNamespaceIdentifier() + ": " + ex.getMessage(), ex);
            }
        }
    }
    return janitors;
}
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 73 with IExtensionPoint

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

the class NodeExecutionJobManagerPool method collectJobManagerFactories.

private static void collectJobManagerFactories() {
    managerFactories = new LinkedHashMap<String, NodeExecutionJobManagerFactory>();
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint point = registry.getExtensionPoint(EXT_POINT_ID);
    if (point == null) {
        // let's throw in the default manager - otherwise things fail badly
        managerFactories.put(getDefaultJobManagerFactory().getID(), getDefaultJobManagerFactory());
        LOGGER.error("Invalid extension point: " + EXT_POINT_ID);
        throw new IllegalStateException("ACTIVATION ERROR: " + " --> Invalid extension point: " + EXT_POINT_ID);
    }
    for (IConfigurationElement elem : point.getConfigurationElements()) {
        String jobMgr = elem.getAttribute(EXT_POINT_ATTR_JOBMGR);
        String decl = elem.getDeclaringExtension().getUniqueIdentifier();
        if (jobMgr == null || jobMgr.isEmpty()) {
            LOGGER.error("The extension '" + decl + "' doesn't provide the required attribute '" + EXT_POINT_ATTR_JOBMGR + "'");
            LOGGER.error("Extension " + decl + " ignored.");
            continue;
        }
        // try instantiating the job manager.
        NodeExecutionJobManagerFactory instance = null;
        try {
            // TODO: THE THREADED MANAGER NEEDS TO BE RE-WRITTEN!
            if (jobMgr.equals(getDefaultJobManagerFactory().getID())) {
                instance = getDefaultJobManagerFactory();
            } else {
                instance = (NodeExecutionJobManagerFactory) elem.createExecutableExtension(EXT_POINT_ATTR_JOBMGR);
            }
        } catch (UnsatisfiedLinkError ule) {
            // in case an implementation tries to load an external lib
            // when the factory class gets loaded
            LOGGER.error("Unable to load a library required for '" + jobMgr + "'");
            LOGGER.error("Either specify it in the -Djava.library.path " + "option at the program's command line, or");
            LOGGER.error("include it in the LD_LIBRARY_PATH variable.");
            LOGGER.error("Extension " + jobMgr + " ('" + decl + "') ignored.", ule);
        } catch (CoreException ex) {
            Throwable cause = ex.getStatus().getException();
            if (cause != null) {
                LOGGER.error("Problems during initialization of job manager (with id '" + jobMgr + "'): " + cause.getMessage(), ex);
                if (decl != null) {
                    LOGGER.error("Extension " + decl + " ignored.");
                }
            } else {
                LOGGER.error("Problems during initialization of job manager (with id '" + jobMgr + "')", ex);
                if (decl != null) {
                    LOGGER.error("Extension " + decl + " ignored.");
                }
            }
        } catch (Throwable t) {
            LOGGER.error("Problems during initialization of job manager (with id '" + jobMgr + "')", t);
            if (decl != null) {
                LOGGER.error("Extension " + decl + " ignored.");
            }
        }
        if (instance != null) {
            /*
                 * make sure the ThreadedJobManagerFactory is always the first
                 * in the list
                 */
            if ((instance instanceof ThreadPool) && managerFactories.size() > 0) {
                Map<String, NodeExecutionJobManagerFactory> old = managerFactories;
                managerFactories = new LinkedHashMap<String, NodeExecutionJobManagerFactory>();
                managerFactories.put(instance.getID(), instance);
                for (Map.Entry<String, NodeExecutionJobManagerFactory> e : old.entrySet()) {
                    managerFactories.put(e.getKey(), e.getValue());
                }
            } else {
                managerFactories.put(instance.getID(), instance);
            }
        }
    }
}
Also used : ThreadPool(org.knime.core.util.ThreadPool) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) NodeExecutionJobManagerFactory(org.knime.core.node.workflow.NodeExecutionJobManagerFactory) ThreadNodeExecutionJobManagerFactory(org.knime.core.node.exec.ThreadNodeExecutionJobManagerFactory) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) CoreException(org.eclipse.core.runtime.CoreException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 74 with IExtensionPoint

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

the class AbstractWizardNodeView method getAllWizardNodeViews.

/**
 * Queries extension point for additional {@link AbstractWizardNodeView} implementations.
 *
 * @return A list with all registered view implementations.
 */
@SuppressWarnings("unchecked")
public static List<WizardNodeViewExtension> getAllWizardNodeViews() {
    List<WizardNodeViewExtension> viewExtensionList = new ArrayList<WizardNodeViewExtension>();
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint point = registry.getExtensionPoint(EXT_POINT_ID);
    assert point != null : "Invalid extension point id: " + EXT_POINT_ID;
    for (IExtension ext : point.getExtensions()) {
        IConfigurationElement[] elements = ext.getConfigurationElements();
        for (IConfigurationElement viewElement : elements) {
            String viewClassName = viewElement.getAttribute("viewClass");
            String viewName = viewElement.getAttribute("name");
            String viewDesc = viewElement.getAttribute("description");
            Class<AbstractWizardNodeView<?, ?, ?>> viewClass;
            try {
                viewClass = (Class<AbstractWizardNodeView<?, ?, ?>>) Platform.getBundle(viewElement.getDeclaringExtension().getContributor().getName()).loadClass(viewClassName);
                viewExtensionList.add(new WizardNodeViewExtension(viewClass, viewName, viewDesc));
            } catch (ClassNotFoundException ex) {
                NodeLogger.getLogger(AbstractWizardNodeView.class).error("Could not find implementation for " + viewClassName, ex);
            }
        }
    }
    return viewExtensionList;
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtension(org.eclipse.core.runtime.IExtension) ArrayList(java.util.ArrayList) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 75 with IExtensionPoint

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

the class DatabaseDriverLoader method loadDriversFromExtensionPoint.

/**
 * Loads all JDBC driver registered via the extension point.
 */
private static void loadDriversFromExtensionPoint() {
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint point = registry.getExtensionPoint(EXT_POINT_ID);
    if (point == null) {
        throw new IllegalStateException("Invalid extension point id: " + EXT_POINT_ID);
    }
    for (IExtension ext : point.getExtensions()) {
        IConfigurationElement[] elements = ext.getConfigurationElements();
        for (IConfigurationElement e : elements) {
            String path = e.getAttribute("jarFile");
            String bundleId = e.getDeclaringExtension().getNamespaceIdentifier();
            Bundle bundle = Platform.getBundle(bundleId);
            URL jdbcUrl = FileLocator.find(bundle, new Path(path), null);
            if (jdbcUrl != null) {
                ClassLoader bundleClassLoader = bundle.adapt(BundleWiring.class).getClassLoader();
                try {
                    loadDriver(new File(FileLocator.toFileURL(jdbcUrl).getPath()), bundleClassLoader, false);
                } catch (IOException ex) {
                    LOGGER.error("Could not load JDBC driver '" + path + "': " + ex.getMessage(), ex);
                }
            } else {
                LOGGER.error("Could not find JDBC driver file '" + path + "' from plug-in '" + bundleId + "'");
            }
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) IOException(java.io.IOException) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) URL(java.net.URL) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtension(org.eclipse.core.runtime.IExtension) URLClassLoader(java.net.URLClassLoader) File(java.io.File) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

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