You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@batchee.apache.org by st...@apache.org on 2015/11/10 12:17:52 UTC

[2/6] incubator-batchee git commit: BATCHEE-65 added support for CDI-1.1

BATCHEE-65 added support for CDI-1.1

extensions/cdi currently failes with cdi-1.1


Project: http://git-wip-us.apache.org/repos/asf/incubator-batchee/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-batchee/commit/b0bf6a10
Tree: http://git-wip-us.apache.org/repos/asf/incubator-batchee/tree/b0bf6a10
Diff: http://git-wip-us.apache.org/repos/asf/incubator-batchee/diff/b0bf6a10

Branch: refs/heads/master
Commit: b0bf6a1003f87f1a0a046f940d0a0d16c4dd9482
Parents: a212f4f
Author: Reinhard Sandtner <rs...@apache.org>
Authored: Fri May 22 23:16:08 2015 +0200
Committer: Reinhard Sandtner <rs...@apache.org>
Committed: Mon Nov 9 23:20:38 2015 +0100

----------------------------------------------------------------------
 extensions/cdi/pom.xml                          | 72 +++++++++++++++++---
 .../cdi/testng/CdiContainerLifecycle.java       | 12 ++--
 extensions/pom.xml                              | 28 ++++++++
 jbatch/pom.xml                                  | 57 +++++++++++++---
 .../cdi/BatchCDIInjectionExtension.java         | 56 +++++++++++++--
 pom.xml                                         |  6 ++
 6 files changed, 199 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/b0bf6a10/extensions/cdi/pom.xml
----------------------------------------------------------------------
diff --git a/extensions/cdi/pom.xml b/extensions/cdi/pom.xml
index 575e770..74c36f1 100644
--- a/extensions/cdi/pom.xml
+++ b/extensions/cdi/pom.xml
@@ -31,26 +31,76 @@
     <dependencies>
         <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
-            <artifactId>geronimo-jcdi_1.0_spec</artifactId>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-servlet_3.0_spec</artifactId>
             <version>1.0</version>
             <scope>test</scope>
         </dependency>
+
         <dependency>
-            <groupId>org.apache.geronimo.specs</groupId>
-            <artifactId>geronimo-interceptor_1.1_spec</artifactId>
-            <version>1.0</version>
+            <groupId>org.apache.deltaspike.cdictrl</groupId>
+            <artifactId>deltaspike-cdictrl-owb</artifactId>
+            <version>1.4.0</version>
             <scope>test</scope>
         </dependency>
+
         <dependency>
-            <groupId>org.apache.openwebbeans.test</groupId>
-            <artifactId>cditest-owb</artifactId>
-            <version>1.2.1</version>
+            <groupId>org.apache.openwebbeans</groupId>
+            <artifactId>openwebbeans-impl</artifactId>
+            <version>${owb.version}</version>
             <scope>test</scope>
         </dependency>
+
     </dependencies>
+
+
+    <profiles>
+        <profile>
+            <id>cdi-1.0</id>
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
+
+            <properties>
+                <owb.version>1.2.1</owb.version>
+            </properties>
+
+            <dependencies>
+                <dependency>
+                    <groupId>org.apache.geronimo.specs</groupId>
+                    <artifactId>geronimo-jcdi_1.0_spec</artifactId>
+                </dependency>
+
+                <dependency>
+                    <groupId>org.apache.geronimo.specs</groupId>
+                    <artifactId>geronimo-interceptor_1.1_spec</artifactId>
+                    <version>1.0</version>
+                    <scope>test</scope>
+                </dependency>
+
+            </dependencies>
+        </profile>
+
+        <profile>
+            <id>cdi-1.1</id>
+
+            <properties>
+                <owb.version>1.6.0-SNAPSHOT</owb.version>
+            </properties>
+
+            <dependencies>
+                <dependency>
+                    <groupId>org.apache.geronimo.specs</groupId>
+                    <artifactId>geronimo-jcdi_1.1_spec</artifactId>
+                </dependency>
+
+                <dependency>
+                    <groupId>org.apache.geronimo.specs</groupId>
+                    <artifactId>geronimo-interceptor_1.2_spec</artifactId>
+                    <version>1.0</version>
+                    <scope>test</scope>
+                </dependency>
+
+            </dependencies>
+        </profile>
+    </profiles>
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/b0bf6a10/extensions/cdi/src/test/java/org/apache/batchee/cdi/testng/CdiContainerLifecycle.java
----------------------------------------------------------------------
diff --git a/extensions/cdi/src/test/java/org/apache/batchee/cdi/testng/CdiContainerLifecycle.java b/extensions/cdi/src/test/java/org/apache/batchee/cdi/testng/CdiContainerLifecycle.java
index 6d7aee3..f06cbcb 100644
--- a/extensions/cdi/src/test/java/org/apache/batchee/cdi/testng/CdiContainerLifecycle.java
+++ b/extensions/cdi/src/test/java/org/apache/batchee/cdi/testng/CdiContainerLifecycle.java
@@ -16,14 +16,14 @@
  */
 package org.apache.batchee.cdi.testng;
 
