deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject git commit: DELTASPIKE-208 explicitely enable global alternatives
Date Wed, 22 May 2013 15:09:43 GMT
Updated Branches:
  refs/heads/master fc063b934 -> e56f26140


DELTASPIKE-208 explicitely enable global alternatives

This now works on Weld, OWB with BDA enabled, etc


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

Branch: refs/heads/master
Commit: e56f26140787fbe76b3c155c0248558287370e2c
Parents: fc063b9
Author: Mark Struberg <struberg@apache.org>
Authored: Wed May 22 17:01:50 2013 +0200
Committer: Mark Struberg <struberg@apache.org>
Committed: Wed May 22 17:01:50 2013 +0200

----------------------------------------------------------------------
 .../impl/exclude/extension/ExcludeExtension.java   |   73 ++++++++------
 .../META-INF/apache-deltaspike.properties          |    6 +-
 2 files changed, 45 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/e56f2614/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java
index 88a5972..22dd33c 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java
@@ -44,8 +44,10 @@ import java.lang.reflect.Method;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.jar.Attributes;
 import java.util.jar.Manifest;
@@ -60,27 +62,56 @@ import java.util.logging.Logger;
  */
 public class ExcludeExtension implements Extension, Deactivatable
 {
-    private static final Logger LOG = Logger.getLogger(ExcludeExtension.class.getName());
+    private static final String GLOBAL_ALTERNATIVES = "globalAlternatives.";
 
-    private static Boolean isWeld1Detected = false;
+    private static final Logger LOG = Logger.getLogger(ExcludeExtension.class.getName());
 
     private boolean isActivated = true;
     private boolean isGlobalAlternativeActivated = true;
     private boolean isCustomProjectStageBeanFilterActivated = true;
 
+    /**
+     * Contains the globalAlternatives which should get used
+     * KEY=Interface class name
+     * VALUE=Implementation class name
+     */
+    private Map<String, String> globalAlternatives = new HashMap<String, String>();
+
+
     @SuppressWarnings("UnusedDeclaration")
     protected void init(@Observes BeforeBeanDiscovery beforeBeanDiscovery, BeanManager beanManager)
     {
         isActivated =
                 ClassDeactivationUtils.isActivated(getClass());
 
-        isGlobalAlternativeActivated =
-                ClassDeactivationUtils.isActivated(GlobalAlternative.class);
-
         isCustomProjectStageBeanFilterActivated =
                 ClassDeactivationUtils.isActivated(CustomProjectStageBeanFilter.class);
 
-        isWeld1Detected = isWeld1(beanManager);
+        isGlobalAlternativeActivated =
+                ClassDeactivationUtils.isActivated(GlobalAlternative.class);
+        if (isGlobalAlternativeActivated)
+        {
+            Map<String, String> allProperties = ConfigResolver.getAllProperties();
+            for (Map.Entry<String, String> property : allProperties.entrySet())
+            {
+                if (property.getKey().startsWith(GLOBAL_ALTERNATIVES))
+                {
+                    String interfaceName = property.getKey().substring(GLOBAL_ALTERNATIVES.length());
+                    String implementation = property.getValue();
+                    if (LOG.isLoggable(Level.FINE))
+                    {
+                        LOG.fine("Enabling global alternative for interface " + interfaceName
+ ": " + implementation);
+                    }
+
+                    globalAlternatives.put(interfaceName, implementation);
+                }
+            }
+
+            if (globalAlternatives.isEmpty())
+            {
+                isGlobalAlternativeActivated = false;
+            }
+        }
     }
 
     /**
@@ -101,9 +132,9 @@ public class ExcludeExtension implements Extension, Deactivatable
     protected void vetoBeans(@Observes ProcessAnnotatedType processAnnotatedType, BeanManager
beanManager)
     {
         //we need to do it before the exclude logic to keep the @Exclude support for global
alternatives
-        if (isGlobalAlternativeActivated && isWeld1Detected)
+        if (isGlobalAlternativeActivated)
         {
-            activateGlobalAlternativesWeld1(processAnnotatedType, beanManager);
+            activateGlobalAlternatives(processAnnotatedType, beanManager);
         }
 
         if (isCustomProjectStageBeanFilterActivated)
@@ -158,8 +189,8 @@ public class ExcludeExtension implements Extension, Deactivatable
 
 
 
-    private void activateGlobalAlternativesWeld1(ProcessAnnotatedType processAnnotatedType,
-                                                 BeanManager beanManager)
+    private void activateGlobalAlternatives(ProcessAnnotatedType processAnnotatedType,
+                                            BeanManager beanManager)
     {
         Class<Object> currentBean = processAnnotatedType.getAnnotatedType().getJavaClass();
 
@@ -184,7 +215,7 @@ public class ExcludeExtension implements Extension, Deactivatable
         {
             alternativeBeanAnnotations = new HashSet<Annotation>();
 
-            configuredBeanName = ConfigResolver.getPropertyValue(currentType.getName());
+            configuredBeanName = globalAlternatives.get(currentType.getName());
             if (configuredBeanName != null && configuredBeanName.length() > 0)
             {
                 alternativeBeanClass = ClassUtils.tryToLoadClassForName(configuredBeanName);
@@ -442,26 +473,6 @@ public class ExcludeExtension implements Extension, Deactivatable
                 processAnnotatedType.getAnnotatedType().getJavaClass());
     }
 
-    private boolean isWeld1(BeanManager beanManager)
-    {
-        if (beanManager.getClass().getName().startsWith("org.apache"))
-        {
-            return false;
-        }
-
-        if (beanManager.getClass().getName().startsWith("org.jboss.weld"))
-        {
-            String version = getJarVersion(beanManager.getClass());
-
-            if (version != null && version.startsWith("1."))
-            {
-                return true;
-            }
-        }
-
-        return false;
-    }
-
     private static String getJarVersion(Class targetClass)
     {
         String manifestFileLocation = getManifestFileLocationOfClass(targetClass);

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/e56f2614/deltaspike/core/impl/src/test/resources/META-INF/apache-deltaspike.properties
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/resources/META-INF/apache-deltaspike.properties
b/deltaspike/core/impl/src/test/resources/META-INF/apache-deltaspike.properties
index b935ffc..ba29086 100644
--- a/deltaspike/core/impl/src/test/resources/META-INF/apache-deltaspike.properties
+++ b/deltaspike/core/impl/src/test/resources/META-INF/apache-deltaspike.properties
@@ -20,10 +20,10 @@ org.apache.deltaspike.core.spi.activation.ClassDeactivator=org.apache.deltaspike
 testProperty02=test_value_02
 db=prodDB
 
-org.apache.deltaspike.test.core.api.alternative.global.BaseBean1=org.apache.deltaspike.test.core.api.alternative.global.SubBaseBean2
-org.apache.deltaspike.test.core.api.alternative.global.BaseInterface1=org.apache.deltaspike.test.core.api.alternative.global.BaseInterface1AlternativeImplementation
+globalAlternatives.org.apache.deltaspike.test.core.api.alternative.global.BaseBean1=org.apache.deltaspike.test.core.api.alternative.global.SubBaseBean2
+globalAlternatives.org.apache.deltaspike.test.core.api.alternative.global.BaseInterface1=org.apache.deltaspike.test.core.api.alternative.global.BaseInterface1AlternativeImplementation
 
-org.apache.deltaspike.test.core.api.alternative.global.qualifier.BaseInterface=org.apache.deltaspike.test.core.api.alternative.global.qualifier.AlternativeBaseBeanB
+globalAlternatives.org.apache.deltaspike.test.core.api.alternative.global.qualifier.BaseInterface=org.apache.deltaspike.test.core.api.alternative.global.qualifier.AlternativeBaseBeanB
 
 configProperty1=14
 configProperty2=7


Mime
View raw message