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/03 11:46:23 UTC

[camel] 02/10: CAMEL-15498: Add java source parser for discovering API methods for API based components.

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

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

commit 7827ff02870144aed3ab122668e5dec23ee84f05
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Sep 3 09:57:04 2020 +0200

    CAMEL-15498:  Add java source parser for discovering API methods for API based components.
---
 .../camel/maven/ApiComponentGeneratorMojo.java     | 33 +++++++++++++++++++---
 .../main/java/org/apache/camel/maven/ApiProxy.java | 10 +++++++
 .../apache/camel/maven/DocumentGeneratorMojo.java  |  3 ++
 .../org/apache/camel/maven/FromJavasource.java     | 23 +++++++++++++++
 4 files changed, 65 insertions(+), 4 deletions(-)

diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiComponentGeneratorMojo.java b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiComponentGeneratorMojo.java
index df3160c..51f732c 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiComponentGeneratorMojo.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiComponentGeneratorMojo.java
@@ -48,6 +48,12 @@ public class ApiComponentGeneratorMojo extends AbstractApiMethodBaseMojo {
     protected FromJavadoc fromJavadoc = new FromJavadoc();
 
     /**
+     * Common Javasource code generation settings.
+     */
+    @Parameter
+    protected FromJavasource fromJavasource = new FromJavasource();
+
+    /**
      * Names of options that can be set to null value if not specified.
      */
     @Parameter
@@ -159,14 +165,20 @@ public class ApiComponentGeneratorMojo extends AbstractApiMethodBaseMojo {
 
         final File signatureFile = api.getFromSignatureFile();
         if (signatureFile != null) {
-
             final FileApiMethodGeneratorMojo fileMojo = new FileApiMethodGeneratorMojo();
             fileMojo.signatureFile = signatureFile;
             apiMethodGenerator = fileMojo;
-
         } else {
-
             final FromJavadoc apiFromJavadoc = api.getFromJavadoc();
+            final FromJavasource apiFromJavasource = api.getFromJavasource();
+
+            if (apiFromJavadoc == null && apiFromJavasource == null) {
+                throw new IllegalArgumentException("Must specify to use either fromJavadoc or fromJavasource");
+            }
+            if (apiFromJavadoc != null && apiFromJavasource != null) {
+                throw new IllegalArgumentException("Cannot use both fromJavadoc and fromJavasource");
+            }
+
             if (apiFromJavadoc != null) {
                 final JavadocApiMethodGeneratorMojo javadocMojo = new JavadocApiMethodGeneratorMojo();
                 javadocMojo.excludePackages = apiFromJavadoc.getExcludePackages() != null
@@ -179,9 +191,22 @@ public class ApiComponentGeneratorMojo extends AbstractApiMethodBaseMojo {
                         ? apiFromJavadoc.getExcludeMethods() : fromJavadoc.getExcludeMethods();
                 javadocMojo.includeStaticMethods = apiFromJavadoc.getIncludeStaticMethods() != null
                         ? apiFromJavadoc.getIncludeStaticMethods() : fromJavadoc.getIncludeStaticMethods();
-
                 apiMethodGenerator = javadocMojo;
             }
+            if (apiFromJavasource != null) {
+                final JavaSourceApiMethodGeneratorMojo javasourceMojo = new JavaSourceApiMethodGeneratorMojo();
+                javasourceMojo.excludePackages = apiFromJavasource.getExcludePackages() != null
+                        ? apiFromJavasource.getExcludePackages() : apiFromJavasource.getExcludePackages();
+                javasourceMojo.excludeClasses = apiFromJavasource.getExcludeClasses() != null
+                        ? apiFromJavasource.getExcludeClasses() : apiFromJavasource.getExcludeClasses();
+                javasourceMojo.includeMethods = apiFromJavasource.getIncludeMethods() != null
+                        ? apiFromJavasource.getIncludeMethods() : apiFromJavasource.getIncludeMethods();
+                javasourceMojo.excludeMethods = apiFromJavasource.getExcludeMethods() != null
+                        ? apiFromJavasource.getExcludeMethods() : apiFromJavasource.getExcludeMethods();
+                javasourceMojo.includeStaticMethods = apiFromJavasource.getIncludeStaticMethods() != null
+                        ? apiFromJavasource.getIncludeStaticMethods() : apiFromJavasource.getIncludeStaticMethods();
+                apiMethodGenerator = javasourceMojo;
+            }
         }
         return apiMethodGenerator;
     }
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiProxy.java b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiProxy.java
index ad8038d..c7f0778 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiProxy.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiProxy.java
@@ -35,6 +35,8 @@ public class ApiProxy {
 
     private FromJavadoc fromJavadoc;
 
+    private FromJavasource fromJavasource;
+
     private Substitution[] substitutions = new Substitution[0];
 
     private String excludeConfigNames;
@@ -81,6 +83,14 @@ public class ApiProxy {
         this.fromJavadoc = fromJavadoc;
     }
 
+    public FromJavasource getFromJavasource() {
+        return fromJavasource;
+    }
+
+    public void setFromJavasource(FromJavasource fromJavasource) {
+        this.fromJavasource = fromJavasource;
+    }
+
     public Substitution[] getSubstitutions() {
         return substitutions;
     }
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/DocumentGeneratorMojo.java b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/DocumentGeneratorMojo.java
index c384e1f..39e66a9 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/DocumentGeneratorMojo.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/DocumentGeneratorMojo.java
@@ -57,8 +57,11 @@ import org.codehaus.plexus.util.StringUtils;
  */
 @Mojo(name = "document", requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true,
       defaultPhase = LifecyclePhase.SITE, threadSafe = true)
+@Deprecated
 public class DocumentGeneratorMojo extends AbstractGeneratorMojo implements MavenReport {
 
+    // TODO: remove me
+
     // document output directory
     @Parameter(property = PREFIX + "reportOutputDirectory",
                defaultValue = "${project.reporting.outputDirectory}/cameldocs")
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/FromJavasource.java b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/FromJavasource.java
new file mode 100644
index 0000000..1fb2e7b
--- /dev/null
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/FromJavasource.java
@@ -0,0 +1,23 @@
+/*
+ * 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;
+
+/**
+ * Java source API generator properties.
+ */
+public class FromJavasource extends FromJavadoc {
+}