From 6675c150a3a27bdf907310cb133eec991b5bf50b Mon Sep 17 00:00:00 2001 From: Philipp Katz Date: Tue, 23 Mar 2021 17:33:38 +0100 Subject: [PATCH] Get plugin ID for port types --- .../jsondocgen/JsonNodeDocuGenerator.java | 32 ++++++++++++++++--- .../knime/jsondocgen/docs/PortTypeDoc.java | 9 ++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/de.philippkatz.knime.jsondocgen.application/src/de/philippkatz/knime/jsondocgen/JsonNodeDocuGenerator.java b/de.philippkatz.knime.jsondocgen.application/src/de/philippkatz/knime/jsondocgen/JsonNodeDocuGenerator.java index 580e548..d400bd7 100644 --- a/de.philippkatz.knime.jsondocgen.application/src/de/philippkatz/knime/jsondocgen/JsonNodeDocuGenerator.java +++ b/de.philippkatz.knime.jsondocgen.application/src/de/philippkatz/knime/jsondocgen/JsonNodeDocuGenerator.java @@ -60,11 +60,14 @@ import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.xml.transform.TransformerException; import org.apache.commons.io.IOUtils; import org.apache.log4j.Logger; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.Platform; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; import org.eclipse.swt.widgets.Display; @@ -270,9 +273,21 @@ private void generate() throws Exception { Map, PortType> portTypes = PortTypeRegistry.getInstance().availablePortTypes() .stream().collect(Collectors.toMap(PortType::getPortObjectClass, Function.identity())); + // additional information from extension point `org.knime.core.PortType` + // TODO -- should we better take specClass additionally? + Map objectClassToPluginId = new HashMap<>(); + IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint("org.knime.core.PortType"); + Stream.of(point.getExtensions()).flatMap(ext -> Stream.of(ext.getConfigurationElements())).forEach(e -> { + String extensionIdentifier = e.getDeclaringExtension().getNamespaceIdentifier(); + String objectClass = e.getAttribute("objectClass"); + if (extensionIdentifier != null) { + objectClassToPluginId.put(objectClass, extensionIdentifier); + } + }); + LOGGER.debug(String.format("Found %s ports to process", portTypes.size())); - processPorts(portTypes.keySet(), portTypes, builders); + processPorts(portTypes.keySet(), portTypes, builders, objectClassToPluginId); // get the root element (all PortObjects inherit from this interface). PortTypeDoc rootElement = builders.get(PortObject.class).build(); @@ -307,10 +322,13 @@ private void generate() throws Exception { * All *registered* port types. * @param builders * Map with builders for appending the children. + * @param objectClassToExtensionId + * Mapping from object class to the extension ID. */ private static void processPorts(Collection> portObjectClasses, Map, PortType> registeredPortTypes, - Map, PortTypeDocBuilder> builders) { + Map, PortTypeDocBuilder> builders, + Map objectClassToExtensionId) { portObjectClasses.forEach(portObjectClass -> { @@ -320,25 +338,29 @@ private static void processPorts(Collection> portObj List> parentPortObjectClasses = getParentPortObjectClasses(portObjectClass); - processPorts(parentPortObjectClasses, registeredPortTypes, builders); + processPorts(parentPortObjectClasses, registeredPortTypes, builders, objectClassToExtensionId); if (builder == null) { // haven't processed this type yet PortType parent = registeredPortTypes.get(portObjectClass); if (parent != null) { // parent port type is registered via extension point - builder = PortTypeDoc.builderForObjectClass(parent.getPortObjectClass().getName()); + String objectClassName = parent.getPortObjectClass().getName(); + builder = PortTypeDoc.builderForObjectClass(objectClassName); builder.setName(parent.getName()); builder.setSpecClass(parent.getPortObjectSpecClass().getName()); builder.setColor(makeHexColor(parent.getColor())); builder.setHidden(parent.isHidden()); builder.setRegistered(true); + builder.setContributingPlugin(objectClassToExtensionId.get(objectClassName)); } else { // not registered -- only create dummy intermediate; this is e.g. the case for // org.knime.core.node.port.AbstractPortObject which only serve as // implementation helper and are not supposed to be used directly - builder = PortTypeDoc.builderForObjectClass(portObjectClass.getName()); + String objectClassName = portObjectClass.getName(); + builder = PortTypeDoc.builderForObjectClass(objectClassName); builder.setHidden(true); builder.setRegistered(false); + builder.setContributingPlugin(objectClassToExtensionId.get(objectClassName)); } builders.put(portObjectClass, builder); } diff --git a/de.philippkatz.knime.jsondocgen.application/src/de/philippkatz/knime/jsondocgen/docs/PortTypeDoc.java b/de.philippkatz.knime.jsondocgen.application/src/de/philippkatz/knime/jsondocgen/docs/PortTypeDoc.java index 1784197..066d5e5 100644 --- a/de.philippkatz.knime.jsondocgen.application/src/de/philippkatz/knime/jsondocgen/docs/PortTypeDoc.java +++ b/de.philippkatz.knime.jsondocgen.application/src/de/philippkatz/knime/jsondocgen/docs/PortTypeDoc.java @@ -15,6 +15,7 @@ public static class PortTypeDocBuilder { private boolean hidden; private boolean registered; private Set children; + private String contributingPlugin; private PortTypeDocBuilder(String objectClass) { this.objectClass = objectClass; @@ -60,6 +61,11 @@ public PortTypeDocBuilder setRegistered(boolean registered) { return this; } + public PortTypeDocBuilder setContributingPlugin(String contributingPlugin) { + this.contributingPlugin = contributingPlugin; + return this; + } + public PortTypeDoc build() { return new PortTypeDoc(this); } @@ -104,6 +110,8 @@ public static PortTypeDocBuilder builderForObjectClass(String objectClass) { public final boolean hidden; public final boolean registered; public final Set children; + /** @since 1.11 */ + public final String contributingPlugin; private PortTypeDoc(PortTypeDocBuilder builder) { name = builder.name; @@ -113,6 +121,7 @@ private PortTypeDoc(PortTypeDocBuilder builder) { hidden = builder.hidden; registered = builder.registered; children = buildChildren(builder); + contributingPlugin = builder.contributingPlugin; } private static Set buildChildren(PortTypeDocBuilder builder) {