openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1727792 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/util/ main/java/org/apache/webbeans/xml/ test/java/org/apache/webbeans/test/xml/ test/resources/org/apache/webbeans/test/xml/strict/
Date Sun, 31 Jan 2016 11:10:40 GMT
Author: struberg
Date: Sun Jan 31 11:10:40 2016
New Revision: 1727792

URL: http://svn.apache.org/viewvc?rev=1727792&view=rev
Log:
OWB-1107 adding <scopedBeansOnly/> backward compat option

adding a scopedBeansOnly tag to your beans.xml will make OWB only pick up scoped beans.
This is a backward compat option for bean-discovery-mode="scoped"

Added:
    openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/strict/cdi11_discovery_scoped.xml
      - copied, changed from r1727751, openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/strict/cdi11_discovery_none.xml
    openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/strict/cdi11_discovery_scopedBeansOnly.xml
  (with props)
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansConstants.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveService.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/BeanArchiveServiceTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansConstants.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansConstants.java?rev=1727792&r1=1727791&r2=1727792&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansConstants.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansConstants.java
Sun Jan 31 11:10:40 2016
@@ -43,6 +43,8 @@ public final class WebBeansConstants
     public static final String WEB_BEANS_XML_ALLOW_PROXYING_ELEMENT = "allowProxying";
     public static final String WEB_BEANS_XML_ALTERNATIVES_ELEMENT = "alternatives";
     public static final String WEB_BEANS_XML_SCAN_ELEMENT = "scan";
+    /** Having this tag in beans.xml fordes bean-discovery-mode="scoped" in a backward compat
way */
+    public static final String WEB_BEANS_XML_SCOPED_BEANS_ONLY_ELEMENT = "scopedBeansOnly";
 
     public static final String WEB_BEANS_XML_CLASS = "class";
     public static final String WEB_BEANS_XML_STEREOTYPE = "stereotype";

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveService.java?rev=1727792&r1=1727791&r2=1727792&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveService.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveService.java
Sun Jan 31 11:10:40 2016
@@ -214,7 +214,7 @@ public class DefaultBeanArchiveService i
         {
             xmlStream = beansXmlUrl.openStream();
 
-            return readBeansXml(xmlStream);
+            return readBeansXml(xmlStream, beansXmlUrl.toExternalForm());
 
         }
         catch (Exception e)
@@ -257,7 +257,7 @@ public class DefaultBeanArchiveService i
      * Read the information from the given beans.xml and fill it into a
      * BeanArchiveInformation instance.
      */