-import org.apache.webbeans.cditest.CdiTestContainer;
-import org.apache.webbeans.cditest.CdiTestContainerLoader;
+import org.apache.deltaspike.cdise.api.CdiContainer;
+import org.apache.deltaspike.cdise.api.CdiContainerLoader;
 import org.testng.ITestContext;
 import org.testng.ITestListener;
 import org.testng.ITestResult;
 
 public class CdiContainerLifecycle implements ITestListener {
-    private CdiTestContainer container;
+    private CdiContainer container;
 
     @Override
     public void onTestStart(final ITestResult iTestResult) {
@@ -52,9 +52,9 @@ public class CdiContainerLifecycle implements ITestListener {
 
     @Override
     public void onStart(final ITestContext iTestContext) {
-        container = CdiTestContainerLoader.getCdiContainer();
+        container = CdiContainerLoader.getCdiContainer();
         try {
-            container.bootContainer();
+            container.boot();
         } catch (final Exception e) {
             throw new RuntimeException(e);
         }
@@ -63,7 +63,7 @@ public class CdiContainerLifecycle implements ITestListener {
     @Override
     public void onFinish(final ITestContext iTestContext) {
         try {
-            container.shutdownContainer();
+            container.shutdown();
         } catch (final Exception e) {
             // no-op
         }

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/b0bf6a10/extensions/pom.xml
----------------------------------------------------------------------
diff --git a/extensions/pom.xml b/extensions/pom.xml
index b974fc1..036dfbc 100644
--- a/extensions/pom.xml
+++ b/extensions/pom.xml
@@ -66,4 +66,32 @@
             <artifactId>derby</artifactId>
         </dependency>
     </dependencies>
+
+    <profiles>
+        <profile>
+            <id>cdi-1.0</id>
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
+
+            <dependencies>
+                <dependency>
+                    <groupId>org.apache.geronimo.specs</groupId>
+                    <artifactId>geronimo-jcdi_1.0_spec</artifactId>
+                </dependency>
+            </dependencies>
+        </profile>
+
+        <profile>
+            <id>cdi-1.1</id>
+
+            <dependencies>
+                <dependency>
+                    <groupId>org.apache.geronimo.specs</groupId>
+                    <artifactId>geronimo-jcdi_1.1_spec</artifactId>
+                </dependency>
+            </dependencies>
+        </profile>
+    </profiles>
+
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/b0bf6a10/jbatch/pom.xml
----------------------------------------------------------------------
diff --git a/jbatch/pom.xml b/jbatch/pom.xml
index 9af8663..db3bcc9 100644
--- a/jbatch/pom.xml
+++ b/jbatch/pom.xml
@@ -46,10 +46,6 @@
         </dependency>
         <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
-            <artifactId>geronimo-jcdi_1.0_spec</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-ejb_3.1_spec</artifactId>
         </dependency>
         <dependency>
@@ -85,12 +81,6 @@
             <groupId>org.apache.derby</groupId>
             <artifactId>derby</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.apache.openejb</groupId>
-            <artifactId>openejb-core</artifactId>
-            <version>4.6.0</version>
-            <scope>test</scope>
-        </dependency>
 
     </dependencies>
 
@@ -434,6 +424,53 @@
                 </plugins>
             </build>
         </profile>
+
+        <profile>
+            <id>cdi-1.0</id>
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
+
+            <dependencies>
+                <dependency>
+                    <groupId>org.apache.geronimo.specs</groupId>
+                    <artifactId>geronimo-jcdi_1.0_spec</artifactId>
+                </dependency>
+
+                <dependency>
+                    <groupId>org.apache.openejb</groupId>
+                    <artifactId>openejb-core</artifactId>
+                    <version>4.6.0</version>
+                    <scope>test</scope>
+                </dependency>
+            </dependencies>
+        </profile>
+
+        <profile>
+            <id>cdi-1.1</id>
+
+            <dependencies>
+                <dependency>
+                    <groupId>org.apache.geronimo.specs</groupId>
+                    <artifactId>geronimo-jcdi_1.1_spec</artifactId>
+                </dependency>
+
+                <dependency>
+                    <groupId>org.apache.tomee</groupId>
+                    <artifactId>openejb-core</artifactId>
+                    <version>7.0.0-SNAPSHOT</version>
+                    <scope>test</scope>
+                </dependency>
+
+                <!-- dont know why we need this -->
+                <dependency>
+                    <groupId>org.fusesource.jansi</groupId>
+                    <artifactId>jansi</artifactId>
+                    <version>1.8</version>
+                    <scope>test</scope>
+                </dependency>
+            </dependencies>
+        </profile>
     </profiles>
 
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/b0bf6a10/jbatch/src/main/java/org/apache/batchee/container/cdi/BatchCDIInjectionExtension.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/cdi/BatchCDIInjectionExtension.java b/jbatch/src/main/java/org/apache/batchee/container/cdi/BatchCDIInjectionExtension.java
index fc8afad..18e4655 100755
--- a/jbatch/src/main/java/org/apache/batchee/container/cdi/BatchCDIInjectionExtension.java
+++ b/jbatch/src/main/java/org/apache/batchee/container/cdi/BatchCDIInjectionExtension.java
@@ -17,6 +17,7 @@
 
 package org.apache.batchee.container.cdi;
 
+import javax.batch.operations.BatchRuntimeException;
 import javax.enterprise.event.Observes;
 import javax.enterprise.inject.spi.AfterBeanDiscovery;
 import javax.enterprise.inject.spi.AfterDeploymentValidation;
@@ -26,14 +27,44 @@ import javax.enterprise.inject.spi.BeforeShutdown;
 import javax.enterprise.inject.spi.Extension;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
+import java.lang.reflect.Method;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
 // excepted beforeBeanDiscovery() all is forked from DeltaSpike - we don't want to depend from it here
 public class BatchCDIInjectionExtension implements Extension {
+
+    private static final boolean CDI_1_1_AVAILABLE;
+    private static final Method CDI_CURRENT_METHOD;
+    private static final Method CDI_GET_BEAN_MANAGER_METHOD;
+
+
     private static BatchCDIInjectionExtension bmpSingleton = null;
+
     private volatile Map<ClassLoader, BeanManagerInfo> bmInfos = new ConcurrentHashMap<ClassLoader, BeanManagerInfo>();
 
+
+    static {
+        boolean cdi11Available;
+        Method currentMethod;
+        Method getBmMethod;
+
+        try {
+            Class<?> cdi = Class.forName("javax.enterprise.inject.spi.CDI", false, loader());
+            currentMethod = cdi.getDeclaredMethod("current");
+            getBmMethod = cdi.getDeclaredMethod("getBeanManager");
+            cdi11Available = true;
+        } catch (Exception e) {
+            currentMethod = null;
+            getBmMethod = null;
+            cdi11Available = false;
+        }
+
+        CDI_CURRENT_METHOD = currentMethod;
+        CDI_GET_BEAN_MANAGER_METHOD = getBmMethod;
+        CDI_1_1_AVAILABLE = cdi11Available;
+    }
+
     void beforeBeanDiscovery(final @Observes BeforeBeanDiscovery bbd, BeanManager bm) {
         bbd.addAnnotatedType(bm.createAnnotatedType(BatchProducerBean.class));
     }
@@ -43,20 +74,26 @@ public class BatchCDIInjectionExtension implements Extension {
         if (bmpSingleton == null) {
             bmpSingleton = this;
         }
-        final BeanManagerInfo bmi = getBeanManagerInfo(loader());
-        bmi.loadTimeBm = beanManager;
+
+        if (!CDI_1_1_AVAILABLE) {
+            final BeanManagerInfo bmi = getBeanManagerInfo(loader());
+            bmi.loadTimeBm = beanManager;
+        }
     }
 
     public void cleanupFinalBeanManagers(final @Observes AfterDeploymentValidation adv) {
-        for (final BeanManagerInfo bmi : bmpSingleton.bmInfos.values()) {
-            bmi.finalBm = null;
+        if (!CDI_1_1_AVAILABLE) {
+            for (final BeanManagerInfo bmi : bmpSingleton.bmInfos.values()) {
+                bmi.finalBm = null;
+            }
         }
     }
 
     public void cleanupStoredBeanManagerOnShutdown(final @Observes BeforeShutdown beforeShutdown) {
-        if (bmpSingleton == null) {
+        if (CDI_1_1_AVAILABLE || bmpSingleton == null) {
             return;
         }
+
         bmpSingleton.bmInfos.remove(loader());
     }
 
@@ -69,6 +106,15 @@ public class BatchCDIInjectionExtension implements Extension {
     }
 
     public BeanManager getBeanManager() {
+        if (CDI_1_1_AVAILABLE) {
+            try {
+                return (BeanManager) CDI_GET_BEAN_MANAGER_METHOD.invoke(CDI_CURRENT_METHOD.invoke(null));
+            } catch (Exception e) {
+                throw new BatchRuntimeException("unable to resolve BeanManager");
+            }
+        }
+
+        // fallback if CDI isn't available
         final BeanManagerInfo bmi = getBeanManagerInfo(loader());
 
         BeanManager result = bmi.finalBm;

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/b0bf6a10/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index fdad006..4fc261e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -134,6 +134,12 @@
             </dependency>
             <dependency>
                 <groupId>org.apache.geronimo.specs</groupId>
+                <artifactId>geronimo-jcdi_1.1_spec</artifactId>
+                <version>1.0</version>
+                <scope>provided</scope>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.geronimo.specs</groupId>
                 <artifactId>geronimo-ejb_3.1_spec</artifactId>
                 <version>1.0.2</version>
                 <scope>provided</scope>