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/09/15 15:56:56 UTC

[camel] 07/22: CAMEL-15478: api-component should generate @ApiParam with more fine grained details so we know which parameter is for which api method.

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

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

commit 9f8f9fb73cb902a57bb2aed24486afd94cde6a87
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Sep 14 10:18:52 2020 +0200

    CAMEL-15478: api-component should generate @ApiParam with more fine grained details so we know which parameter is for which api method.
---
 .../apache/camel/maven/AbstractGeneratorMojo.java  |  9 ++-
 .../org/apache/camel/maven/JavaSourceParser.java   |  6 +-
 .../org/apache/camel/component/test/TestProxy.java | 18 +++---
 .../camel/maven/ApiComponentGeneratorMojoTest.java |  2 +-
 .../ApiJavaSourceComponentGeneratorMojoTest.java   | 64 ++++++++++++++++++++++
 .../apache/camel/maven/JavaSourceParserTest.java   |  6 +-
 .../src/test/resources/test-proxy-signatures.txt   |  1 -
 7 files changed, 87 insertions(+), 19 deletions(-)

diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractGeneratorMojo.java b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractGeneratorMojo.java
index 4cc359e..9d44f67 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractGeneratorMojo.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractGeneratorMojo.java
@@ -20,6 +20,7 @@ import java.io.File;
 import java.io.IOError;
 import java.io.IOException;
 import java.io.StringWriter;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.nio.file.Path;
@@ -123,13 +124,17 @@ public abstract class AbstractGeneratorMojo extends AbstractMojo {
         this.projectClassLoader = projectClassLoader;
     }
 
