Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get plugin ID for port types #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -270,9 +273,21 @@ private void generate() throws Exception {
Map<Class<? extends PortObject>, 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<String, String> 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();
Expand Down Expand Up @@ -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<Class<? extends PortObject>> portObjectClasses,
Map<Class<? extends PortObject>, PortType> registeredPortTypes,
Map<Class<? extends PortObject>, PortTypeDocBuilder> builders) {
Map<Class<? extends PortObject>, PortTypeDocBuilder> builders,
Map<String, String> objectClassToExtensionId) {

portObjectClasses.forEach(portObjectClass -> {

Expand All @@ -320,25 +338,29 @@ private static void processPorts(Collection<Class<? extends PortObject>> portObj

List<Class<? extends PortObject>> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static class PortTypeDocBuilder {
private boolean hidden;
private boolean registered;
private Set<PortTypeDocBuilder> children;
private String contributingPlugin;

private PortTypeDocBuilder(String objectClass) {
this.objectClass = objectClass;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -104,6 +110,8 @@ public static PortTypeDocBuilder builderForObjectClass(String objectClass) {
public final boolean hidden;
public final boolean registered;
public final Set<PortTypeDoc> children;
/** @since 1.11 */
public final String contributingPlugin;

private PortTypeDoc(PortTypeDocBuilder builder) {
name = builder.name;
Expand All @@ -113,6 +121,7 @@ private PortTypeDoc(PortTypeDocBuilder builder) {
hidden = builder.hidden;
registered = builder.registered;
children = buildChildren(builder);
contributingPlugin = builder.contributingPlugin;
}

private static Set<PortTypeDoc> buildChildren(PortTypeDocBuilder builder) {
Expand Down