You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by st...@apache.org on 2022/07/09 17:50:20 UTC

[deltaspike] branch master updated (236dce67 -> b7c4f46c)

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

struberg pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/deltaspike.git


    from 236dce67 DELTASPIKE-1434 - Adds relocation pattern for javax.persistence
     new 12e2ae84 Allow to pass properties to Weld
     new e5c3f1df Changing key value to be `Object`, not `String`
     new b7c4f46c DELTASPIKE-1455 call setProperties via reflection

The 3 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:
 .../cdise/weld/WeldContainerControl.java           | 72 +++++++++++++++++++++-
 .../apache/deltaspike/core/util/ClassUtils.java    | 28 ++++++++-
 2 files changed, 95 insertions(+), 5 deletions(-)


[deltaspike] 02/03: Changing key value to be `Object`, not `String`

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

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

commit e5c3f1dfbfd29eac4377cfbeb72fa02d6f082ef9
Author: Krzysztof Wolny <k....@gmail.com>
AuthorDate: Thu Jun 2 15:20:41 2022 +0200

    Changing key value to be `Object`, not `String`
---
 .../java/org/apache/deltaspike/cdise/weld/WeldContainerControl.java     | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContainerControl.java b/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContainerControl.java
index 98d41fd5..10578294 100644
--- a/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContainerControl.java
+++ b/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContainerControl.java
@@ -152,7 +152,7 @@ public class WeldContainerControl implements CdiContainer
         return map.entrySet().stream()
                 .collect(Collectors.toMap(
                         entry -> String.valueOf(entry.getKey()),
-                        entry -> String.valueOf(entry.getValue())
+                        Map.Entry::getValue
                 ));
     }
 


[deltaspike] 01/03: Allow to pass properties to Weld

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

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

commit 12e2ae84840c8cd15edd3c6186587a51518bb65d
Author: Krzysztof Wolny <k....@gmail.com>
AuthorDate: Thu Jun 2 15:13:13 2022 +0200

    Allow to pass properties to Weld
---
 .../deltaspike/cdise/weld/WeldContainerControl.java      | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContainerControl.java b/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContainerControl.java
index ac114f33..98d41fd5 100644
--- a/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContainerControl.java
+++ b/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContainerControl.java
@@ -32,6 +32,7 @@ import javax.enterprise.inject.spi.BeanManager;
 import java.util.Map;
 import java.util.Set;
 import java.util.logging.Logger;
+import java.util.stream.Collectors;
 
 import javax.enterprise.context.ConversationScoped;
 import javax.enterprise.context.RequestScoped;
@@ -75,9 +76,9 @@ public class WeldContainerControl implements CdiContainer
     @Override
     public void boot(Map<?, ?> properties)
     {
-        // no configuration yet. Perform default boot
-
-        boot();
+        weld = new Weld();
+        weld.setProperties(convertProperties(properties));
+        weldContainer = weld.initialize();
     }
 
     @Override
@@ -146,4 +147,13 @@ public class WeldContainerControl implements CdiContainer
     {
         return "WeldContainerControl [Weld " + Formats.version(Container.class.getPackage()) + ']';
     }
+    
+    private static Map<String, Object> convertProperties(final Map<?, ?> map) {
+        return map.entrySet().stream()
+                .collect(Collectors.toMap(
+                        entry -> String.valueOf(entry.getKey()),
+                        entry -> String.valueOf(entry.getValue())
+                ));
+    }
+
 }


[deltaspike] 03/03: DELTASPIKE-1455 call setProperties via reflection

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

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

commit b7c4f46c1ef893d37f02ca97ef5b5d4bce93e24a
Author: Mark Struberg <st...@apache.org>
AuthorDate: Sat Jul 9 19:46:12 2022 +0200

    DELTASPIKE-1455 call setProperties via reflection
    
    Only Weld3 and beyond has a setProperties method.
    Thus we only support passing properties for those containers and have
    to use reflection to invoke that method.
---
 .../cdise/weld/WeldContainerControl.java           | 62 +++++++++++++++++++++-
 .../apache/deltaspike/core/util/ClassUtils.java    | 28 ++++++++--
 2 files changed, 85 insertions(+), 5 deletions(-)

