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/07/07 13:20:43 UTC

[camel-quarkus] branch 5056/replace-classProxy-v2 created (now 0a1f0e8d03)

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

nfilotto pushed a change to branch 5056/replace-classProxy-v2
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


      at 0a1f0e8d03 Ref #5056: Improve the replacement of RecorderContext#classProxy

This branch includes the following new commits:

     new 0a1f0e8d03 Ref #5056: Improve the replacement of RecorderContext#classProxy

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.



[camel-quarkus] 01/01: Ref #5056: Improve the replacement of RecorderContext#classProxy

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

nfilotto pushed a commit to branch 5056/replace-classProxy-v2
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 0a1f0e8d0305b1714f6d31dcbe2c817b36780f6a
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Fri Jul 7 15:20:09 2023 +0200

    Ref #5056: Improve the replacement of RecorderContext#classProxy
---
 .../language/runtime/LanguageSupportRecorder.java  | 28 ----------------------
 .../groovy/deployment/GroovyProcessor.java         |  6 ++---
 .../groovy/runtime/GroovyExpressionRecorder.java   |  5 ++--
 .../component/joor/deployment/JoorProcessor.java   | 10 ++++----
 .../joor/runtime/JoorExpressionRecorder.java       | 18 +++++++++-----
 5 files changed, 21 insertions(+), 46 deletions(-)

diff --git a/extensions-support/language/runtime/src/main/java/org/apache/camel/quarkus/support/language/runtime/LanguageSupportRecorder.java b/extensions-support/language/runtime/src/main/java/org/apache/camel/quarkus/support/language/runtime/LanguageSupportRecorder.java
deleted file mode 100644
index 41b9796190..0000000000
--- a/extensions-support/language/runtime/src/main/java/org/apache/camel/quarkus/support/language/runtime/LanguageSupportRecorder.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.quarkus.support.language.runtime;
-
-import io.quarkus.runtime.RuntimeValue;
-import io.quarkus.runtime.annotations.Recorder;
-
-@Recorder
-public class LanguageSupportRecorder {
-
-    public RuntimeValue<Class<?>> loadClass(String name) throws ClassNotFoundException {
-        return new RuntimeValue<>(Class.forName(name, true, Thread.currentThread().getContextClassLoader()));
-    }
-}
diff --git a/extensions/groovy/deployment/src/main/java/org/apache/camel/quarkus/component/groovy/deployment/GroovyProcessor.java b/extensions/groovy/deployment/src/main/java/org/apache/camel/quarkus/component/groovy/deployment/GroovyProcessor.java
index 183200f5a0..53d5324d80 100644
--- a/extensions/groovy/deployment/src/main/java/org/apache/camel/quarkus/component/groovy/deployment/GroovyProcessor.java
+++ b/extensions/groovy/deployment/src/main/java/org/apache/camel/quarkus/component/groovy/deployment/GroovyProcessor.java
@@ -41,7 +41,6 @@ import org.apache.camel.quarkus.support.language.deployment.ExpressionBuildItem;
 import org.apache.camel.quarkus.support.language.deployment.ExpressionExtractionResultBuildItem;
 import org.apache.camel.quarkus.support.language.deployment.ScriptBuildItem;
 import org.apache.camel.quarkus.support.language.runtime.ExpressionUID;
-import org.apache.camel.quarkus.support.language.runtime.LanguageSupportRecorder;
 import org.apache.camel.quarkus.support.language.runtime.ScriptUID;
 import org.codehaus.groovy.control.CompilationUnit;
 import org.codehaus.groovy.control.CompilerConfiguration;
