You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2023/12/05 13:48:28 UTC

(camel-quarkus) branch camel-main updated: Fix Spring 6.1.x native support

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

jamesnetherton pushed a commit to branch camel-main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


The following commit(s) were added to refs/heads/camel-main by this push:
     new 72ff45d11e Fix Spring 6.1.x native support
72ff45d11e is described below

commit 72ff45d11edc96c7eadee188c6da858be8731cb8
Author: James Netherton <ja...@gmail.com>
AuthorDate: Tue Dec 5 13:47:39 2023 +0000

    Fix Spring 6.1.x native support
---
 .../spring/deployment/SpringKotlinProcessor.java   |  5 +++
 .../spring/graal/SpringKotlinSubstitutions.java    | 42 ++++++++++++++++++++++
 extensions-support/spring/shade/beans/pom.xml      |  1 -
 integration-tests/jta/pom.xml                      |  5 ++-
 integration-tests/spring-rabbitmq/pom.xml          |  5 ++-
 integration-tests/sql/pom.xml                      |  5 ++-
 6 files changed, 53 insertions(+), 10 deletions(-)

diff --git a/extensions-support/spring/deployment/src/main/java/org/apache/camel/quarkus/support/spring/deployment/SpringKotlinProcessor.java b/extensions-support/spring/deployment/src/main/java/org/apache/camel/quarkus/support/spring/deployment/SpringKotlinProcessor.java
index 6ed096e288..10f1f5a52d 100644
--- a/extensions-support/spring/deployment/src/main/java/org/apache/camel/quarkus/support/spring/deployment/SpringKotlinProcessor.java
+++ b/extensions-support/spring/deployment/src/main/java/org/apache/camel/quarkus/support/spring/deployment/SpringKotlinProcessor.java
@@ -47,6 +47,11 @@ public class SpringKotlinProcessor {
         createClass(generatedClass, "kotlin.reflect.KParameter", Object.class.getName(), true);
         createClass(generatedClass, "kotlin.reflect.KCallable", Object.class.getName(), false);
         createClass(generatedClass, "kotlin.reflect.KFunction", "kotlin.reflect.KCallable", false);
+        createClass(generatedClass, "kotlin.reflect.KAnnotatedElement", Object.class.getName(), false);
+        createClass(generatedClass, "kotlin.reflect.KClass", "kotlin.reflect.KAnnotatedElement", false);
+        createClass(generatedClass, "kotlin.text.Regex", Object.class.getName(), false);
+        createClass(generatedClass, "kotlin.coroutines.CoroutineContext$Key", Object.class.getName(), false);
+        createClass(generatedClass, "kotlinx.coroutines.Job$Key", "kotlin.coroutines.CoroutineContext$Key", false);
     }
 
     private boolean isKotlinStdlibAvailable(ApplicationModel applicationModel) {
diff --git a/extensions-support/spring/runtime/src/main/java/org/apache/camel/quarkus/support/spring/graal/SpringKotlinSubstitutions.java b/extensions-support/spring/runtime/src/main/java/org/apache/camel/quarkus/support/spring/graal/SpringKotlinSubstitutions.java
index 51bed4412f..c72e4111c4 100644
--- a/extensions-support/spring/runtime/src/main/java/org/apache/camel/quarkus/support/spring/graal/SpringKotlinSubstitutions.java
+++ b/extensions-support/spring/runtime/src/main/java/org/apache/camel/quarkus/support/spring/graal/SpringKotlinSubstitutions.java
@@ -16,8 +16,11 @@
  */
 package org.apache.camel.quarkus.support.spring.graal;
 
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
+import java.util.function.BooleanSupplier;
 
 import com.oracle.svm.core.annotate.Delete;
 import com.oracle.svm.core.annotate.Substitute;
@@ -44,6 +47,11 @@ final class SubstituteKotlinDetector {
     public static boolean isKotlinType(Class<?> clazz) {
         return false;
     }
+
+    @Substitute
+    public static boolean isSuspendingFunction(Method method) {
+        return false;
+    }
 }
 
 @TargetClass(className = "org.springframework.core.KotlinReflectionParameterNameDiscoverer")
@@ -51,6 +59,20 @@ final class SubstituteKotlinDetector {
 final class SubstituteKotlinReflectionParameterNameDiscoverer {
 }
 
+@TargetClass(className = "org.springframework.beans.BeanUtils$KotlinDelegate")
+final class SubstituteBeanUtilsKotlinDelegate {
+    @Substitute
+    public static <T> Constructor<T> findPrimaryConstructor(Class<T> clazz) {
+        throw new UnsupportedOperationException("Kotlin is not supported");
+    }
+
+    @Substitute
+    public static <T> T instantiateClass(Constructor<T> ctor, Object... args)
+            throws IllegalAccessException, InvocationTargetException, InstantiationException {
+        throw new UnsupportedOperationException("Kotlin is not supported");
+    }
+}
+
 @TargetClass(className = "org.springframework.core.MethodParameter$KotlinDelegate")
 final class SubstituteMethodParameterKotlinDelegate {
     @Substitute
@@ -68,3 +90,23 @@ final class SubstituteMethodParameterKotlinDelegate {
         throw new UnsupportedOperationException("Kotlin is not supported");
     }
 }
+
+@TargetClass(className = "org.springframework.aop.support.AopUtils$KotlinDelegate", onlyWith = SpringAopPresent.class)
+final class SubstituteAopUtilsKotlinDelegate {
+    @Substitute
+    public static Object invokeSuspendingFunction(Method method, Object target, Object... args) {
+        throw new UnsupportedOperationException("Kotlin is not supported");
+    }
+}
+
+final class SpringAopPresent implements BooleanSupplier {
+    @Override
+    public boolean getAsBoolean() {
+        try {
+            Thread.currentThread().getContextClassLoader().loadClass("org.springframework.aop.support.AopUtils");
+            return true;
+        } catch (ClassNotFoundException e) {
+            return false;
+        }
+    }
+}
diff --git a/extensions-support/spring/shade/beans/pom.xml b/extensions-support/spring/shade/beans/pom.xml
index c774af7104..7f067ee6ed 100644
--- a/extensions-support/spring/shade/beans/pom.xml
+++ b/extensions-support/spring/shade/beans/pom.xml
@@ -70,7 +70,6 @@
                                     </includes>
                                     <excludes>
                                         <exclude>org/springframework/beans/factory/groovy/**</exclude>
-                                        <exclude>org/springframework/beans/BeanUtils$Kotlin*</exclude>
                                     </excludes>
                                 </filter>
                             </filters>
diff --git a/integration-tests/jta/pom.xml b/integration-tests/jta/pom.xml
index 5697734c98..017bb3d6a8 100644
--- a/integration-tests/jta/pom.xml
+++ b/integration-tests/jta/pom.xml
@@ -88,8 +88,7 @@
 
 
     <profiles>
-        <!-- https://github.com/apache/camel-quarkus/issues/5583 -->
-        <!--<profile>
+        <profile>
             <id>native</id>
             <activation>
                 <property>
@@ -115,7 +114,7 @@
                     </plugin>
                 </plugins>
             </build>
-        </profile> -->
+        </profile>
         <profile>
             <id>virtualDependencies</id>
             <activation>
diff --git a/integration-tests/spring-rabbitmq/pom.xml b/integration-tests/spring-rabbitmq/pom.xml
index 6ba4b1b432..764b7f4640 100644
--- a/integration-tests/spring-rabbitmq/pom.xml
+++ b/integration-tests/spring-rabbitmq/pom.xml
@@ -79,8 +79,7 @@
     </dependencies>
 
     <profiles>
-        <!-- https://github.com/apache/camel-quarkus/issues/5583 -->
-        <!--<profile>
+        <profile>
             <id>native</id>
             <activation>
                 <property>
@@ -106,7 +105,7 @@
                     </plugin>
                 </plugins>
             </build>
-        </profile> -->
+        </profile>
         <profile>
             <id>virtualDependencies</id>
             <activation>
diff --git a/integration-tests/sql/pom.xml b/integration-tests/sql/pom.xml
index 9587bedf78..01ec2d33ce 100644
--- a/integration-tests/sql/pom.xml
+++ b/integration-tests/sql/pom.xml
@@ -105,8 +105,7 @@
 
 
     <profiles>
-        <!-- https://github.com/apache/camel-quarkus/issues/5583 -->
-        <!--<profile>
+        <profile>
             <id>native</id>
             <activation>
                 <property>
@@ -137,7 +136,7 @@
                     </plugin>
                 </plugins>
             </build>
-        </profile> -->
+        </profile>
         <profile>
             <id>virtualDependencies</id>
             <activation>