Repository: deltaspike
Updated Branches:
  refs/heads/master 42d21481d -> 5a8369ae9


DELTASPIKE-1320 labeled alternatives take priority over global alternatives


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

Branch: refs/heads/master
Commit: 5a8369ae9b15555130951bc223352c8eb7ad64e3
Parents: 42d2148
Author: gpetracek <[email protected]>
Authored: Thu Mar 1 09:09:15 2018 +0100
Committer: gpetracek <[email protected]>
Committed: Thu Mar 1 09:12:36 2018 +0100

----------------------------------------------------------------------
 ...AwareGlobalAlternativeBeanClassProvider.java | 24 ++++++++------------
 1 file changed, 10 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5a8369ae/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/LabelAwareGlobalAlternativeBeanClassProvider.java
----------------------------------------------------------------------
diff --git 
a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/LabelAwareGlobalAlternativeBeanClassProvider.java
 
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/LabelAwareGlobalAlternativeBeanClassProvider.java
index 8a2ddf7..9d7d296 100644
--- 
a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/LabelAwareGlobalAlternativeBeanClassProvider.java
+++ 
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/LabelAwareGlobalAlternativeBeanClassProvider.java
@@ -48,39 +48,35 @@ public class LabelAwareGlobalAlternativeBeanClassProvider 
implements Alternative
         }
 
         Map<String, String> allProperties = ConfigResolver.getAllProperties();
-        // first read all globalAlternatives
         for (Map.Entry<String, String> property : allProperties.entrySet())
         {
-            if (property.getKey().startsWith(GLOBAL_ALTERNATIVES))
+            if (activeQualifierLabel != null && 
property.getKey().startsWith(activeQualifierLabel))
             {
-                String interfaceName = 
property.getKey().substring(GLOBAL_ALTERNATIVES.length());
+                String interfaceName = 
property.getKey().substring(activeQualifierLabel.length());
                 String implementation = property.getValue();
                 if (LOG.isLoggable(Level.FINE))
                 {
-                    LOG.fine("Enabling global alternative for interface " + 
interfaceName + ": " + implementation);
+                    LOG.fine("Enabling labeled alternative for interface " + 
interfaceName + ": " + implementation);
                 }
 
                 result.put(interfaceName, implementation);
             }
-        }
-
-        // and overwrite with any possible labled alternative, if exists
-        for (Map.Entry<String, String> property : allProperties.entrySet())
-        {
-            if (activeQualifierLabel != null && 
property.getKey().startsWith(activeQualifierLabel))
+            else if (property.getKey().startsWith(GLOBAL_ALTERNATIVES))
             {
-                String interfaceName = 
property.getKey().substring(activeQualifierLabel.length());
+                String interfaceName = 
property.getKey().substring(GLOBAL_ALTERNATIVES.length());
                 String implementation = property.getValue();
                 if (LOG.isLoggable(Level.FINE))
                 {
-                    LOG.fine("Enabling labeled alternative for interface " + 
interfaceName + ": " + implementation);
+                    LOG.fine("Enabling global alternative for interface " + 
interfaceName + ": " + implementation);
                 }
 
-                result.put(interfaceName, implementation);
+                if (!result.containsKey(interfaceName)) //don't override 
labeled alternatives
+                {
+                    result.put(interfaceName, implementation);
+                }
             }
         }
 
         return result;
     }
-
 }

Reply via email to