-    private ClassLoader buildProjectClassLoader() throws DependencyResolutionRequiredException {
+    private ClassLoader buildProjectClassLoader() throws DependencyResolutionRequiredException, MalformedURLException {
         URL[] urls = project.getTestClasspathElements().stream()
                 .map(File::new)
                 .map(ThrowingHelper.wrapAsFunction(e -> e.toURI().toURL()))
-                .peek(url -> log.debug("Adding project path " + url))
+                .peek(url -> System.out.println("Adding project path " + url))
                 .toArray(URL[]::new);
 
+        if (urls.length == 0) {
+            urls = new URL[] { new URL("file:src/main/java/"), new URL("file:src/test/java/") };
+        }
+
         ClassLoader tccl = Thread.currentThread().getContextClassLoader();
         return new URLClassLoader(urls, tccl != null ? tccl : getClass().getClassLoader());
     }
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/JavaSourceParser.java b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/JavaSourceParser.java
index ac1e466..8419cf0 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/JavaSourceParser.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/JavaSourceParser.java
@@ -286,12 +286,16 @@ public class JavaSourceParser {
             return null;
         }
 
-        // remove leading - or / and whitespaces
+        // remove leading/trailing - or / and whitespaces
         desc = desc.trim();
         while (desc.startsWith("-") || desc.startsWith("/")) {
             desc = desc.substring(1);
             desc = desc.trim();
         }
+        while (desc.endsWith("-") || desc.endsWith("/")) {
+            desc = desc.substring(0, desc.length() - 1);
+            desc = desc.trim();
+        }
         desc = sanitizeDescription(desc, summary);
         if (desc != null && !desc.isEmpty()) {
             // upper case first letter
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/component/test/TestProxy.java b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/component/test/TestProxy.java
index 8eede8e..ea94d23 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/component/test/TestProxy.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/component/test/TestProxy.java
@@ -69,15 +69,11 @@ public class TestProxy {
         return "Greetings " + name1 + ", " + name2;
     }
 
-    public final String greetAll(final String[] names) {
-        StringBuilder builder = new StringBuilder("Greetings ");
-        for (String name : names) {
-            builder.append(name).append(", ");
-        }
-        builder.delete(builder.length() - 2, builder.length());
-        return builder.toString();
-    }
-
+    /**
+     * Greeting method for all
+     *
+     * @param names the names to greet
+     */
     public final String greetAll(List<String> names) {
         StringBuilder builder = new StringBuilder("Greetings ");
         for (String name : names) {
@@ -87,9 +83,9 @@ public class TestProxy {
         return builder.toString();
     }
 
-    public final String greetWildcard(String... names) {
+    public final String greetWildcard(String... wildcardNames) {
         StringBuilder builder = new StringBuilder("Greetings ");
-        for (String name : names) {
+        for (String name : wildcardNames) {
             builder.append(name).append(", ");
         }
         builder.delete(builder.length() - 2, builder.length());
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/ApiComponentGeneratorMojoTest.java b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/ApiComponentGeneratorMojoTest.java
index dd357d7..31d9de5 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/ApiComponentGeneratorMojoTest.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/ApiComponentGeneratorMojoTest.java
@@ -25,7 +25,7 @@ import org.apache.velocity.VelocityContext;
 import org.junit.jupiter.api.Test;
 
 /**
- * Tests {@link ApiComponentGeneratorMojo}
+ * Tests {@link ApiComponentGeneratorMojo} for signature file and javadoc
  */
 public class ApiComponentGeneratorMojoTest extends AbstractGeneratorMojoTest {
 
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/ApiJavaSourceComponentGeneratorMojoTest.java b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/ApiJavaSourceComponentGeneratorMojoTest.java
new file mode 100644
index 0000000..fd9bad2
--- /dev/null
+++ b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/ApiJavaSourceComponentGeneratorMojoTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.maven;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.component.test.TestProxy;
+import org.apache.velocity.VelocityContext;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link ApiComponentGeneratorMojo} for javasource parser
+ */
+public class ApiJavaSourceComponentGeneratorMojoTest extends AbstractGeneratorMojoTest {
+
+    @Test
+    public void testExecute() throws Exception {
+
+        final File collectionFile = new File(OUT_DIR, PACKAGE_PATH + COMPONENT_NAME + "ApiCollection.java");
+
+        // delete target files to begin
+        collectionFile.delete();
+
+        final ApiComponentGeneratorMojo mojo = createGeneratorMojo();
+
+        mojo.execute();
+
+        // check target file was generated
+        assertExists(collectionFile);
+    }
+
+    @Override
+    protected ApiComponentGeneratorMojo createGeneratorMojo() {
+        final ApiComponentGeneratorMojo mojo = new ApiComponentGeneratorMojo();
+        configureSourceGeneratorMojo(mojo);
+
+        mojo.apis = new ApiProxy[1];
+        mojo.apis[0] = new ApiProxy();
+        mojo.apis[0].setApiName("test");
+        mojo.apis[0].setProxyClass(TestProxy.class.getName());
+        final FromJavasource fromJavasource = new FromJavasource();
+        fromJavasource.setExcludePackages(JavaSourceApiMethodGeneratorMojo.DEFAULT_EXCLUDE_PACKAGES);
+        mojo.apis[0].setFromJavasource(fromJavasource);
+
+        return mojo;
+    }
+
+}
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/JavaSourceParserTest.java b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/JavaSourceParserTest.java
index b7eb376..e07abad 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/JavaSourceParserTest.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/JavaSourceParserTest.java
@@ -84,12 +84,12 @@ public class JavaSourceParserTest {
         final JavaSourceParser parser = new JavaSourceParser();
 
         parser.parse(new FileInputStream("src/test/java/org/apache/camel/component/test/TestProxy.java"), null);
-        assertEquals(11, parser.getMethods().size());
+        assertEquals(10, parser.getMethods().size());
 
         // varargs is transformed to an array type as that is what works
         assertEquals(
-                "public java.lang.String greetWildcard(String[] names)",
-                parser.getMethods().get(7));
+                "public java.lang.String greetWildcard(String[] wildcardNames)",
+                parser.getMethods().get(6));
         parser.reset();
     }
 
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/test/resources/test-proxy-signatures.txt b/tooling/maven/camel-api-component-maven-plugin/src/test/resources/test-proxy-signatures.txt
index 1d1b926..1b11a19 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/test/resources/test-proxy-signatures.txt
+++ b/tooling/maven/camel-api-component-maven-plugin/src/test/resources/test-proxy-signatures.txt
@@ -3,7 +3,6 @@ public String sayHi(boolean hello);
 public String sayHi(final String name);
 public final String greetMe(final String name);
 public final String greetUs(final String name1, String name2);
-public final String greetAll(String[] names);
 public final String greetAll(java.util.List<String> names);
 public final <T> String greetAll(java.util.List<T> people);
 public final <K, Vv> String greetAll(java.util.Map<K, Vv> peopleMap);