You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/02/06 13:17:04 UTC

[camel] 01/01: CAMEL-14503: Hack to make cpmp do 3rd party components

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

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

commit 8e29e1744a83a253bc3beeaffbfab6504ee792f5
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Feb 6 14:02:26 2020 +0100

    CAMEL-14503: Hack to make cpmp do 3rd party components
---
 .../packaging/EndpointSchemaGeneratorMojo.java     | 37 ++++++++++++++++------
 1 file changed, 28 insertions(+), 9 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 0526959..b83bd98 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
@@ -42,6 +42,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
+import java.util.Optional;
 import java.util.Set;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
@@ -275,10 +276,12 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
         doc = JavadocHelper.sanitizeDescription(doc, false);
         option.setDescription(doc);
 
+        /*
+
         if (isNullOrEmpty(doc)) {
             throw new IllegalStateException("Empty doc for option: " + option.getName() + ", parent options: "
                     + (parentOptions != null ? Jsoner.serialize(JsonMapper.asJsonObject(parentOptions)) : "<null>"));
-        }
+        }*/
     }
 
     private boolean filterOutOption(ComponentModel component, BaseOptionModel option) {
@@ -495,11 +498,13 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
             // We order the methods according to the source code to keep compatibility
             // with the old apt processing tool, however, we could get rid of that
             JavaClassSource source = javaClassSource(classElement.getName());
-            List<MethodSource<JavaClassSource>> methodSources = source.getMethods().stream()
+            List<MethodSource<JavaClassSource>> methodSources = source != null ?
+                    source.getMethods().stream()
                     .filter(method -> method.isPublic()
                             && method.getName().startsWith("set")
                             && method.getParameters().size() == 1
-                            && method.getReturnType().getName().equals("void")).collect(Collectors.toList());
+                            && method.getReturnType().getName().equals("void")).collect(Collectors.toList()) :
+                    Collections.EMPTY_LIST;
 
             List<Method> methods = Stream.of(classElement.getDeclaredMethods()).filter(method -> {
                 Metadata metadata = method.getAnnotation(Metadata.class);
@@ -529,6 +534,9 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
                 }
                 return true;
             }).sorted(Comparator.comparing(m -> {
+                if (methodSources.isEmpty()) {
+                    return 0;
+                }
                 int index = -1;
                 for (int i = 0; i < methodSources.size(); i++) {
                     MethodSource<?> ms = methodSources.get(i);
@@ -536,8 +544,7 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
                             && ms.getReturnType().getName().equals("void")
                             && ms.getParameters().size() == 1
                             && getSimpleName(ms.getParameters().get(0).getType())
-                                    .equals(m.getParameters()[0].getType().getSimpleName())
-                    ) {
+                                    .equals(m.getParameters()[0].getType().getSimpleName())) {
                         index = i;
                     }
                 }
@@ -1228,6 +1235,9 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
     }
 
     static String getJavaDocText(String source, JavaDocCapable<?> member) {
+        if (member == null) {
+            return null;
+        }
         JavaDoc<?> javaDoc = member.getJavaDoc();
         Javadoc jd = (Javadoc) javaDoc.getInternal();
         if (source != null && jd.tags().size() > 0) {
@@ -1255,8 +1265,8 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
                 sourceRoots = project.getCompileSourceRoots().stream()
                         .map(Paths::get)
                         .collect(Collectors.toList());
-                Path camelRoot = PackageHelper.findCamelCoreDirectory(project.getBasedir())
-                        .toPath().getParent().getParent();
+                File camelRootFile = PackageHelper.findCamelCoreDirectory(project.getBasedir());
+                final Path camelRoot = camelRootFile != null ? camelRootFile.toPath().getParent().getParent() : project.getBasedir().toPath();
                 project.getCompileClasspathElements().stream()
                         .flatMap(dep -> {
                             // m2 repo dependency
@@ -1264,7 +1274,7 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
                                 String name = Strings.before(Strings.after(dep, "/org/apache/camel/"), "/");
                                 return Stream.of(name);
                             // reactor dependency
-                            } else if (dep.startsWith(camelRoot.toString() + "/")) {
+                            } else if (camelRootFile != null && dep.startsWith(camelRoot.toString() + "/")) {
                                 String name = Strings.before(Strings.after(dep, camelRoot.toString() + "/"), "/target");
                                 int idx = name.lastIndexOf("/");
                                 if (idx > 0) {
@@ -1302,7 +1312,11 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
     private JavaClassSource doParseJavaClassSource(String className) {
         try {
             String source = loadJavaSource(className);
-            return (JavaClassSource) Roaster.parse(source);
+            if (source != null) {
+                return (JavaClassSource) Roaster.parse(source);
+            } else {
+                return null;
+            }
         } catch (Exception e) {
             throw new RuntimeException("Unable to parse java class " + className, e);
         }
@@ -1313,6 +1327,11 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
     }
 
     private String doLoadJavaSource(String className) {
+        // skip default
+        if (className.startsWith("org.apache.camel.support.")) {
+            return null;
+        }
+
         try {
             Path file = getSourceRoots().stream()
                     .map(d -> d.resolve(className.replace('.', '/') + ".java"))