@@ -149,9 +148,8 @@ class GroovyProcessor {
     @BuildStep(onlyIf = NativeBuild.class)
     CamelBeanBuildItem configureLanguage(
             GroovyExpressionRecorder recorder,
-            LanguageSupportRecorder languageRecorder,
             ExpressionExtractionResultBuildItem result,
-            List<GroovyExpressionSourceBuildItem> sources) throws ClassNotFoundException {
+            List<GroovyExpressionSourceBuildItem> sources) {
 
         if (result.isSuccess() && !sources.isEmpty()) {
             RuntimeValue<GroovyLanguage.Builder> builder = recorder.languageBuilder();
@@ -159,7 +157,7 @@ class GroovyProcessor {
                 recorder.addScript(
                         builder,
                         source.getOriginalCode(),
-                        languageRecorder.loadClass(source.getClassName()));
+                        source.getClassName());
             }
             final RuntimeValue<GroovyLanguage> language = recorder.languageNewInstance(builder);
             return new CamelBeanBuildItem("groovy", GroovyLanguage.class.getName(), language);
diff --git a/extensions/groovy/runtime/src/main/java/org/apache/camel/quarkus/component/groovy/runtime/GroovyExpressionRecorder.java b/extensions/groovy/runtime/src/main/java/org/apache/camel/quarkus/component/groovy/runtime/GroovyExpressionRecorder.java
index e0ee300344..756a1812f3 100644
--- a/extensions/groovy/runtime/src/main/java/org/apache/camel/quarkus/component/groovy/runtime/GroovyExpressionRecorder.java
+++ b/extensions/groovy/runtime/src/main/java/org/apache/camel/quarkus/component/groovy/runtime/GroovyExpressionRecorder.java
@@ -29,9 +29,10 @@ public class GroovyExpressionRecorder {
     }
 
     @SuppressWarnings("unchecked")
-    public void addScript(RuntimeValue<GroovyLanguage.Builder> builder, String content, RuntimeValue<Class<?>> clazz) {
+    public void addScript(RuntimeValue<GroovyLanguage.Builder> builder, String content, String className) {
         try {
-            builder.getValue().addScript(content, (Class<Script>) clazz.getValue());
+            builder.getValue().addScript(content,
+                    (Class<Script>) Class.forName(className, true, Thread.currentThread().getContextClassLoader()));
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
diff --git a/extensions/joor/deployment/src/main/java/org/apache/camel/quarkus/component/joor/deployment/JoorProcessor.java b/extensions/joor/deployment/src/main/java/org/apache/camel/quarkus/component/joor/deployment/JoorProcessor.java
index a6378ab77a..03ef3755a7 100644
--- a/extensions/joor/deployment/src/main/java/org/apache/camel/quarkus/component/joor/deployment/JoorProcessor.java
+++ b/extensions/joor/deployment/src/main/java/org/apache/camel/quarkus/component/joor/deployment/JoorProcessor.java
@@ -53,7 +53,6 @@ import org.apache.camel.quarkus.support.language.deployment.ExpressionBuildItem;
 import org.apache.camel.quarkus.support.language.deployment.ExpressionExtractionResultBuildItem;
 import org.apache.camel.quarkus.support.language.deployment.ScriptBuildItem;
 import org.apache.camel.quarkus.support.language.runtime.ExpressionUID;
-import org.apache.camel.quarkus.support.language.runtime.LanguageSupportRecorder;
 import org.apache.camel.quarkus.support.language.runtime.ScriptUID;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -158,10 +157,9 @@ class JoorProcessor {
     CamelBeanBuildItem configureLanguage(
             JoorExpressionConfig config,
             JoorExpressionRecorder recorder,
-            LanguageSupportRecorder languageRecorder,
             CamelContextBuildItem context,
             ExpressionExtractionResultBuildItem result,
-            List<JoorExpressionSourceBuildItem> sources) throws ClassNotFoundException {
+            List<JoorExpressionSourceBuildItem> sources) {
 
         if (result.isSuccess() && !sources.isEmpty()) {
             final RuntimeValue<JoorExpressionCompiler.Builder> expressionCompilerBuilder = recorder
@@ -176,13 +174,13 @@ class JoorProcessor {
                             expressionScriptingCompilerBuilder,
                             camelContext,
                             source.getId(),
-                            languageRecorder.loadClass(source.getClassName()));
+                            source.getClassName());
                 } else {
                     recorder.addExpression(
                             expressionCompilerBuilder,
                             camelContext,
                             source.getId(),
-                            languageRecorder.loadClass(source.getClassName()));
+                            source.getClassName());
                 }
             }
             final RuntimeValue<JoorLanguage> language = recorder.languageNewInstance(config, expressionCompilerBuilder,
@@ -191,7 +189,7 @@ class JoorProcessor {
             if (config.resultType.isPresent()) {
                 recorder.setResultType(
                         language,
-                        languageRecorder.loadClass(config.resultType.get()));
+                        config.resultType.get());
             }
 
             return new CamelBeanBuildItem("joor", JoorLanguage.class.getName(), language);
diff --git a/extensions/joor/runtime/src/main/java/org/apache/camel/quarkus/component/joor/runtime/JoorExpressionRecorder.java b/extensions/joor/runtime/src/main/java/org/apache/camel/quarkus/component/joor/runtime/JoorExpressionRecorder.java
index 62d47febce..21a5c71e36 100644
--- a/extensions/joor/runtime/src/main/java/org/apache/camel/quarkus/component/joor/runtime/JoorExpressionRecorder.java
+++ b/extensions/joor/runtime/src/main/java/org/apache/camel/quarkus/component/joor/runtime/JoorExpressionRecorder.java
@@ -36,8 +36,12 @@ public class JoorExpressionRecorder {
         return language;
     }
 
-    public void setResultType(RuntimeValue<JoorLanguage> language, RuntimeValue<Class<?>> resultType) {
-        language.getValue().setResultType(resultType.getValue());
+    public void setResultType(RuntimeValue<JoorLanguage> language, String className) {
+        try {
+            language.getValue().setResultType(Class.forName(className, true, Thread.currentThread().getContextClassLoader()));
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
     }
 
     public RuntimeValue<JoorExpressionCompiler.Builder> expressionCompilerBuilder() {
@@ -49,20 +53,22 @@ public class JoorExpressionRecorder {
     }
 
     public void addExpression(RuntimeValue<JoorExpressionCompiler.Builder> builder, RuntimeValue<CamelContext> ctx, String id,
-            RuntimeValue<Class<?>> clazz) {
+            String className) {
         try {
             builder.getValue().addExpression(id,
-                    (JoorMethod) clazz.getValue().getConstructor(CamelContext.class).newInstance(ctx.getValue()));
+                    (JoorMethod) Class.forName(className, true, Thread.currentThread().getContextClassLoader())
+                            .getConstructor(CamelContext.class).newInstance(ctx.getValue()));
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
     }
 
     public void addScript(RuntimeValue<JoorExpressionScriptingCompiler.Builder> builder, RuntimeValue<CamelContext> ctx,
-            String id, RuntimeValue<Class<?>> clazz) {
+            String id, String className) {
         try {
             builder.getValue().addScript(id,
-                    (JoorScriptingMethod) clazz.getValue().getConstructor(CamelContext.class).newInstance(ctx.getValue()));
+                    (JoorScriptingMethod) Class.forName(className, true, Thread.currentThread().getContextClassLoader())
+                            .getConstructor(CamelContext.class).newInstance(ctx.getValue()));
         } catch (Exception e) {
             throw new RuntimeException(e);
         }