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 2023/02/20 16:14:10 UTC

[camel-quarkus] branch 4393/get-rid-of-report-unsupported-elements-at-runtime updated (7a8ff7dbea -> 410ce46911)

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

nfilotto pushed a change to branch 4393/get-rid-of-report-unsupported-elements-at-runtime
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


 discard 7a8ff7dbea Ref #4393: Get rid of --report-unsupported-elements-at-runtime for Groovy DSL
     new 410ce46911 Ref #4393: Groovy DSL - Get rid of --report-unsupported-elements-at-runtime

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   (7a8ff7dbea)
            \
             N -- N -- N   refs/heads/4393/get-rid-of-report-unsupported-elements-at-runtime (410ce46911)

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:
 .../src/main/resources/routes/routes-with-endpoint-dsl.groovy         | 2 +-
 .../src/main/resources/routes/routes-with-error-handler.groovy        | 2 +-
 .../main/resources/routes/routes-with-languages-configuration.groovy  | 4 +---
 .../groovy-dsl/src/main/resources/routes/routes-with-rest.groovy      | 2 +-
 4 files changed, 4 insertions(+), 6 deletions(-)


[camel-quarkus] 01/01: Ref #4393: Groovy DSL - Get rid of --report-unsupported-elements-at-runtime

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

nfilotto pushed a commit to branch 4393/get-rid-of-report-unsupported-elements-at-runtime
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 410ce46911e0e36de461807c2320920afd211ae6
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Mon Feb 20 17:09:02 2023 +0100

    Ref #4393: Groovy DSL - Get rid of --report-unsupported-elements-at-runtime
---
 .../pages/reference/extensions/groovy-dsl.adoc     | 17 ---------
 .../dsl/groovy/deployment/GroovyDslProcessor.java  | 22 ++++++------
 .../runtime/src/main/doc/limitations.adoc          | 17 ---------
 integration-tests/groovy-dsl/pom.xml               | 23 ++----------
 .../quarkus/dsl/groovy/GroovyDslResource.java      | 19 ++++++++++
 .../routes-with-components-configuration.groovy    | 17 +++++----
 .../routes-with-dataformats-configuration.groovy   |  4 +--
 .../routes/routes-with-endpoint-dsl.groovy         |  5 +--
 .../routes/routes-with-error-handler.groovy        |  6 ++--
 .../routes-with-languages-configuration.groovy     | 10 ++++--
 ...onfiguration.groovy => routes-with-rest.groovy} | 42 ++++++++++++++--------
 .../camel/quarkus/dsl/groovy/GroovyDslTest.java    | 22 +++++++++++-
 12 files changed, 109 insertions(+), 95 deletions(-)

diff --git a/docs/modules/ROOT/pages/reference/extensions/groovy-dsl.adoc b/docs/modules/ROOT/pages/reference/extensions/groovy-dsl.adoc
index b5b1d0c9e4..f9c62daa0d 100644
--- a/docs/modules/ROOT/pages/reference/extensions/groovy-dsl.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/groovy-dsl.adoc
@@ -49,20 +49,3 @@ endif::[]
 
 The Groovy extensions are not supported which means that the extensions defined in the Camel project are ignored, more details in https://github.com/apache/camel-quarkus/issues/4384[Groovy DSL - Add support of Groovy extensions issue #4384].
 
-In case of native compilation, for some specific use cases like the following one, it could be needed to add the flag `--report-unsupported-elements-at-runtime` to prevent compilation error of type `DeletedElementException: Unsupported method java.lang.Class.registerNatives() is reachable`.
-
-[source,groovy]
-----
-import org.apache.camel.component.seda.SedaComponent
-
-camel {
-    components {
-        mySeda(SedaComponent) { // <1>
-            // rest of the closure here
-        }
-    }
-}
-// rest of the Groovy script
-----
-<1> Requires the flag `--report-unsupported-elements-at-runtime` to be added to the build command for native compilation.
-
diff --git a/extensions/groovy-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/groovy/deployment/GroovyDslProcessor.java b/extensions/groovy-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/groovy/deployment/GroovyDslProcessor.java
index 739c7221d6..5f23bb77c0 100644
--- a/extensions/groovy-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/groovy/deployment/GroovyDslProcessor.java
+++ b/extensions/groovy-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/groovy/deployment/GroovyDslProcessor.java
@@ -24,7 +24,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
-import java.util.stream.Collectors;
 
 import io.quarkus.deployment.annotations.BuildProducer;
 import io.quarkus.deployment.annotations.BuildStep;
