You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2023/02/25 08:25:28 UTC

[openwebbeans] branch main updated: OWB-1428 make default bean-discovery-mode configurable

This is an automated email from the ASF dual-hosted git repository.

struberg pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/openwebbeans.git


The following commit(s) were added to refs/heads/main by this push:
     new f9a1dd7d0 OWB-1428 make default bean-discovery-mode configurable
f9a1dd7d0 is described below

commit f9a1dd7d01d593acce000c3414a766f40099a74d
Author: Mark Struberg <st...@apache.org>
AuthorDate: Sat Feb 25 09:24:08 2023 +0100

    OWB-1428 make default bean-discovery-mode configurable
    
    There was a really problematic change in the CDI-4.0 specification which will break many applications. They switched the bean-discovery-mode of an empty beans.xml file (or a beans.xml without any version) from ALL to ANNOTATED (Despite warnings that his is totally backward incompatible and could easily have been avoided).
    
    The default in OWB is still ALL, but it can be configured to any other bean-discovery-mode with this config switch to pass this very TCK test.
---
 .../org/apache/webbeans/config/BeansDeployer.java   |  3 ++-
 .../webbeans/config/OpenWebBeansConfiguration.java  | 21 +++++++++++++++++++++
 .../webbeans/xml/DefaultBeanArchiveService.java     | 16 +++++++++++++++-
 .../META-INF/openwebbeans/openwebbeans.properties   | 10 ++++++++++
 .../META-INF/openwebbeans/openwebbeans.properties   |  4 ++++
 webbeans-tck/standalone-suite.xml                   | 10 ----------
 6 files changed, 52 insertions(+), 12 deletions(-)

diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java b/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
index 99e0e8371..33c1ad9a1 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
@@ -196,7 +196,8 @@ public class BeansDeployer
         skipNoClassDefFoundTriggers = this.webBeansContext.getOpenWebBeansConfiguration().isSkipNoClassDefFoundErrorTriggers();
 
         defaultBeanArchiveInformation = new DefaultBeanArchiveInformation("default");
-        defaultBeanArchiveInformation.setBeanDiscoveryMode(BeanDiscoveryMode.ALL);
+
+        defaultBeanArchiveInformation.setBeanDiscoveryMode(webBeansContext.getOpenWebBeansConfiguration().getDefaultBeanDiscoveryMode());
     }
 
     /**
diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java b/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
index d692e4296..a8c12b58e 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
@@ -35,6 +35,7 @@ import java.util.stream.Stream;
 
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
+import org.apache.webbeans.spi.BeanArchiveService;
 
 import static java.util.Arrays.asList;
 import static java.util.stream.Collectors.toList;
@@ -205,6 +206,18 @@ public class OpenWebBeansConfiguration
     public static final String GENERATOR_JAVA_VERSION = "org.apache.webbeans.generator.javaVersion";
 
 
+    /**
+     * Default bean discovery mode for empty beans.xml
+     * There was a really wicked change in the CDI-4.0 specification which will break many applications.
+     * They switched the bean-discovery-mode of an empty beans.xml file (or a beans.xml without any version)
+     * from ALL to ANNOTATED (Despite warnings that his is totally backward incompatible and could easily have been avoided).
+     *
+     * The default in OWB is still ALL, but it can be configured to any other bean-discovery-mode with this config switch
+     */
+    public static final String DEFAULT_BEAN_DISCOVERY_MODE = "org.apache.webbeans.defaultBeanDiscoveryMode";
+
+
+
     /**Default configuration files*/
     private static final String DEFAULT_CONFIG_PROPERTIES_NAME = "META-INF/openwebbeans/openwebbeans.properties";
 
@@ -598,4 +611,12 @@ public class OpenWebBeansConfiguration
         }
         return proxyReservedPackages;
     }
+
+    /**
+     * @see #DEFAULT_BEAN_DISCOVERY_MODE
+     */
+    public BeanArchiveService.BeanDiscoveryMode getDefaultBeanDiscoveryMode()
+    {
+        return BeanArchiveService.BeanDiscoveryMode.valueOf(getProperty(OpenWebBeansConfiguration.DEFAULT_BEAN_DISCOVERY_MODE));
+    }
 }
diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveService.java b/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveService.java
index c5d12ba24..9404b1148 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveService.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/xml/DefaultBeanArchiveService.java
@@ -33,6 +33,7 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.apache.webbeans.config.OWBLogConst;
+import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.exception.WebBeansDeploymentException;
 import org.apache.webbeans.exception.WebBeansException;
@@ -56,6 +57,8 @@ public class DefaultBeanArchiveService implements BeanArchiveService
 
     private static final Logger logger = WebBeansLoggerFacade.getLogger(BeanArchiveService.class);
 
+    private WebBeansContext webBeansContext;
+
     /**
      * Contains a map from the URL externalForm to the stored BeanArchiveInformation
      */
@@ -294,7 +297,7 @@ public class DefaultBeanArchiveService implements BeanArchiveService
             if (firstVal < 0)
             {
                 // this means the stream is empty
-                bdaInfo.setBeanDiscoveryMode(BeanDiscoveryMode.ALL);
+                bdaInfo.setBeanDiscoveryMode(getWebBeansContext().getOpenWebBeansConfiguration().getDefaultBeanDiscoveryMode());
             }
             else
             {
@@ -347,6 +350,17 @@ public class DefaultBeanArchiveService implements BeanArchiveService
         return bdaInfo;
     }
 
+    private WebBeansContext getWebBeansContext()
+    {
+        // lazy init to avoid setup issues
+        if (webBeansContext == null)
+        {
+                webBeansContext = WebBeansContext.currentInstance();
+        }
+
+        return webBeansContext;
+    }
+
     private void readBeanChildren(DefaultBeanArchiveInformation bdaInfo, Element webBeansRoot, String beansXmlLocation)
     {
         ElementIterator elit = new ElementIterator(webBeansRoot);
diff --git a/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties b/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
index 8c48d699d..0c93bd805 100644
--- a/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
+++ b/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
@@ -161,6 +161,16 @@ org.apache.webbeans.web.eagerSessionInitialisation=false
 ################################################################################################
 
 
+###################### Default Bean Discovery Mode for empty beans.xml #########################
+# Default bean discovery mode for empty beans.xml
+# There was a really wicked change in the CDI-4.0 specification which will break many applications.
+# They switched the bean-discovery-mode of an empty beans.xml file (or a beans.xml without any version)
+# from ALL to ANNOTATED (Despite warnings that his is totally backward incompatible and could easily have been avoided).
+#
+# The default in OWB is still ALL, but it can be configured to any other bean-discovery-mode with this config switch
+################################################################################################
+org.apache.webbeans.defaultBeanDiscoveryMode=ALL
+
 ######################### Java version for generated proxy classes #############################
 # The Java Version to use for the generated proxy classes.
 # If "auto" then we will pick the version of the current JVM.
diff --git a/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties b/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
index dca603680..bf0ea5f95 100644
--- a/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
+++ b/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
@@ -46,3 +46,7 @@ org.apache.webbeans.container.InjectionResolver.fastMatching = false
 # only org.jboss.cdi.tck.tests.extensions.beanManager.beanAttributes.CreateBeanAttributesTest currently
 # we can write an arquillian extension to avoid to set it globally
 org.apache.webbeans.service.DefaultInjectionPointService.implicitSupport = false
+
+# Necessary due to messed um specification in CDI-4.0
+# Actually this breaks backward compatibility, but they totally didn't care.
+org.apache.webbeans.defaultBeanDiscoveryMode=ANNOTATED
diff --git a/webbeans-tck/standalone-suite.xml b/webbeans-tck/standalone-suite.xml
index fcaa02f3c..efc025f91 100644
--- a/webbeans-tck/standalone-suite.xml
+++ b/webbeans-tck/standalone-suite.xml
@@ -90,16 +90,6 @@
                 </methods>
             </class>
 
-            <!--
-                This is just the most backward breaking change I've seen in years.
-                Not going to implement it!
-            -->
-            <class name="org.jboss.cdi.tck.tests.deployment.discovery.EmptyBeansXmlDiscoveryTest" >
-                <methods>
-                    <exclude name=".*"/>
-                </methods>
-            </class>
-
             <!--
                 The test asserts something which is not defined in the spec.
             -->