You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2022/04/01 16:44:13 UTC

[camel] branch CAMEL-17898/retrieve-headers-from-parent-classes updated (086d989 -> e385518)

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

nfilotto pushed a change to branch CAMEL-17898/retrieve-headers-from-parent-classes
in repository https://gitbox.apache.org/repos/asf/camel.git.


 discard 086d989  CAMEL-17898: Allow to retrieve header definitions from parent classes
     new e385518  CAMEL-17898: Allow to retrieve header definitions from parent classes

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (086d989)
            \
             N -- N -- N   refs/heads/CAMEL-17898/retrieve-headers-from-parent-classes (e385518)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

[camel] 01/01: CAMEL-17898: Allow to retrieve header definitions from parent classes

Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

nfilotto pushed a commit to branch CAMEL-17898/retrieve-headers-from-parent-classes
in repository https://gitbox.apache.org/repos/asf/camel.git

commit e385518b7fd78ff48722a6611a943c84c3d96aba
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Fri Apr 1 18:34:03 2022 +0200

    CAMEL-17898: Allow to retrieve header definitions from parent classes
---
 .../packaging/EndpointSchemaGeneratorMojo.java     | 31 +++++++++++++---------
 .../packaging/EndpointSchemaGeneratorMojoTest.java | 14 ++++++++++
 .../packaging/endpoint/SomeCommonConstants.java    | 28 +++++++++++++++++++
 .../SomeEndpointWithHeaderClassHierarchy.java      | 23 ++++++++++++++++
 .../packaging/endpoint/SomeSpecificConstants.java  | 28 +++++++++++++++++++
 5 files changed, 111 insertions(+), 13 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 fb9c3e3..f4be7d4 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
@@ -320,21 +320,26 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
         // A header class has been defined
         boolean foundHeader = false;
         final boolean isEnum = headersClass.isEnum();
-        for (Field field : headersClass.getDeclaredFields()) {
-            if ((isEnum || isStatic(field.getModifiers()) && field.getType() == String.class)
-                    && field.isAnnotationPresent(Metadata.class)) {
-                getLog().debug(
-                        String.format("Trying to add the constant %s in the class %s as header.", field.getName(),
-                                headersClass.getName()));
-                if (addEndpointHeader(componentModel, field, scheme)) {
-                    foundHeader = true;
-                    continue;
+        Class<?> currentClass = headersClass;
+        do {
+            for (Field field : currentClass.getDeclaredFields()) {
+                if ((isEnum || isStatic(field.getModifiers()) && field.getType() == String.class)
+                        && field.isAnnotationPresent(Metadata.class)) {
+                    getLog().debug(
+                            String.format("Trying to add the constant %s in the class %s as header.", field.getName(),
+                                    currentClass.getName()));
+                    if (addEndpointHeader(componentModel, field, scheme)) {
+                        foundHeader = true;
+                        continue;
+                    }
                 }
+                getLog().debug(
+                        String.format(
+                                "The field %s of the class %s is not considered as a name of a header, thus it is skipped",
+                                field.getName(), currentClass.getName()));
             }
-            getLog().debug(
-                    String.format("The field %s of the class %s is not considered as a name of a header, thus it is skipped",
-                            field.getName(), headersClass.getName()));
-        }
+            currentClass = currentClass.getSuperclass();
+        } while (!currentClass.equals(Object.class));
         if (!foundHeader) {
             getLog().debug(String.format("No headers have been detected in the headers class %s", headersClass.getName()));
         }
diff --git a/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojoTest.java b/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojoTest.java
index 903fad2..52c3596 100644
--- a/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojoTest.java
+++ b/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojoTest.java
@@ -23,6 +23,7 @@ import org.apache.camel.maven.packaging.endpoint.SomeEndpoint;
 import org.apache.camel.maven.packaging.endpoint.SomeEndpointUsingEnumConstants;
 import org.apache.camel.maven.packaging.endpoint.SomeEndpointWithBadHeaders;
 import org.apache.camel.maven.packaging.endpoint.SomeEndpointWithFilter;
+import org.apache.camel.maven.packaging.endpoint.SomeEndpointWithHeaderClassHierarchy;
 import org.apache.camel.maven.packaging.endpoint.SomeEndpointWithJavadocAsDescription;
 import org.apache.camel.maven.packaging.endpoint.SomeEndpointWithoutHeaders;
 import org.apache.camel.spi.UriEndpoint;
@@ -146,4 +147,17 @@ class EndpointSchemaGeneratorMojoTest {
         assertEquals("no-description", headerEmpty.getName());
         assertEquals("Some description about NO_DESCRIPTION.", headerEmpty.getDescription());
     }
+
+    @Test
+    void testEndpointWithHeaderClassHierarchy() {
+        mojo.addEndpointHeaders(model, SomeEndpointWithHeaderClassHierarchy.class.getAnnotation(UriEndpoint.class), "some");
+        List<EndpointHeaderModel> endpointHeaders = model.getEndpointHeaders();
+        assertEquals(2, endpointHeaders.size());
+        EndpointHeaderModel header = endpointHeaders.get(0);
+        assertEquals("header", header.getKind());
+        assertEquals("KEY_FROM_SPECIFIC", header.getName());
+        header = endpointHeaders.get(1);
+        assertEquals("header", header.getKind());
+        assertEquals("KEY_FROM_COMMON", header.getName());
+    }
 }
diff --git a/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/endpoint/SomeCommonConstants.java b/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/endpoint/SomeCommonConstants.java
new file mode 100644
index 0000000..577acff
--- /dev/null
+++ b/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/endpoint/SomeCommonConstants.java
@@ -0,0 +1,28 @@
+/*
+ * 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.packaging.endpoint;
+
+import org.apache.camel.spi.Metadata;
+
+public class SomeCommonConstants {
+
+    @Metadata
+    static final String KEY_FROM_COMMON = "KEY_FROM_COMMON";
+
+    protected SomeCommonConstants() {
+    }
+}
diff --git a/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/endpoint/SomeEndpointWithHeaderClassHierarchy.java b/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/endpoint/SomeEndpointWithHeaderClassHierarchy.java
new file mode 100644
index 0000000..414b917
--- /dev/null
+++ b/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/endpoint/SomeEndpointWithHeaderClassHierarchy.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.packaging.endpoint;
+
+import org.apache.camel.spi.UriEndpoint;
+
+@UriEndpoint(scheme = "some", syntax = "some", title = "some", headersClass = SomeSpecificConstants.class)
+public class SomeEndpointWithHeaderClassHierarchy {
+}
diff --git a/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/endpoint/SomeSpecificConstants.java b/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/endpoint/SomeSpecificConstants.java
new file mode 100644
index 0000000..132de65
--- /dev/null
+++ b/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/endpoint/SomeSpecificConstants.java
@@ -0,0 +1,28 @@
+/*
+ * 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.packaging.endpoint;
+
+import org.apache.camel.spi.Metadata;
+
+public final class SomeSpecificConstants extends SomeCommonConstants {
+
+    @Metadata
+    static final String KEY_FROM_SPECIFIC = "KEY_FROM_SPECIFIC";
+
+    private SomeSpecificConstants() {
+    }
+}