@@ -55,14 +54,17 @@ public class GroovyDslProcessor {
 
     private static final Logger LOG = LoggerFactory.getLogger(GroovyDslProcessor.class);
     private static final String PACKAGE_NAME = "org.apache.camel.quarkus.dsl.groovy.generated";
-    private static final String FILE_FORMAT = "package %s\n" +
-            "%s\n" +
-            "@groovy.transform.InheritConstructors \n" +
-            "class %s extends %s {\n" +
-            "  void configure(){ \n" +
-            "    %s\n" +
-            "  }\n" +
-            "}";
+    private static final String FILE_FORMAT = """
+            package %s
+            %s
+            @groovy.transform.InheritConstructors
+            class %s extends %s {
+              void configure() {
+                %s
+              }
+            }
+            """;
+
     private static final String FEATURE = "camel-groovy-dsl";
 
     @BuildStep
@@ -101,7 +103,7 @@ public class GroovyDslProcessor {
                         .map(ResolvedDependency::getResolvedPaths)
                         .flatMap(PathCollection::stream)
                         .map(Objects::toString)
-                        .collect(Collectors.toList()));
+                        .toList());
         unit.configure(cc);
         unit.compile(Phases.CLASS_GENERATION);
         for (GroovyClass clazz : unit.getClasses()) {
diff --git a/extensions/groovy-dsl/runtime/src/main/doc/limitations.adoc b/extensions/groovy-dsl/runtime/src/main/doc/limitations.adoc
index b1a77c234a..a77743a491 100644
--- a/extensions/groovy-dsl/runtime/src/main/doc/limitations.adoc
+++ b/extensions/groovy-dsl/runtime/src/main/doc/limitations.adoc
@@ -1,18 +1 @@
 The Groovy extensions are not supported which means that the extensions defined in the Camel project are ignored, more details in https://github.com/apache/camel-quarkus/issues/4384[Groovy DSL - Add support of Groovy extensions issue #4384].
-
-In case of native compilation, for some specific use cases like the following one, it could be needed to add the flag `--report-unsupported-elements-at-runtime` to prevent compilation error of type `DeletedElementException: Unsupported method java.lang.Class.registerNatives() is reachable`.
-
-[source,groovy]
-----
-import org.apache.camel.component.seda.SedaComponent
-
-camel {
-    components {
-        mySeda(SedaComponent) { // <1>
-            // rest of the closure here
-        }
-    }
-}
-// rest of the Groovy script
-----
-<1> Requires the flag `--report-unsupported-elements-at-runtime` to be added to the build command for native compilation.
diff --git a/integration-tests/groovy-dsl/pom.xml b/integration-tests/groovy-dsl/pom.xml
index cb0e802a89..07f11a865a 100644
--- a/integration-tests/groovy-dsl/pom.xml
+++ b/integration-tests/groovy-dsl/pom.xml
@@ -39,10 +39,6 @@
             <groupId>org.apache.camel.quarkus</groupId>
             <artifactId>camel-quarkus-direct</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.apache.camel.quarkus</groupId>
-            <artifactId>camel-quarkus-seda</artifactId>
-        </dependency>
         <dependency>
             <groupId>org.apache.camel.quarkus</groupId>
             <artifactId>camel-quarkus-jackson</artifactId>
@@ -53,11 +49,11 @@
         </dependency>
         <dependency>
             <groupId>org.apache.camel.quarkus</groupId>
-            <artifactId>camel-quarkus-timer</artifactId>
+            <artifactId>camel-quarkus-log</artifactId>
         </dependency>
         <dependency>
             <groupId>org.apache.camel.quarkus</groupId>
-            <artifactId>camel-quarkus-log</artifactId>
+            <artifactId>camel-quarkus-rest</artifactId>
         </dependency>
         <dependency>
             <groupId>io.quarkus</groupId>
@@ -159,20 +155,7 @@
                 </dependency>
                 <dependency>
                     <groupId>org.apache.camel.quarkus</groupId>
-                    <artifactId>camel-quarkus-seda-deployment</artifactId>
-                    <version>${project.version}</version>
-                    <type>pom</type>
-                    <scope>test</scope>
-                    <exclusions>
-                        <exclusion>
-                            <groupId>*</groupId>
-                            <artifactId>*</artifactId>
-                        </exclusion>
-                    </exclusions>
-                </dependency>
-                <dependency>
-                    <groupId>org.apache.camel.quarkus</groupId>
-                    <artifactId>camel-quarkus-timer-deployment</artifactId>
+                    <artifactId>camel-quarkus-rest-deployment</artifactId>
                     <version>${project.version}</version>
                     <type>pom</type>
                     <scope>test</scope>
diff --git a/integration-tests/groovy-dsl/src/main/java/org/apache/camel/quarkus/dsl/groovy/GroovyDslResource.java b/integration-tests/groovy-dsl/src/main/java/org/apache/camel/quarkus/dsl/groovy/GroovyDslResource.java
index c0af54f739..b731e15a85 100644
--- a/integration-tests/groovy-dsl/src/main/java/org/apache/camel/quarkus/dsl/groovy/GroovyDslResource.java
+++ b/integration-tests/groovy-dsl/src/main/java/org/apache/camel/quarkus/dsl/groovy/GroovyDslResource.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.quarkus.dsl.groovy;
 
+import java.util.Set;
 import java.util.stream.Collectors;
 
 import jakarta.enterprise.context.ApplicationScoped;
@@ -29,6 +30,7 @@ import jakarta.ws.rs.core.MediaType;
 import org.apache.camel.ExtendedCamelContext;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.Route;
+import org.apache.camel.component.direct.DirectEndpoint;
 import org.apache.camel.dsl.groovy.GroovyRoutesBuilderLoader;
 import org.apache.camel.quarkus.main.CamelMain;
 import org.apache.camel.spi.RoutesBuilderLoader;
@@ -71,6 +73,23 @@ public class GroovyDslResource {
                 .collect(Collectors.joining(","));
     }
 
+    @GET
+    @Path("/main/successful/routes")
+    @Consumes(MediaType.TEXT_PLAIN)
+    @Produces(MediaType.TEXT_PLAIN)
+    public int successfulRoutes() {
+        int successful = 0;
+        Set<String> excluded = Set.of("my-groovy-route", "routes-with-rest-dsl-get", "routes-with-rest-dsl-post");
+        for (Route route : main.getCamelContext().getRoutes()) {
+            String name = route.getRouteId();
+            if (route.getEndpoint() instanceof DirectEndpoint && !excluded.contains(name)
+                    && producerTemplate.requestBody(route.getEndpoint(), "", Boolean.class) == Boolean.TRUE) {
+                successful++;
+            }
+        }
+        return successful;
+    }
+
     @POST
     @Path("/hello")
     @Consumes(MediaType.TEXT_PLAIN)
diff --git a/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-components-configuration.groovy b/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-components-configuration.groovy
index c32538db86..276b1246d1 100644
--- a/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-components-configuration.groovy
+++ b/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-components-configuration.groovy
@@ -14,20 +14,23 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+import org.apache.camel.component.direct.DirectComponent
 
 camel {
     components {
-        seda {
+        direct {
             // set value as method
-            queueSize 1234
-
-            // set value as property
-            concurrentConsumers = 12
+            timeout 1234
+        }
+        myDirect(DirectComponent) {
+            // set value as method
+            timeout = 4321
         }
     }
 }
 
 
-from('timer:tick')
+
+from('direct:routes-with-components-configuration')
     .id('routes-with-components-configuration')
-    .to('log:info')
+    .setBody(simple('${camelContext.getComponent("myDirect")} != null', Boolean.class))
diff --git a/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-dataformats-configuration.groovy b/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-dataformats-configuration.groovy
index 127dba3550..3e2788cbaf 100644
--- a/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-dataformats-configuration.groovy
+++ b/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-dataformats-configuration.groovy
@@ -31,6 +31,6 @@ camel {
 }
 
 
-from('timer:tick')
+from('direct:routes-with-dataformats-configuration')
     .id('routes-with-dataformats-configuration')
-    .to('log:info')
+    .setBody(simple('${ref:my-jackson} != null', Boolean.class))
diff --git a/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-endpoint-dsl.groovy b/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-endpoint-dsl.groovy
index 18f2b7b9ce..269ccd7e3a 100644
--- a/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-endpoint-dsl.groovy
+++ b/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-endpoint-dsl.groovy
@@ -14,9 +14,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-def f = timer('tick').period('1s')
+def f = direct("routes-with-endpoint-dsl").advanced().synchronous(true)
 def t = log('info')
 
 from(f)
     .id('routes-with-endpoint-dsl')
-    .to(t)
\ No newline at end of file
+    .setBody().constant("true")
+    .to(t)
diff --git a/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-error-handler.groovy b/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-error-handler.groovy
index 406269a016..ecf90a4949 100644
--- a/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-error-handler.groovy
+++ b/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-error-handler.groovy
@@ -19,6 +19,8 @@ onException(IllegalArgumentException.class)
     .id('my-on-exception')
     .to('log:exception')
 
-from('timer:tick')
+from('direct:routes-with-error-handler')
     .id('routes-with-error-handler')
-    .to('log:info')
\ No newline at end of file
+    .setHeader("SomeHeader", constant("SomeHeaderValue"))
+    .filter().simple('${header.SomeHeader} == "SomeHeaderValue"')
+    .setBody().constant("true")
diff --git a/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-languages-configuration.groovy b/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-languages-configuration.groovy
index 144249b8ae..11039543b6 100644
--- a/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-languages-configuration.groovy
+++ b/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-languages-configuration.groovy
@@ -14,6 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+import org.apache.camel.language.bean.BeanLanguage
 
 camel {
     languages {
@@ -21,10 +22,13 @@ camel {
             beanType = String.class
             method = "toUpperCase"
         }
+        myBean(BeanLanguage) {
+            beanType = String.class
+            method = "toLowerCase"
+        }
     }
 }
 
-
-from('timer:tick')
+from('direct:routes-with-languages-configuration')
     .id('routes-with-languages-configuration')
-    .to('log:info')
\ No newline at end of file
+    .setBody(simple('${ref:my-bean} != null', Boolean.class))
diff --git a/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-dataformats-configuration.groovy b/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-rest.groovy
similarity index 50%
copy from integration-tests/groovy-dsl/src/main/resources/routes/routes-with-dataformats-configuration.groovy
copy to integration-tests/groovy-dsl/src/main/resources/routes/routes-with-rest.groovy
index 127dba3550..ab12f3f457 100644
--- a/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-dataformats-configuration.groovy
+++ b/integration-tests/groovy-dsl/src/main/resources/routes/routes-with-rest.groovy
@@ -14,23 +14,37 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+rest {
+    configuration {
+        contextPath = "/root"
+    }
 
-import org.apache.camel.component.jackson.JacksonDataFormat
-
-camel {
-    dataFormats {
-        dataFormat("jackson") {
-            unmarshalType = Map.class
-            prettyPrint = true
-        }
-        dataFormat("my-jackson", JacksonDataFormat) {
-            unmarshalType = String.class
-            prettyPrint = false
+    path("/my/path") {
+        get("/get") {
+            id("routes-with-rest-get")
+            produces("text/plain")
+            to("direct:get")
         }
     }
+
+    post {
+        id("routes-with-rest-post")
+        path("/post")
+        consumes("text/plain")
+        produces("text/plain")
+        to("direct:post")
+    }
 }
 
+from('direct:get')
+    .id("routes-with-rest-dsl-get")
+    .transform().constant("Hello World")
+from('direct:post')
+    .id("routes-with-rest-dsl-post")
+    .setBody().simple('Hello ${body}')
 
-from('timer:tick')
-    .id('routes-with-dataformats-configuration')
-    .to('log:info')
+from("direct:routes-with-rest")
+    .id("routes-with-rest")
+    .setHeader("AnotherHeader", constant("AnotherHeaderValue"))
+    .filter().simple('${header.AnotherHeader} == "AnotherHeaderValue"')
+    .setBody().constant("true")
diff --git a/integration-tests/groovy-dsl/src/test/java/org/apache/camel/quarkus/dsl/groovy/GroovyDslTest.java b/integration-tests/groovy-dsl/src/test/java/org/apache/camel/quarkus/dsl/groovy/GroovyDslTest.java
index 87e065f256..fdc6a4faf4 100644
--- a/integration-tests/groovy-dsl/src/test/java/org/apache/camel/quarkus/dsl/groovy/GroovyDslTest.java
+++ b/integration-tests/groovy-dsl/src/test/java/org/apache/camel/quarkus/dsl/groovy/GroovyDslTest.java
@@ -54,6 +54,26 @@ class GroovyDslTest {
                 .then()
                 .statusCode(200)
                 .body(CoreMatchers.is(
-                        "my-groovy-route,routes-with-components-configuration,routes-with-dataformats-configuration,routes-with-endpoint-dsl,routes-with-error-handler,routes-with-languages-configuration"));
+                        "my-groovy-route,routes-with-components-configuration,routes-with-dataformats-configuration,routes-with-endpoint-dsl,routes-with-error-handler,routes-with-languages-configuration,routes-with-rest,routes-with-rest-dsl-get,routes-with-rest-dsl-post,routes-with-rest-get,routes-with-rest-post"));
+        RestAssured.given()
+                .get("/groovy-dsl/main/successful/routes")
+                .then()
+                .statusCode(200)
+                .body(CoreMatchers.is("5"));
+    }
+
+    @Test
+    void testRestEndpoints() {
+        RestAssured.given()
+                .get("/root/my/path/get")
+                .then()
+                .statusCode(200)
+                .body(CoreMatchers.is("Hello World"));
+        RestAssured.given()
+                .body("Will")
+                .post("/root/post")
+                .then()
+                .statusCode(200)
+                .body(CoreMatchers.is("Hello Will"));
     }
 }