Search in sources :

Example 1 with PortTypeDoc

use of de.philippkatz.knime.jsondocgen.docs.PortTypeDoc in project knime-json-node-doc-generator by NodePit.

the class JsonNodeDocuGenerator method generate.

/**
 * Starts generating the node reference documents.
 *
 * @throws Exception
 */
private void generate() throws Exception {
    if (!m_skipNodeDocumentation) {
        LOGGER.info("Reading node repository");
        IRepositoryObject root = RepositoryManager.INSTANCE.getRoot();
        rootCategoryDoc = new CategoryDocBuilder();
        rootCategoryDoc.setId(root.getID());
        rootCategoryDoc.setName(root.getName());
        rootCategoryDoc.setContributingPlugin(root.getContributingPlugin());
        // replace '/' with points and remove leading '/'
        if (m_catPath.startsWith("/")) {
            m_catPath = m_catPath.substring(1);
        }
        m_catPath = m_catPath.replaceAll("/", ".");
        // recursively generate the node reference and the node description
        // pages
        generate(m_directory, root, null, rootCategoryDoc);
        CategoryDoc rootCategory = rootCategoryDoc.build();
        String resultJson = rootCategory.toJson();
        File resultFile = new File(m_directory, "nodeDocumentation.json");
        LOGGER.info("Writing nodes to " + resultFile);
        IOUtils.write(resultJson, new FileOutputStream(resultFile), StandardCharsets.UTF_8);
    }
    if (!m_skipPortDocumentation) {
        LOGGER.info("Generating port documentation");
        Map<Class<? extends PortObject>, PortTypeDocBuilder> builders = new HashMap<>();
        // all registered port types indexed by the PortObject class; read this only
        // once from the registry and cache it, b/c the registry creates new PortTypes
        // dynamically when requesting an unknown type
        Map<Class<? extends PortObject>, PortType> portTypes = PortTypeRegistry.getInstance().availablePortTypes().stream().collect(Collectors.toMap(PortType::getPortObjectClass, Function.identity()));
        LOGGER.debug(String.format("Found %s ports to process", portTypes.size()));
        processPorts(portTypes.keySet(), portTypes, builders);
        // get the root element (all PortObjects inherit from this interface).
        PortTypeDoc rootElement = builders.get(PortObject.class).build();
        File portTypeResultFile = new File(m_directory, "portDocumentation.json");
        LOGGER.info("Writing port types to " + portTypeResultFile);
        IOUtils.write(Utils.toJson(rootElement), new FileOutputStream(portTypeResultFile), StandardCharsets.UTF_8);
    }
    if (!m_skipSplashIcons) {
        LOGGER.debug("Generating splash icons");
        List<SplashIconDoc> splashIcons = SplashIconReader.readSplashIcons();
        LOGGER.debug(String.format("Found %s splash icons", splashIcons.size()));
        File splashIconsResultFile = new File(m_directory, "splashIcons.json");
        LOGGER.info("Writing splash icons to " + splashIconsResultFile);
        IOUtils.write(Utils.toJson(splashIcons), new FileOutputStream(splashIconsResultFile), StandardCharsets.UTF_8);
    }
}
Also used : HashMap(java.util.HashMap) CategoryDoc(de.philippkatz.knime.jsondocgen.docs.CategoryDoc) PortTypeDoc(de.philippkatz.knime.jsondocgen.docs.PortTypeDoc) IRepositoryObject(org.knime.workbench.repository.model.IRepositoryObject) CategoryDocBuilder(de.philippkatz.knime.jsondocgen.docs.CategoryDoc.CategoryDocBuilder) FileOutputStream(java.io.FileOutputStream) SplashIconDoc(de.philippkatz.knime.jsondocgen.docs.SplashIconDoc) PortTypeDocBuilder(de.philippkatz.knime.jsondocgen.docs.PortTypeDoc.PortTypeDocBuilder) File(java.io.File) PortObject(org.knime.core.node.port.PortObject) PortType(org.knime.core.node.port.PortType)

Aggregations

CategoryDoc (de.philippkatz.knime.jsondocgen.docs.CategoryDoc)1 CategoryDocBuilder (de.philippkatz.knime.jsondocgen.docs.CategoryDoc.CategoryDocBuilder)1 PortTypeDoc (de.philippkatz.knime.jsondocgen.docs.PortTypeDoc)1 PortTypeDocBuilder (de.philippkatz.knime.jsondocgen.docs.PortTypeDoc.PortTypeDocBuilder)1 SplashIconDoc (de.philippkatz.knime.jsondocgen.docs.SplashIconDoc)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 HashMap (java.util.HashMap)1 PortObject (org.knime.core.node.port.PortObject)1 PortType (org.knime.core.node.port.PortType)1 IRepositoryObject (org.knime.workbench.repository.model.IRepositoryObject)1