You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by zr...@apache.org on 2020/11/05 12:09:29 UTC

[camel-spring-boot] 02/03: fix: xref link for local components

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

zregvart pushed a commit to branch camel-spring-boot-3.4.x
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git

commit 3a39fd649c7143e8b81e9fac76dfdea72ba28e0b
Author: Zoran Regvart <zr...@apache.org>
AuthorDate: Thu Nov 5 11:54:37 2020 +0100

    fix: xref link for local components
    
    We have the components from `core` module in the Camel catalog so when
    generating the list of starters they get pulled in and linked to the
    (main) Camel components reference where they do not exist.
    
    Logic for detecting such components by looking if the `.adoc` files are
    present looked at `component-starters` subdirectory of
    `docs/modules/ROOT/pages` and did not detect them as local components.
    
    This fixes that as all `.adoc` files are placed within
    `docs/modules/ROOT/pages`.
    
    Also cleans up the logic a bit.
    
    (cherry picked from commit bb9ed4f4e84e64eb1512165f84be7fc7cd7d6056)
    
    # Conflicts:
    #	components-starter/README.adoc
    #	docs/modules/ROOT/pages/list.adoc
    #	tooling/camel-spring-boot-docs-maven-plugin/src/main/java/org/apache/camel/springboot/maven/ExtMvelHelper.java
---
 components-starter/README.adoc                     |  8 ++--
 docs/modules/ROOT/pages/list.adoc                  |  8 ++--
 .../camel/springboot/maven/ExtMvelHelper.java      | 55 ++++++++++------------
 .../maven/UpdateDocComponentsListMojo.java         |  3 +-
 4 files changed, 34 insertions(+), 40 deletions(-)

diff --git a/components-starter/README.adoc b/components-starter/README.adoc
index 22d5432..10de155 100644
--- a/components-starter/README.adoc
+++ b/components-starter/README.adoc
@@ -1309,16 +1309,16 @@ Number of miscellaneous extensions: 26 in 26 JAR artifacts (1 deprecated)
 | xref:3.4.x@components:others:shiro.adoc[Shiro] +
 (camel-shiro-starter) | 2.5 | Security using Shiro
 
-| xref:3.4.x@components:others:spring-cloud.adoc[Spring Cloud] +
+| xref:spring-cloud.adoc[Spring Cloud] +
 (camel-spring-cloud-starter) | 2.19 | Camel Cloud integration with Spring Cloud
 
-| xref:3.4.x@components:others:spring-cloud-consul.adoc[Spring Cloud Consul] +
+| xref:spring-cloud-consul.adoc[Spring Cloud Consul] +
 (camel-spring-cloud-consul-starter) | 2.19 | Camel Cloud integration with Spring Cloud Consul
 
-| xref:3.4.x@components:others:spring-cloud-netflix.adoc[Spring Cloud Netflix] +
+| xref:spring-cloud-netflix.adoc[Spring Cloud Netflix] +
 (camel-spring-cloud-netflix-starter) | 2.19 | Camel Cloud integration with Spring Cloud Netflix
 
-| xref:3.4.x@components:others:spring-cloud-zookeeper.adoc[Spring Cloud Zookeeper] +
+| xref:spring-cloud-zookeeper.adoc[Spring Cloud Zookeeper] +
 (camel-spring-cloud-zookeeper-starter) | 2.19 | Camel Cloud integration with Spring Cloud Zookeeper
 
 | xref:3.4.x@components:others:spring-javaconfig.adoc[Spring Java Configuration] +
diff --git a/docs/modules/ROOT/pages/list.adoc b/docs/modules/ROOT/pages/list.adoc
index 22d5432..10de155 100644
--- a/docs/modules/ROOT/pages/list.adoc
+++ b/docs/modules/ROOT/pages/list.adoc
@@ -1309,16 +1309,16 @@ Number of miscellaneous extensions: 26 in 26 JAR artifacts (1 deprecated)
 | xref:3.4.x@components:others:shiro.adoc[Shiro] +
 (camel-shiro-starter) | 2.5 | Security using Shiro
 
-| xref:3.4.x@components:others:spring-cloud.adoc[Spring Cloud] +
+| xref:spring-cloud.adoc[Spring Cloud] +
 (camel-spring-cloud-starter) | 2.19 | Camel Cloud integration with Spring Cloud
 
-| xref:3.4.x@components:others:spring-cloud-consul.adoc[Spring Cloud Consul] +
+| xref:spring-cloud-consul.adoc[Spring Cloud Consul] +
 (camel-spring-cloud-consul-starter) | 2.19 | Camel Cloud integration with Spring Cloud Consul
 
-| xref:3.4.x@components:others:spring-cloud-netflix.adoc[Spring Cloud Netflix] +
+| xref:spring-cloud-netflix.adoc[Spring Cloud Netflix] +
 (camel-spring-cloud-netflix-starter) | 2.19 | Camel Cloud integration with Spring Cloud Netflix
 
-| xref:3.4.x@components:others:spring-cloud-zookeeper.adoc[Spring Cloud Zookeeper] +
+| xref:spring-cloud-zookeeper.adoc[Spring Cloud Zookeeper] +
 (camel-spring-cloud-zookeeper-starter) | 2.19 | Camel Cloud integration with Spring Cloud Zookeeper
 
 | xref:3.4.x@components:others:spring-javaconfig.adoc[Spring Java Configuration] +
