This is an automated email from the ASF dual-hosted git repository.

oscerd pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-kafka-connector.git


The following commit(s) were added to refs/heads/main by this push:
     new e341f1feb0 Fix #1195: make the docs plugin paths configurable and 
detect connectors by manifest (#1856)
e341f1feb0 is described below

commit e341f1feb0383b0d64db3845601f063e19b75435
Author: Andrea Cosentino <[email protected]>
AuthorDate: Thu Nov 5 11:36:37 2026 +0100

    Fix #1195: make the docs plugin paths configurable and detect connectors by 
manifest (#1856)
    
    Since #1788 removed the generated *SinkTask / *SourceTask classes, the
    docs mojo, which selected connector modules by those file names, only
    found camel-syslog-kafka-connector on a clean checkout. Any build then
    rewrote reference/index.adoc and the connectors block of nav.adoc down
    to that single connector. CI does not check for regenerated files, so
    the regression went unnoticed.
    
    - Detect sink and source connector modules from the Kafka Connect
      ServiceLoader manifests (KIP-898) under src/main/resources, which
      every connector module ships, so stale target/ output cannot change
      the result.
    - Turn the hard-coded link prefix and suffixes, the docs module
      directory and the index and nav files into mojo parameters, with
      today's values as defaults.
    - Drop the solrCloud special case: no Camel 4.22 component or Kamelet
      can produce that module.
    - Add the plugin's first unit tests.
    
    Regenerating the docs from a clean checkout now leaves them identical to
    the committed files.
    
    Signed-off-by: Andrea Cosentino <[email protected]>
    Co-authored-by: Claude Opus 5.5 <[email protected]>
---
 .../pom.xml                                        |  16 +-
 .../maven/docs/UpdateDocComponentsListMojo.java    | 178 ++++++++++++-------
 .../docs/UpdateDocComponentsListMojoTest.java      | 188 +++++++++++++++++++++
 3 files changed, 313 insertions(+), 69 deletions(-)

diff --git a/tooling/camel-kafka-connector-docs-maven-plugin/pom.xml 
b/tooling/camel-kafka-connector-docs-maven-plugin/pom.xml
index 6b0e517276..5e5192ff59 100644
--- a/tooling/camel-kafka-connector-docs-maven-plugin/pom.xml
+++ b/tooling/camel-kafka-connector-docs-maven-plugin/pom.xml
@@ -93,10 +93,6 @@
             <artifactId>gson</artifactId>
             <version>${gson-version}</version>
         </dependency>
-        <dependency>
-            <groupId>commons-io</groupId>
-            <artifactId>commons-io</artifactId>
-        </dependency>
 
         <!-- camel -->
         <dependency>
@@ -148,5 +144,17 @@
             <artifactId>log4j-slf4j2-impl</artifactId>
             <scope>test</scope>
         </dependency>
+
+        <!-- testing -->
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-api</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-engine</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
diff --git 
a/tooling/camel-kafka-connector-docs-maven-plugin/src/main/java/org/apache/camel/kafkaconnector/maven/docs/UpdateDocComponentsListMojo.java
 
b/tooling/camel-kafka-connector-docs-maven-plugin/src/main/java/org/apache/camel/kafkaconnector/maven/docs/UpdateDocComponentsListMojo.java
index 5bf67e7689..39ea8653ef 100644
--- 
a/tooling/camel-kafka-connector-docs-maven-plugin/src/main/java/org/apache/camel/kafkaconnector/maven/docs/UpdateDocComponentsListMojo.java
+++ 
b/tooling/camel-kafka-connector-docs-maven-plugin/src/main/java/org/apache/camel/kafkaconnector/maven/docs/UpdateDocComponentsListMojo.java
@@ -19,16 +19,12 @@ package org.apache.camel.kafkaconnector.maven.docs;
 import java.io.File;
 import java.io.FileInputStream;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
 
 import 
org.apache.camel.kafkaconnector.maven.docs.dto.CamelKafkaConnectorTableModel;
 import 
org.apache.camel.kafkaconnector.maven.docs.dto.CamelKafkaConnectorTableOptionModel;
 import org.apache.camel.maven.packaging.MvelHelper;
 import org.apache.camel.tooling.util.Strings;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.DirectoryFileFilter;
-import org.apache.commons.io.filefilter.RegexFileFilter;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -44,14 +40,17 @@ import static 
org.apache.camel.tooling.util.PackageHelper.loadText;
 import static org.apache.camel.tooling.util.PackageHelper.writeText;
 
 /**
- * Generates the table of connectors in: - 
docs/modules/ROOT/pages/reference/index.adoc
+ * Generates the table of connectors in the connectors index page (by default
+ * docs/modules/ROOT/pages/reference/index.adoc) and the list of connectors in 
the nav file (by default
+ * docs/modules/ROOT/nav.adoc).
  */
 @Mojo(name = "update-doc-connectors-list", threadSafe = true)
 public class UpdateDocComponentsListMojo extends AbstractMojo {
-    //TODO: make these configurable:
-    private static final String SINK_CONNECTOR_LINK_SUFFIX_ADOC = 
"kafka-sink-connector.adoc[Sink Docs]";
-    private static final String SOURCE_CONNECTOR_LINK_SUFFIX_ADOC = 
"kafka-source-connector.adoc[Source Docs]";
-    private static final String XREF_CONNECTOR_LINK_PREFIX = 
"xref:reference/connectors/";
+    // The Kafka Connect ServiceLoader manifests (KIP-898) that every 
connector module, generated or hand-maintained,
+    // ships for each type of connector it provides. They are only looked up 
in the module sources, so build output
+    // such as a stale target/ directory cannot change the list of connectors.
+    private static final String SINK_CONNECTOR_SERVICE_FILE = 
"src/main/resources/META-INF/services/org.apache.kafka.connect.sink.SinkConnector";
+    private static final String SOURCE_CONNECTOR_SERVICE_FILE = 
"src/main/resources/META-INF/services/org.apache.kafka.connect.source.SourceConnector";
 
     /**
      * The maven project.
@@ -83,7 +82,48 @@ public class UpdateDocComponentsListMojo extends 
AbstractMojo {
      */
     @Parameter
     protected String lastReleasedVersion;
-    
+
+    /**
+     * The prefix of the links to the connector reference pages.
+     */
+    @Parameter(defaultValue = "xref:reference/connectors/")
+    protected String xrefConnectorLinkPrefix;
+
+    /**
+     * The suffix of the links to the sink connector reference pages, appended 
to the connector module name without
+     * its "kafka-connector" suffix.
+     */
+    @Parameter(defaultValue = "kafka-sink-connector.adoc[Sink Docs]")
+    protected String sinkConnectorLinkSuffix;
+
+    /**
+     * The suffix of the links to the source connector reference pages, 
appended to the connector module name without
+     * its "kafka-connector" suffix.
+     */
+    @Parameter(defaultValue = "kafka-source-connector.adoc[Source Docs]")
+    protected String sourceConnectorLinkSuffix;
+
+    /**
+     * The docs module directory holding the connectors index page and the nav 
file, absolute or relative to
+     * projectBaseDir.
+     */
+    @Parameter(defaultValue = "docs/modules/ROOT/")
+    protected String docsModuleDir;
+
+    /**
+     * The page with the table of connectors between the "// kafka-connectors 
list: START" and
+     * "// kafka-connectors list: END" markers, absolute or relative to 
docsModuleDir.
+     */
+    @Parameter(defaultValue = "pages/reference/index.adoc")
+    protected String connectorsIndexFile;
+
+    /**
+     * The nav file with the list of connectors between the "// connectors: 
START" and "// connectors: END" markers,
+     * absolute or relative to docsModuleDir.
+     */
+    @Parameter(defaultValue = "nav.adoc")
+    protected String navFile;
+
     /**
      * The maven project.
      */
@@ -114,63 +154,12 @@ public class UpdateDocComponentsListMojo extends 
AbstractMojo {
 
     protected void executeComponentsReadme() throws MojoExecutionException, 
MojoFailureException {
         CamelKafkaConnectorTableModel tableModel = new 
CamelKafkaConnectorTableModel();
-        ArrayList<CamelKafkaConnectorTableOptionModel> options = new 
ArrayList<>();
 
         if (connectorsDir != null && connectorsDir.isDirectory()) {
-            File[] files = connectorsDir.listFiles();
-            if (files != null) {
-                for (int i = 0; i < files.length; i++) {
-                    File file = files[i];
-                    if (file.isDirectory()) {
-                        Collection sinkConnector = FileUtils.listFiles(file, 
new RegexFileFilter(".*SinkTask.*"), DirectoryFileFilter.DIRECTORY);
-                        Collection sourceConnector = FileUtils.listFiles(file, 
new RegexFileFilter(".*SourceTask.*"), DirectoryFileFilter.DIRECTORY);
-                        if (!sinkConnector.isEmpty() || 
!sourceConnector.isEmpty()) {
-                            CamelKafkaConnectorTableOptionModel 
singleConnector = new CamelKafkaConnectorTableOptionModel();
-                            singleConnector.setName(file.getName());
-                            if (!sinkConnector.isEmpty()) {
-                                singleConnector.setSink(true);
-                                String connectorFinal = 
StringUtils.removeEnd(file.getName(), "kafka-connector");
-                                if 
(connectorFinal.equalsIgnoreCase("camel-coap-tcp-")) {
-                                    
singleConnector.setDocsSink(XREF_CONNECTOR_LINK_PREFIX + "camel-coap+tcp-" + 
SINK_CONNECTOR_LINK_SUFFIX_ADOC);
-                                } else if 
(connectorFinal.equalsIgnoreCase("camel-coaps-tcp-")) {
-                                    
singleConnector.setDocsSink(XREF_CONNECTOR_LINK_PREFIX + "camel-coaps+tcp-" + 
SINK_CONNECTOR_LINK_SUFFIX_ADOC);
-                                } else if 
(connectorFinal.equalsIgnoreCase("camel-solrcloud-")) {
-                                    
singleConnector.setDocsSink(XREF_CONNECTOR_LINK_PREFIX + "camel-solrCloud-" + 
SINK_CONNECTOR_LINK_SUFFIX_ADOC);
-                                } else {
-                                    
singleConnector.setDocsSink(XREF_CONNECTOR_LINK_PREFIX + connectorFinal + 
SINK_CONNECTOR_LINK_SUFFIX_ADOC);
-                                }
-                            }
-                            if (!sourceConnector.isEmpty()) {
-                                singleConnector.setSource(true);
-                                String connectorFinal = 
StringUtils.removeEnd(file.getName(), "kafka-connector");
-                                if 
(connectorFinal.equalsIgnoreCase("camel-coap-tcp-")) {
-                                    
singleConnector.setDocsSource(XREF_CONNECTOR_LINK_PREFIX + "camel-coap+tcp-" + 
SOURCE_CONNECTOR_LINK_SUFFIX_ADOC);
-                                } else if 
(connectorFinal.equalsIgnoreCase("camel-coaps-tcp-")) {
-                                    
singleConnector.setDocsSource(XREF_CONNECTOR_LINK_PREFIX + "camel-coaps+tcp-" + 
SOURCE_CONNECTOR_LINK_SUFFIX_ADOC);
-                                } else if 
(connectorFinal.equalsIgnoreCase("camel-solrcloud-")) {
-                                    
singleConnector.setDocsSource(XREF_CONNECTOR_LINK_PREFIX + "camel-solrCloud-" + 
SOURCE_CONNECTOR_LINK_SUFFIX_ADOC);
-                                } else {
-                                    
singleConnector.setDocsSource(XREF_CONNECTOR_LINK_PREFIX + connectorFinal + 
SOURCE_CONNECTOR_LINK_SUFFIX_ADOC);
-                                }
-                            }
-                            String downloadLinkTar = repositoryPath + 
singleConnector.getName() + "/" + lastReleasedVersion + "/" + 
singleConnector.getName() + "-" + lastReleasedVersion + 
"-package.tar.gz[Download]";
-                            
singleConnector.setDownloadLinkTar(downloadLinkTar);
-                            options.add(singleConnector);
-                        }
-                    }
-                }
-                options.sort((model1, model2) -> {
-                    String name1 = model1.getName();
-                    String name2 = model2.getName();
-                    int res = String.CASE_INSENSITIVE_ORDER.compare(name1, 
name2);
-                    return (res != 0) ? res : name1.compareTo(name2);
-                });
-                tableModel.setOptions(options);
-            }
+            tableModel.setOptions(findConnectors());
         }
-        //TODO: make these configurable:
-        File docFolderWebsite = new File(projectBaseDir, "docs/modules/ROOT/");
-        File docFileWebsite = new File(docFolderWebsite, 
"pages/reference/index.adoc");
+        File docFolderWebsite = resolve(projectBaseDir, docsModuleDir);
+        File docFileWebsite = resolve(docFolderWebsite, connectorsIndexFile);
         String changed = templateConnnectorsTable(tableModel);
         boolean updated = updateConnectorsTable(docFileWebsite, changed);
         if (updated) {
@@ -178,7 +167,7 @@ public class UpdateDocComponentsListMojo extends 
AbstractMojo {
         } else {
             getLog().debug("No changes to connectors table file: " + 
docFileWebsite);
         }
-        File navWebsite = new File(docFolderWebsite, "nav.adoc");
+        File navWebsite = resolve(docFolderWebsite, navFile);
         boolean navUpdated = updateNav(navWebsite, tableModel);
         if (navUpdated) {
             getLog().info("Updated nav file: " + navWebsite);
@@ -187,6 +176,65 @@ public class UpdateDocComponentsListMojo extends 
AbstractMojo {
         }
     }
 
+    /**
+     * Lists the connector modules of the connectors directory, sorted by 
name. A module provides a sink and/or a
+     * source connector when its sources contain the matching Kafka Connect 
ServiceLoader manifest.
+     */
+    ArrayList<CamelKafkaConnectorTableOptionModel> findConnectors() throws 
MojoExecutionException {
+        File[] modules = connectorsDir.listFiles(File::isDirectory);
+        if (modules == null) {
+            throw new MojoExecutionException("Cannot list the connector 
modules in " + connectorsDir);
+        }
+        ArrayList<CamelKafkaConnectorTableOptionModel> options = new 
ArrayList<>();
+        for (File module : modules) {
+            boolean sink = new File(module, 
SINK_CONNECTOR_SERVICE_FILE).isFile();
+            boolean source = new File(module, 
SOURCE_CONNECTOR_SERVICE_FILE).isFile();
+            if (!sink && !source) {
+                continue;
+            }
+            CamelKafkaConnectorTableOptionModel singleConnector = new 
CamelKafkaConnectorTableOptionModel();
+            singleConnector.setName(module.getName());
+            String docsName = connectorDocsName(module.getName());
+            if (sink) {
+                singleConnector.setSink(true);
+                singleConnector.setDocsSink(xrefConnectorLinkPrefix + docsName 
+ sinkConnectorLinkSuffix);
+            }
+            if (source) {
+                singleConnector.setSource(true);
+                singleConnector.setDocsSource(xrefConnectorLinkPrefix + 
docsName + sourceConnectorLinkSuffix);
+            }
+            String downloadLinkTar = repositoryPath + 
singleConnector.getName() + "/" + lastReleasedVersion + "/" + 
singleConnector.getName() + "-" + lastReleasedVersion + 
"-package.tar.gz[Download]";
+            singleConnector.setDownloadLinkTar(downloadLinkTar);
+            options.add(singleConnector);
+        }
+        options.sort((model1, model2) -> {
+            String name1 = model1.getName();
+            String name2 = model2.getName();
+            int res = String.CASE_INSENSITIVE_ORDER.compare(name1, name2);
+            return (res != 0) ? res : name1.compareTo(name2);
+        });
+        return options;
+    }
+
+    /**
+     * Returns the name of the reference pages of a connector module without 
their sink/source suffix. Connectors
+     * generated from a Camel component whose scheme is not a valid artifact 
id (e.g. coap+tcp) keep the scheme there.
+     */
+    private static String connectorDocsName(String moduleName) {
+        String connectorFinal = StringUtils.removeEnd(moduleName, 
"kafka-connector");
+        if (connectorFinal.equalsIgnoreCase("camel-coap-tcp-")) {
+            return "camel-coap+tcp-";
+        } else if (connectorFinal.equalsIgnoreCase("camel-coaps-tcp-")) {
+            return "camel-coaps+tcp-";
+        }
+        return connectorFinal;
+    }
+
+    private static File resolve(File baseDir, String path) {
+        File file = new File(path);
+        return file.isAbsolute() ? file : new File(baseDir, path);
+    }
+
     private String templateConnnectorsTable(CamelKafkaConnectorTableModel 
model) throws MojoExecutionException {
 
         try {
diff --git 
a/tooling/camel-kafka-connector-docs-maven-plugin/src/test/java/org/apache/camel/kafkaconnector/maven/docs/UpdateDocComponentsListMojoTest.java
 
b/tooling/camel-kafka-connector-docs-maven-plugin/src/test/java/org/apache/camel/kafkaconnector/maven/docs/UpdateDocComponentsListMojoTest.java
new file mode 100644
index 0000000000..bf5d1e1982
--- /dev/null
+++ 
b/tooling/camel-kafka-connector-docs-maven-plugin/src/test/java/org/apache/camel/kafkaconnector/maven/docs/UpdateDocComponentsListMojoTest.java
@@ -0,0 +1,188 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.kafkaconnector.maven.docs;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+
+import 
org.apache.camel.kafkaconnector.maven.docs.dto.CamelKafkaConnectorTableOptionModel;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class UpdateDocComponentsListMojoTest {
+
+    private static final String SINK_MANIFEST = 
"src/main/resources/META-INF/services/org.apache.kafka.connect.sink.SinkConnector";
+    private static final String SOURCE_MANIFEST = 
"src/main/resources/META-INF/services/org.apache.kafka.connect.source.SourceConnector";
+    private static final String REPOSITORY = 
"https://repo.maven.apache.org/maven2/org/apache/camel/kafkaconnector/";;
+
+    @TempDir
+    private Path projectBaseDir;
+
+    private Path connectorsDir;
+    private UpdateDocComponentsListMojo mojo;
+
+    @BeforeEach
+    public void createMojo() throws IOException {
+        connectorsDir = 
Files.createDirectories(projectBaseDir.resolve("connectors"));
+        Files.writeString(connectorsDir.resolve("pom.xml"), "");
+
+        // the configuration of the connectors aggregator, with the default 
values of the parameters
+        mojo = new UpdateDocComponentsListMojo();
+        mojo.connectorsDir = connectorsDir.toFile();
+        mojo.projectBaseDir = projectBaseDir.toFile();
+        mojo.repositoryPath = REPOSITORY;
+        mojo.lastReleasedVersion = "4.22.0";
+        mojo.xrefConnectorLinkPrefix = "xref:reference/connectors/";
+        mojo.sinkConnectorLinkSuffix = "kafka-sink-connector.adoc[Sink Docs]";
+        mojo.sourceConnectorLinkSuffix = "kafka-source-connector.adoc[Source 
Docs]";
+        mojo.docsModuleDir = "docs/modules/ROOT/";
+        mojo.connectorsIndexFile = "pages/reference/index.adoc";
+        mojo.navFile = "nav.adoc";
+    }
+
+    @Test
+    public void detectsConnectorModulesFromTheirServiceLoaderManifests() 
throws Exception {
+        addFile("camel-foo-sink-kafka-connector", SINK_MANIFEST);
+        addFile("camel-foo-source-kafka-connector", SOURCE_MANIFEST);
+        addFile("camel-both-kafka-connector", SINK_MANIFEST);
+        addFile("camel-both-kafka-connector", SOURCE_MANIFEST);
+        // stale build output, e.g. left behind by a module removed from the 
sources, is never looked at
+        addFile("camel-stale-kafka-connector", 
"target/classes/org/apache/camel/kafkaconnector/stale/CamelStaleSinkTask.class");
+        addFile("camel-stale-kafka-connector", 
"target/classes/META-INF/services/org.apache.kafka.connect.sink.SinkConnector");
+        addFile("camel-partly-stale-kafka-connector", SINK_MANIFEST);
+        addFile("camel-partly-stale-kafka-connector", 
"target/classes/org/apache/camel/kafkaconnector/partlystale/CamelPartlyStaleSourceTask.class");
+        addFile("camel-partly-stale-kafka-connector", 
"target/classes/META-INF/services/org.apache.kafka.connect.source.SourceConnector");
+        addFile("target", 
"classes/META-INF/services/org.apache.kafka.connect.sink.SinkConnector");
+
+        List<CamelKafkaConnectorTableOptionModel> connectors = 
mojo.findConnectors();
+
+        assertEquals(4, connectors.size(), connectors.toString());
+        assertConnector(connectors.get(0), "camel-both-kafka-connector",
+                
"xref:reference/connectors/camel-both-kafka-sink-connector.adoc[Sink Docs]",
+                
"xref:reference/connectors/camel-both-kafka-source-connector.adoc[Source 
Docs]");
+        assertConnector(connectors.get(1), "camel-foo-sink-kafka-connector",
+                
"xref:reference/connectors/camel-foo-sink-kafka-sink-connector.adoc[Sink 
Docs]", "");
+        assertConnector(connectors.get(2), "camel-foo-source-kafka-connector",
+                "", 
"xref:reference/connectors/camel-foo-source-kafka-source-connector.adoc[Source 
Docs]");
+        assertConnector(connectors.get(3), 
"camel-partly-stale-kafka-connector",
+                
"xref:reference/connectors/camel-partly-stale-kafka-sink-connector.adoc[Sink 
Docs]", "");
+    }
+
+    @Test
+    public void 
keepsTheComponentSchemeInTheDocsLinksOfSanitizedConnectorNames() throws 
Exception {
+        addFile("camel-coap-tcp-kafka-connector", SINK_MANIFEST);
+        addFile("camel-coap-tcp-kafka-connector", SOURCE_MANIFEST);
+        addFile("camel-coaps-tcp-kafka-connector", SINK_MANIFEST);
+
+        List<CamelKafkaConnectorTableOptionModel> connectors = 
mojo.findConnectors();
+
+        assertEquals(2, connectors.size(), connectors.toString());
+        assertConnector(connectors.get(0), "camel-coap-tcp-kafka-connector",
+                
"xref:reference/connectors/camel-coap+tcp-kafka-sink-connector.adoc[Sink Docs]",
+                
"xref:reference/connectors/camel-coap+tcp-kafka-source-connector.adoc[Source 
Docs]");
+        assertConnector(connectors.get(1), "camel-coaps-tcp-kafka-connector",
+                
"xref:reference/connectors/camel-coaps+tcp-kafka-sink-connector.adoc[Sink 
Docs]", "");
+    }
+
+    @Test
+    public void updatesTheConnectorsTableAndNavBetweenTheirMarkers() throws 
Exception {
+        addFile("camel-foo-sink-kafka-connector", SINK_MANIFEST);
+        addFile("camel-both-kafka-connector", SINK_MANIFEST);
+        addFile("camel-both-kafka-connector", SOURCE_MANIFEST);
+        Path index = 
writeFile(projectBaseDir.resolve("docs/modules/ROOT/pages/reference/index.adoc"),
+                "= Supported connectors\n\n// kafka-connectors list: 
START\nNumber of Camel Kafka connectors: 0\n// kafka-connectors list: 
END\n\nAfter the table\n");
+        Path nav = 
writeFile(projectBaseDir.resolve("docs/modules/ROOT/nav.adoc"),
+                "** xref:reference/index.adoc[Connectors]\n// connectors: 
START\n*** camel-removed-kafka-connector\n// connectors: END\n* 
xref:other.adoc[Other]\n");
+
+        mojo.executeComponentsReadme();
+
+        String table = Files.readString(index);
+        assertTrue(table.startsWith("= Supported connectors\n\n// 
kafka-connectors list: START\nNumber of Camel Kafka connectors: 2"), table);
+        assertTrue(table.contains("\n| *camel-both-kafka-connector* | true | 
true"
+                + " | 
xref:reference/connectors/camel-both-kafka-sink-connector.adoc[Sink Docs]"
+                + " | 
xref:reference/connectors/camel-both-kafka-source-connector.adoc[Source Docs]"
+                + " | " + REPOSITORY + 
"camel-both-kafka-connector/4.22.0/camel-both-kafka-connector-4.22.0-package.tar.gz[Download]\n"),
 table);
+        assertTrue(table.contains("\n| *camel-foo-sink-kafka-connector* | true 
| false"
+                + " | 
xref:reference/connectors/camel-foo-sink-kafka-sink-connector.adoc[Sink Docs] | 
"
+                + " | " + REPOSITORY + 
"camel-foo-sink-kafka-connector/4.22.0/camel-foo-sink-kafka-connector-4.22.0-package.tar.gz[Download]\n"),
 table);
+        assertTrue(table.endsWith("\n|===\n// kafka-connectors list: 
END\n\nAfter the table\n"), table);
+        assertFalse(table.contains("connectors: 0"), table);
+
+        assertEquals("** xref:reference/index.adoc[Connectors]\n"
+                + "// connectors: START\n"
+                + "*** camel-both-kafka-connector\n"
+                + "**** 
xref:reference/connectors/camel-both-kafka-source-connector.adoc[Source Docs]\n"
+                + "**** 
xref:reference/connectors/camel-both-kafka-sink-connector.adoc[Sink Docs]\n"
+                + "*** camel-foo-sink-kafka-connector\n"
+                + "**** 
xref:reference/connectors/camel-foo-sink-kafka-sink-connector.adoc[Sink Docs]\n"
+                + "// connectors: END\n"
+                + "* xref:other.adoc[Other]\n", Files.readString(nav));
+    }
+
+    @Test
+    public void usesTheConfiguredDocsFilesAndLinks() throws Exception {
+        addFile("camel-foo-sink-kafka-connector", SINK_MANIFEST);
+        addFile("camel-foo-source-kafka-connector", SOURCE_MANIFEST);
+        Path docsModuleDir = projectBaseDir.resolve("site/modules/connectors");
+        Path index = writeFile(docsModuleDir.resolve("pages/list.adoc"), "// 
kafka-connectors list: START\n// kafka-connectors list: END\n");
+        Path nav = writeFile(docsModuleDir.resolve("partials/nav.adoc"), "// 
connectors: START\n// connectors: END\n");
+        mojo.docsModuleDir = docsModuleDir.toString();
+        mojo.connectorsIndexFile = "pages/list.adoc";
+        mojo.navFile = "partials/nav.adoc";
+        mojo.xrefConnectorLinkPrefix = "xref:connectors/";
+        mojo.sinkConnectorLinkSuffix = "sink.adoc[Sink]";
+        mojo.sourceConnectorLinkSuffix = "source.adoc[Source]";
+
+        mojo.executeComponentsReadme();
+
+        String table = Files.readString(index);
+        assertTrue(table.contains("\n| *camel-foo-sink-kafka-connector* | true 
| false | xref:connectors/camel-foo-sink-sink.adoc[Sink] |  | "), table);
+        assertTrue(table.contains("\n| *camel-foo-source-kafka-connector* | 
false | true |  | xref:connectors/camel-foo-source-source.adoc[Source] | "), 
table);
+        assertEquals("// connectors: START\n"
+                + "*** camel-foo-sink-kafka-connector\n"
+                + "**** xref:connectors/camel-foo-sink-sink.adoc[Sink]\n"
+                + "*** camel-foo-source-kafka-connector\n"
+                + "**** xref:connectors/camel-foo-source-source.adoc[Source]\n"
+                + "// connectors: END\n", Files.readString(nav));
+        assertFalse(Files.exists(projectBaseDir.resolve("docs")), "the default 
docs module must not be touched");
+    }
+
+    private void addFile(String module, String path) throws IOException {
+        writeFile(connectorsDir.resolve(module).resolve(path), "");
+    }
+
+    private static Path writeFile(Path file, String content) throws 
IOException {
+        Files.createDirectories(file.getParent());
+        return Files.writeString(file, content);
+    }
+
+    private static void assertConnector(CamelKafkaConnectorTableOptionModel 
connector, String name, String docsSink, String docsSource) {
+        assertEquals(name, connector.getName());
+        assertEquals(!docsSink.isEmpty(), connector.isSink(), name);
+        assertEquals(docsSink, connector.getDocsSink(), name);
+        assertEquals(!docsSource.isEmpty(), connector.isSource(), name);
+        assertEquals(docsSource, connector.getDocsSource(), name);
+        assertEquals(REPOSITORY + name + "/4.22.0/" + name + 
"-4.22.0-package.tar.gz[Download]", connector.getDownloadLinkTar(), name);
+    }
+}

Reply via email to