-    protected BeanArchiveInformation readBeansXml(InputStream xmlStreamIn) throws IOException
+    protected BeanArchiveInformation readBeansXml(InputStream xmlStreamIn, String beansXmlLocation)
throws IOException
     {
         DefaultBeanArchiveInformation bdaInfo = createBeanArchiveInformation();
 
@@ -287,7 +287,8 @@ public class DefaultBeanArchiveService i
                 {
                     if (!"beans".equalsIgnoreCase(webBeansRoot.getLocalName()))
                     {
-                        throw new WebBeansConfigurationException("beans.xml must have a <beans>
root element, but has: " + webBeansRoot.getLocalName());
+                        throw new WebBeansConfigurationException("beans.xml must have a <beans>
root element, but has: " + webBeansRoot.getLocalName() +
+                                                                 " in " + beansXmlLocation);
                     }
 
                     bdaInfo.setVersion(getTrimmedAttribute(webBeansRoot, "version"));
@@ -295,13 +296,13 @@ public class DefaultBeanArchiveService i
                     String beanDiscoveryMode = getTrimmedAttribute(webBeansRoot, "bean-discovery-mode");
                     bdaInfo.setBeanDiscoveryMode(beanDiscoveryMode != null ? BeanDiscoveryMode.valueOf(beanDiscoveryMode.toUpperCase())
: null);
 
-                    readBeanChildren(bdaInfo, webBeansRoot);
+                    readBeanChildren(bdaInfo, webBeansRoot, beansXmlLocation);
                 }
 
 
                 if (bdaInfo.getVersion() != null && !"1.0".equals(bdaInfo.getVersion())
&& bdaInfo.getBeanDiscoveryMode() == null)
                 {
-                    throw new WebBeansConfigurationException("beans.xml with version 1.1
and higher must declare a bean-discovery-mode!");
+                    throw new WebBeansConfigurationException("beans.xml with version 1.1
and higher must declare a bean-discovery-mode! url=" + beansXmlLocation);
                 }
 
 
@@ -322,7 +323,7 @@ public class DefaultBeanArchiveService i
         return bdaInfo;
     }
 
-    private void readBeanChildren(DefaultBeanArchiveInformation bdaInfo, Element webBeansRoot)
+    private void readBeanChildren(DefaultBeanArchiveInformation bdaInfo, Element webBeansRoot,
String beansXmlLocation)
     {
         ElementIterator elit = new ElementIterator(webBeansRoot);
         while (elit.hasNext())
@@ -349,6 +350,11 @@ public class DefaultBeanArchiveService i
             {
                 fillAllowProxying(bdaInfo, child);
             }
+            else if (WebBeansConstants.WEB_BEANS_XML_SCOPED_BEANS_ONLY_ELEMENT.equalsIgnoreCase(child.getLocalName()))
+            {
+                logger.info("OWB specific feature detected: force bean-discovery-mode=\"scopex\"
for " + beansXmlLocation);
+                bdaInfo.setBeanDiscoveryMode(BeanDiscoveryMode.SCOPED);
+            }
         }
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/BeanArchiveServiceTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/BeanArchiveServiceTest.java?rev=1727792&r1=1727791&r2=1727792&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/BeanArchiveServiceTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/BeanArchiveServiceTest.java
Sun Jan 31 11:10:40 2016
@@ -131,6 +131,28 @@ public class BeanArchiveServiceTest
     }
 
     @Test
+    public void testCdi11_discovery_scoped() throws Exception
+    {
+        BeanArchiveInformation bai = scanBeansXml("cdi11_discovery_scoped.xml");
+        Assert.assertEquals(BeanDiscoveryMode.SCOPED, bai.getBeanDiscoveryMode());
+        Assert.assertTrue(bai.getAlternativeClasses().isEmpty());
+        Assert.assertTrue(bai.getAlternativeStereotypes().isEmpty());
+        Assert.assertTrue(bai.getDecorators().isEmpty());
+        Assert.assertTrue(bai.getInterceptors().isEmpty());
+    }
+
+    @Test
+    public void testCdi11_discovery_scopedBeansOnly() throws Exception
+    {
+        BeanArchiveInformation bai = scanBeansXml("cdi11_discovery_scopedBeansOnly.xml");
+        Assert.assertEquals(BeanDiscoveryMode.SCOPED, bai.getBeanDiscoveryMode());
+        Assert.assertTrue(bai.getAlternativeClasses().isEmpty());
+        Assert.assertTrue(bai.getAlternativeStereotypes().isEmpty());
+        Assert.assertTrue(bai.getDecorators().isEmpty());
+        Assert.assertTrue(bai.getInterceptors().isEmpty());
+    }
+
+    @Test
     public void testExclude() throws Exception
     {
         BeanArchiveInformation bai = scanBeansXml("cdi11_exclude.xml");

Copied: openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/strict/cdi11_discovery_scoped.xml
(from r1727751, openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/strict/cdi11_discovery_none.xml)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/strict/cdi11_discovery_scoped.xml?p2=openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/strict/cdi11_discovery_scoped.xml&p1=openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/strict/cdi11_discovery_none.xml&r1=1727751&r2=1727792&rev=1727792&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/strict/cdi11_discovery_none.xml
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/strict/cdi11_discovery_scoped.xml
Sun Jan 31 11:10:40 2016
@@ -17,5 +17,5 @@ KIND, either express or implied.  See th
 specific language governing permissions and limitations
 under the License.
 -->
-<beans version="1.1" bean-discovery-mode="none">
+<beans version="1.1" bean-discovery-mode="scoped">
 </beans>

Added: openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/strict/cdi11_discovery_scopedBeansOnly.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/strict/cdi11_discovery_scopedBeansOnly.xml?rev=1727792&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/strict/cdi11_discovery_scopedBeansOnly.xml
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/strict/cdi11_discovery_scopedBeansOnly.xml
Sun Jan 31 11:10:40 2016
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<beans version="1.1" bean-discovery-mode="all">
+    <!-- this overwrites 'all' -->
+    <scopedBeansOnly/>
+</beans>

Propchange: openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/strict/cdi11_discovery_scopedBeansOnly.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message