You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gn...@apache.org on 2020/03/03 06:32:33 UTC

[camel] 17/18: Sort the endpoints correctly in case there is an parent/child relationship

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

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit d1b3d437941edabd5fc99dbdc88157cd6a1203e2
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Tue Mar 3 07:19:57 2020 +0100

    Sort the endpoints correctly in case there is an parent/child relationship
---
 .../packaging/EndpointSchemaGeneratorMojo.java     | 42 +++++++++++++---------
 1 file changed, 26 insertions(+), 16 deletions(-)

diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java
index 9745755..ce024dc 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java
@@ -143,6 +143,7 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
                 return c1.getName().compareTo(c2.getName());
             }
         });
+        Map<Class, ComponentModel> models = new HashMap<>();
         for (Class<?> classElement : classes) {
             UriEndpoint uriEndpoint = classElement.getAnnotation(UriEndpoint.class);
             String scheme = uriEndpoint.scheme();
@@ -169,7 +170,26 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
                 }
                 final String aliasTitle = aTitle;
 
-                writeJSonSchemeAndPropertyConfigurer(classElement, uriEndpoint, aliasTitle, alias, extendsAlias, label, schemes);
+                ComponentModel parentData = null;
+                Class<?> superclass = classElement.getSuperclass();
+                if (superclass != null) {
+                    parentData = models.get(superclass);
+                    if (parentData == null) {
+                        UriEndpoint parentUriEndpoint = superclass.getAnnotation(UriEndpoint.class);
+                        if (parentUriEndpoint != null) {
+                            String parentScheme = parentUriEndpoint.scheme().split(",")[0];
+                            String superClassName = superclass.getName();
+                            String packageName = superClassName.substring(0, superClassName.lastIndexOf("."));
+                            String fileName = packageName.replace('.', '/') + "/" + parentScheme + ".json";
+                            String json = loadResource(fileName);
+                            parentData = JsonMapper.generateComponentModel(json);
+                        }
+                    }
+                }
+
+                ComponentModel model = writeJSonSchemeAndPropertyConfigurer(classElement, uriEndpoint, aliasTitle, alias,
+                        extendsAlias, label, schemes, parentData);
+                models.put(classElement, model);
             }
         }
     }
@@ -182,26 +202,14 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
         }
     }
 
-    protected void writeJSonSchemeAndPropertyConfigurer(Class<?> classElement, UriEndpoint uriEndpoint, String title,
-                                                        String scheme, String extendsScheme, String label, String[] schemes) {
+    protected ComponentModel writeJSonSchemeAndPropertyConfigurer(Class<?> classElement, UriEndpoint uriEndpoint, String title,
+                                                        String scheme, String extendsScheme, String label,
+                                                        String[] schemes, ComponentModel parentData) {
         // gather component information
         ComponentModel componentModel = findComponentProperties(uriEndpoint, classElement, title, scheme, extendsScheme, label, schemes);
 
         // get endpoint information which is divided into paths and options
         // (though there should really only be one path)
-        ComponentModel parentData = null;
-        Class<?> superclass = classElement.getSuperclass();
-        if (superclass != null) {
-            UriEndpoint parentUriEndpoint = superclass.getAnnotation(UriEndpoint.class);
-            if (parentUriEndpoint != null) {
-                String parentScheme = parentUriEndpoint.scheme().split(",")[0];
-                String superClassName = superclass.getName();
-                String packageName = superClassName.substring(0, superClassName.lastIndexOf("."));
-                String fileName = packageName.replace('.', '/') + "/" + parentScheme + ".json";
-                String json = loadResource(fileName);
-                parentData = JsonMapper.generateComponentModel(json);
-            }
-        }
 
         // component options
         Class<?> componentClassElement = loadClass(componentModel.getJavaType());
@@ -231,6 +239,8 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
         updateResource(resourcesOutputDir.toPath(), file, json);
 
         generateEndpointConfigurer(classElement, uriEndpoint, scheme, schemes, componentModel, parentData);
+
+        return componentModel;
     }
 
     protected void updateResource(Path dir, String file, String data) {