diff --git a/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContainerControl.java b/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContainerControl.java
index 10578294..ea1157e4 100644
--- a/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContainerControl.java
+++ b/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContainerControl.java
@@ -29,6 +29,8 @@ import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.BeanManager;
 
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.util.Map;
 import java.util.Set;
 import java.util.logging.Logger;
@@ -77,10 +79,65 @@ public class WeldContainerControl implements CdiContainer
     public void boot(Map<?, ?> properties)
     {
         weld = new Weld();
-        weld.setProperties(convertProperties(properties));
+
+        // setProperties only exists from Weld-2.x onwards
+        setProperties(weld, convertProperties(properties));
+
         weldContainer = weld.initialize();
     }
 
+    private void setProperties(Weld weld, Map<String, Object> properties)
+    {
+        if (properties == null || properties.isEmpty())
+        {
+            return;
+        }
+
+        Method setPropertiesMethod = extractMethod(Weld.class, "setProperties", Map.class);
+        if (setPropertiesMethod != null)
+        {
+            if (!setPropertiesMethod.isAccessible())
+            {
+                setPropertiesMethod.setAccessible(true);
+            }
+
+            try
+            {
+                setPropertiesMethod.invoke(weld, properties);
+            }
+            catch (IllegalAccessException | InvocationTargetException e)
+            {
+                throw new RuntimeException(e);
+            }
+        }
+        else
+        {
+            throw new IllegalStateException("No setProperties method available on this version of Weld!");
+        }
+    }
+
+    /**
+     * Extract a method with the given name and parameterTypes.
+     * Return {@code null} if no such visible method exists on the given class.
+     *
+     * @param clazz
+     * @param methodName
+     * @param parameterTypes
+     * @return
+     */
+    private static Method extractMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes)
+    {
+        try
+        {
+            return clazz != null ? clazz.getMethod(methodName, parameterTypes) : null;
+        }
+        catch (NoSuchMethodException e)
+        {
+            return null;
+        }
+    }
+
+
     @Override
     public synchronized  void shutdown()
     {
@@ -148,7 +205,8 @@ public class WeldContainerControl implements CdiContainer
         return "WeldContainerControl [Weld " + Formats.version(Container.class.getPackage()) + ']';
     }
     
-    private static Map<String, Object> convertProperties(final Map<?, ?> map) {
+    private static Map<String, Object> convertProperties(final Map<?, ?> map)
+    {
         return map.entrySet().stream()
                 .collect(Collectors.toMap(
                         entry -> String.valueOf(entry.getKey()),
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassUtils.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassUtils.java
index 9347900c..670aad6d 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassUtils.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassUtils.java
@@ -31,9 +31,10 @@ import java.util.jar.Attributes;
 import java.net.URL;
 
 /**
- * Util methods for classes, {@link ClassLoader} and {@link Manifest} handling
+ * Util methods for classes, {@link ClassLoader} and {@link Manifest} handling.
+ *
+ * Abstract to not get picked up as CDI bean on old containers.
  */
-//X TODO quite a few of this methods needs merging with Seam Solder and a few can get dropped at all.
 @Typed()
 public abstract class ClassUtils
 {
@@ -398,7 +399,7 @@ public abstract class ClassUtils
         String classLocation = targetClass.getResource(targetClass.getSimpleName() + ".class").toString();
         return classLocation.substring(0, classLocation.indexOf(classFilePath) - 1) + manifestFilePath;
     }
-    
+
     /**
      * Checks if the given class contains a method with the same signature.
      * 
@@ -431,6 +432,27 @@ public abstract class ClassUtils
         }
     }
 
+    /**
+     * Extract a method with the given name and parameterTypes.
+     * Return {@code null} if no such visible method exists on the given class.
+     *
+     * @param clazz
+     * @param methodName
+     * @param parameterTypes
+     * @return
+     */
+    public static Method extractMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes)
+    {
+        try
+        {
+            return clazz != null ? clazz.getMethod(methodName, parameterTypes) : null;
+        }
+        catch (NoSuchMethodException e)
+        {
+            return null;
+        }
+    }
+
     /**
      * Checks if the given class has a method with the same signature, taking in to account generic types
      * @param targetClass