diff --git a/tooling/camel-spring-boot-docs-maven-plugin/src/main/java/org/apache/camel/springboot/maven/ExtMvelHelper.java b/tooling/camel-spring-boot-docs-maven-plugin/src/main/java/org/apache/camel/springboot/maven/ExtMvelHelper.java
index d5de97b..8229fd8 100644
--- a/tooling/camel-spring-boot-docs-maven-plugin/src/main/java/org/apache/camel/springboot/maven/ExtMvelHelper.java
+++ b/tooling/camel-spring-boot-docs-maven-plugin/src/main/java/org/apache/camel/springboot/maven/ExtMvelHelper.java
@@ -16,14 +16,17 @@
  */
 package org.apache.camel.springboot.maven;
 
+import java.nio.file.Files;
 import java.nio.file.Path;
 
 import org.apache.camel.maven.packaging.MvelHelper;
-import org.apache.camel.tooling.model.OtherModel;
-import org.apache.camel.tooling.util.Strings;
+import org.apache.camel.tooling.model.ArtifactModel;
+import org.apache.camel.tooling.model.BaseModel;
 import org.apache.camel.tooling.model.ComponentModel;
 import org.apache.camel.tooling.model.DataFormatModel;
 import org.apache.camel.tooling.model.LanguageModel;
+import org.apache.camel.tooling.model.OtherModel;
+import org.apache.camel.tooling.model.SupportLevel;
 
 public class ExtMvelHelper {
 
@@ -37,46 +40,38 @@ public class ExtMvelHelper {
         return MvelHelper.escape(raw);
     }
 
-    public String getFirstVersionShort(Object model) {
-        String version = (String) invokeGetter(model, "getFirstVersion");
+    public String getFirstVersionShort(BaseModel<?> model) {
+        String version = model.getFirstVersion();
         return org.apache.camel.tooling.model.Strings.cutLastZeroDigit(version);
     }
 
-    public String getDocLink(Object model) {
-        if (localDocExists(model)) {
-            return getLocalDocLink(model);
+    public String getSupportLevel(ArtifactModel<?> model) {
+        final SupportLevel supportLevel = model.getSupportLevel();
+        if (supportLevel != null) {
+            return model.getSupportLevel().name();
+        }
+
+        return SupportLevel.Preview.name();
+    }
+
+    public String getDocLink(ArtifactModel<?> model) {
+        if (isLocalComponent(model)) {
+            return String.format("xref:%s.adoc", ((ArtifactModel<?>) model).getName());
         } else if (model instanceof ComponentModel) {
-            return String.format("xref:3.4.x@components::%s-component.adoc", invokeGetter(model, "getScheme"));
+            return String.format("xref:3.4.x@components::%s-component.adoc", ((ComponentModel) model).getScheme());
         } else if (model instanceof DataFormatModel) {
-            return String.format("xref:3.4.x@components:dataformats:%s-dataformat.adoc", invokeGetter(model, "getName"));
+            return String.format("xref:3.4.x@components:dataformats:%s-dataformat.adoc", ((DataFormatModel) model).getName());
         } else if (model instanceof LanguageModel) {
-            return String.format("xref:3.4.x@components:languages:%s-language.adoc", invokeGetter(model, "getName"));
+            return String.format("xref:3.4.x@components:languages:%s-language.adoc", ((LanguageModel) model).getName());
         } else if (model instanceof OtherModel) {
-            return String.format("xref:3.4.x@components:others:%s.adoc", invokeGetter(model, "getName"));
+            return String.format("xref:3.4.x@components:others:%s.adoc", ((OtherModel) model).getName());
         } else {
             return null;
         }
     }
 
-    private Object invokeGetter(Object model, String method) {
-        try {
-            return model.getClass().getMethod(method)
-                    .invoke(model);
-        } catch (Exception e) {
-            throw new RuntimeException("Unable to access " + method + " from " + model, e);
-        }
-    }
-
-    private boolean localDocExists(Object model) {
-        Path path = extensionsDocPath.resolve(getSpringBootDocName(model));
-        return path.toFile().exists();
+    private boolean isLocalComponent(ArtifactModel<?> model) {
+        return Files.exists(extensionsDocPath.resolve(((ArtifactModel<?>) model).getName() + ".adoc"));
     }
 
-    private String getLocalDocLink(Object model) {
-        return "xref:components-starter/" + getSpringBootDocName(model);
-    }
-
-    private String getSpringBootDocName(Object model) {
-        return Strings.after((String) invokeGetter(model, "getArtifactId"), "camel-") + ".adoc";
-    }
 }
diff --git a/tooling/camel-spring-boot-docs-maven-plugin/src/main/java/org/apache/camel/springboot/maven/UpdateDocComponentsListMojo.java b/tooling/camel-spring-boot-docs-maven-plugin/src/main/java/org/apache/camel/springboot/maven/UpdateDocComponentsListMojo.java
index 9bc9f8c..0312ded 100644
--- a/tooling/camel-spring-boot-docs-maven-plugin/src/main/java/org/apache/camel/springboot/maven/UpdateDocComponentsListMojo.java
+++ b/tooling/camel-spring-boot-docs-maven-plugin/src/main/java/org/apache/camel/springboot/maven/UpdateDocComponentsListMojo.java
@@ -20,7 +20,6 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -628,7 +627,7 @@ public class UpdateDocComponentsListMojo extends AbstractMojo {
     }
 
     private Path getComponentsStarterDocPath() {
-        return Paths.get(websiteDocBaseDir.toString(), "components-starter");
+        return websiteDocBaseDir.toPath();
     }
 
 }