openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1545244 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/inject/ main/java/org/apache/webbeans/xml/ test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/ test/resources/org/apache/webbeans/newtests/co...
Date Mon, 25 Nov 2013 12:50:19 GMT
Author: struberg
Date: Mon Nov 25 12:50:19 2013
New Revision: 1545244

URL: http://svn.apache.org/r1545244
Log:
OWB-916 allow multiple alternatives as long as they are in different beans.xmls

Added:
    openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/concepts/alternatives/tests/MultipleAlternativesInSameFile_broken.xml
      - copied, changed from r1545239, openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeOnProducerFieldTest.xml
    openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/concepts/alternatives/tests/simpleAlternative_2.xml
      - copied unchanged from r1545239, openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/concepts/alternatives/tests/simpleAlternative.xml
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansXMLConfigurator.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeBeanResolvingTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java?rev=1545244&r1=1545243&r2=1545244&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java
Mon Nov 25 12:50:19 2013
@@ -56,8 +56,7 @@ public class AlternativesManager
                 if(AnnotationUtil.hasClassAnnotation(stereo, Alternative.class))
                 {
                     boolean isBDAScanningEnabled=(scanner!=null && scanner.isBDABeansXmlScanningEnabled());
-                    if(isBDAScanningEnabled && !scanner.getBDABeansXmlScanner().addStereoType(stereo,
fileName) ||
-                            (!isBDAScanningEnabled && stereoAlternatives.contains(stereo))
)
+                    if(isBDAScanningEnabled && !scanner.getBDABeansXmlScanner().addStereoType(stereo,
fileName))
                     {
                         throw new WebBeansConfigurationException("Given alternative class
: " + alternative.getName() + " is already added as @Alternative" );
                     }
@@ -84,8 +83,7 @@ public class AlternativesManager
         if(AnnotationUtil.hasClassAnnotation(alternative, Alternative.class))
         {
             boolean isBDAScanningEnabled=(scanner!=null && scanner.isBDABeansXmlScanningEnabled());
-            if((isBDAScanningEnabled && !scanner.getBDABeansXmlScanner().addAlternative(alternative,
fileName)) ||
-                    (!isBDAScanningEnabled && alternatives.contains(alternative)))
+            if((isBDAScanningEnabled && !scanner.getBDABeansXmlScanner().addAlternative(alternative,
fileName)))
             {
                 throw new WebBeansConfigurationException("Given class : " + alternative.getName()
+ " is already added as @Alternative" );
             }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansXMLConfigurator.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansXMLConfigurator.java?rev=1545244&r1=1545243&r2=1545244&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansXMLConfigurator.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansXMLConfigurator.java
Mon Nov 25 12:50:19 2013
@@ -374,12 +374,18 @@ public final class WebBeansXMLConfigurat
     /**
      * Configures enablements of the decorators.
      *
-     * @param alternativesElement decorators element
+     * @param alternativesElement alternatives element
      */
     private void configureAlternativesElement(Element alternativesElement,String fileName,ScannerService
scanner)
     {
         Node node;
         Element child;
+
+        // the alternatives in this beans.xml
+        // this gets used to detect multiple definitions of the
+        // same alternative in one beans.xml file.
+        Set<String> alternativesInFile = new HashSet<String>();
+
         NodeList ns = alternativesElement.getChildNodes();
         for (int i = 0; i < ns.getLength(); i++)
         {
@@ -389,6 +395,14 @@ public final class WebBeansXMLConfigurat
                 continue;
             }
             child = (Element) node;
+            String alternativeName = child.getTextContent().trim();
+
+            if (alternativesInFile.contains(alternativeName))
+            {
+                throw new WebBeansConfigurationException("Given alternative : " + alternativeName
+                                                         + " is already added as @Alternative"
);
+            }
+            alternativesInFile.add(alternativeName);
 
             if (getName(child).equals(WebBeansConstants.WEB_BEANS_XML_SPEC_SPECIFIC_STEREOTYPE)
||
                 getName(child).equals(WebBeansConstants.WEB_BEANS_XML_OWB_SPECIFIC_STEREOTYPE))

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeBeanResolvingTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeBeanResolvingTest.java?rev=1545244&r1=1545243&r2=1545244&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeBeanResolvingTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeBeanResolvingTest.java
Mon Nov 25 12:50:19 2013
@@ -24,7 +24,9 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Set;
 
+import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.apache.webbeans.newtests.concepts.alternatives.common.AlternativeBean;
 import org.apache.webbeans.newtests.concepts.alternatives.common.AlternativeOnClassAndProducerMethodBean;
 import org.apache.webbeans.newtests.concepts.alternatives.common.AlternativeOnClassOnlyBean;
 import org.apache.webbeans.newtests.concepts.alternatives.common.DefaultBeanProducerWithoutDisposes;
@@ -70,4 +72,45 @@ public class AlternativeBeanResolvingTes
         Assert.assertEquals(2, beans.size());
     }
 
+
+    /**
+     * Having the same alternative enabled multiple times in the same beans.xml
+     * This must abort with a deployment error.
+     */
+    @Test(expected = WebBeansConfigurationException.class)
+    public void testMultipleAlternativeInSameFile()
+    {
+        Collection<String> beanXmls = new ArrayList<String>();
+        beanXmls.add(getXmlPath(PACKAGE_NAME, "MultipleAlternativesInSameFile_broken"));
+
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(Pen.class);
+        beanClasses.add(Pencil.class);
+        beanClasses.add(PencilProducerBean.class);
+        beanClasses.add(DefaultBeanProducerWithoutDisposes.class);
+        beanClasses.add(AlternativeOnClassAndProducerMethodBean.class);
+        beanClasses.add(YetAnotherPencil.class);
+
+        startContainer(beanClasses, beanXmls, true);
+    }
+
+
+    @Test
+    public void testMultipleAlternativeInDifferentFiles()
+    {
+        Collection<String> beanXmls = new ArrayList<String>();
+        beanXmls.add(getXmlPath(PACKAGE_NAME, "simpleAlternative"));
+        beanXmls.add(getXmlPath(PACKAGE_NAME, "simpleAlternative_2"));
+
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(AlternativeBean.class);
+
+        startContainer(beanClasses, beanXmls, true);
+
+        AlternativeBean alternativeBean = getInstance(AlternativeBean.class);
+        Assert.assertNotNull(alternativeBean);
+        Assert.assertEquals(AlternativeBean.class, alternativeBean.getImplementationType());
+
+    }
+
 }

Copied: openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/concepts/alternatives/tests/MultipleAlternativesInSameFile_broken.xml
(from r1545239, openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeOnProducerFieldTest.xml)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/concepts/alternatives/tests/MultipleAlternativesInSameFile_broken.xml?p2=openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/concepts/alternatives/tests/MultipleAlternativesInSameFile_broken.xml&p1=openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeOnProducerFieldTest.xml&r1=1545239&r2=1545244&rev=1545244&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeOnProducerFieldTest.xml
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/concepts/alternatives/tests/MultipleAlternativesInSameFile_broken.xml
Mon Nov 25 12:50:19 2013
@@ -20,5 +20,6 @@ under the License.
 <beans>
     <alternatives>
         <class>org.apache.webbeans.newtests.concepts.alternatives.common.PencilProducerBean</class>
+        <class>org.apache.webbeans.newtests.concepts.alternatives.common.PencilProducerBean</class>
     </alternatives>
 </beans>



Mime
View raw message