tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1517440 - in /tomee/tomee/trunk/container/openejb-core/src/main: java/org/apache/openejb/cdi/CdiScanner.java resources/container-cdi-classes.properties
Date Mon, 26 Aug 2013 07:13:50 GMT
Author: rmannibucau
Date: Mon Aug 26 07:13:50 2013
New Revision: 1517440

URL: http://svn.apache.org/r1517440
Log:
OWB-895 adding myfaces and bval cdi beans if possible

Added:
    tomee/tomee/trunk/container/openejb-core/src/main/resources/container-cdi-classes.properties
Modified:
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiScanner.java

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiScanner.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiScanner.java?rev=1517440&r1=1517439&r2=1517440&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiScanner.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiScanner.java
Mon Aug 26 07:13:50 2013
@@ -37,12 +37,16 @@ import org.apache.webbeans.spi.ScannerSe
 import org.apache.webbeans.util.AnnotationUtil;
 
 import javax.interceptor.Interceptor;
+import java.io.IOException;
 import java.net.URL;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 
 /**
@@ -51,18 +55,33 @@ import java.util.Set;
 public class CdiScanner implements ScannerService {
     public static final String OPENEJB_CDI_FILTER_CLASSLOADER = "openejb.cdi.filter.classloader";
     public static final ThreadLocal<Collection<String>> ADDITIONAL_CLASSES =
new ThreadLocal<Collection<String>>();
+    private static final Map<String, Collection<String>> CONTAINER_CLASSES =
new HashMap<String, Collection<String>>();
+    static { // load container classes lists
+        final Properties props = new Properties();
+        try {
+            props.load(CdiScanner.class.getResourceAsStream("/container-cdi-classes.properties"));
+        } catch (final IOException e) {
+            // no-op
+        }
+        for (final String key : props.stringPropertyNames()) {
+            final Collection<String> set = new HashSet<String>();
+            CONTAINER_CLASSES.put(key, set);
+            Collections.addAll(set, props.getProperty(key).split(","));
+        }
+    }
 
     // TODO add all annotated class
     private final Set<Class<?>> classes = new HashSet<Class<?>>();
 
     @Override
-    public void init(Object object) {
+    public void init(final Object object) {
         if (!(object instanceof StartupObject)) {
             return;
         }
-        StartupObject startupObject = (StartupObject) object;
-        AppInfo appInfo = startupObject.getAppInfo();
-        ClassLoader classLoader = startupObject.getClassLoader();
+
+        final StartupObject startupObject = (StartupObject) object;
+        final AppInfo appInfo = startupObject.getAppInfo();
+        final ClassLoader classLoader = startupObject.getClassLoader();
         final ClassLoaderComparator comparator;
         if (classLoader instanceof  ClassLoaderComparator) {
             comparator = (ClassLoaderComparator) classLoader;
@@ -77,10 +96,12 @@ public class CdiScanner implements Scann
 
         final AnnotationManager annotationManager = webBeansContext.getAnnotationManager();
 
-        for (EjbJarInfo ejbJar : appInfo.ejbJars) {
+        for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
             final BeansInfo beans = ejbJar.beans;
 
-            if (beans == null) continue;
+            if (beans == null) {
+                continue;
+            }
 
             if (startupObject.isFromWebApp()) { // deploy only the related ejbmodule
                 if (!ejbJar.moduleId.equals(startupObject.getWebContext().getId())) {
@@ -104,8 +125,8 @@ public class CdiScanner implements Scann
             beans.duplicatedDecorators.clear();
             beans.duplicatedInterceptors.clear();
 
-            for (String className : beans.interceptors) {
-                Class<?> clazz = load(PropertyPlaceHolderHelper.simpleValue(className),
classLoader);
+            for (final String className : beans.interceptors) {
+                final Class<?> clazz = load(PropertyPlaceHolderHelper.simpleValue(className),
classLoader);
 
                 if (clazz != null) {
 // TODO: Move check to validation phase
@@ -125,9 +146,8 @@ public class CdiScanner implements Scann
                 }
             }
 
-            for (String className : beans.decorators) {
-                Class<?> clazz = load(PropertyPlaceHolderHelper.simpleValue(className),
classLoader);
-
+            for (final String className : beans.decorators) {
+                final Class<?> clazz = load(PropertyPlaceHolderHelper.simpleValue(className),
classLoader);
                 if (clazz != null) {
                     if (!decoratorsManager.isDecoratorEnabled(clazz)) {
                         decoratorsManager.addEnabledDecorator(clazz);
@@ -139,8 +159,8 @@ public class CdiScanner implements Scann
             }
 
 
-            for (String className : beans.alternativeStereotypes) {
-                Class<?> clazz = load(PropertyPlaceHolderHelper.simpleValue(className),
classLoader);
+            for (final String className : beans.alternativeStereotypes) {
+                final Class<?> clazz = load(PropertyPlaceHolderHelper.simpleValue(className),
classLoader);
                 if (clazz != null) {
                     alternativesManager.addStereoTypeAlternative(clazz, null, null);
                     classes.add(clazz);
@@ -149,8 +169,8 @@ public class CdiScanner implements Scann
                 }
             }
 
-            for (String className : beans.alternativeClasses) {
-                Class<?> clazz = load(PropertyPlaceHolderHelper.simpleValue(className),
classLoader);
+            for (final String className : beans.alternativeClasses) {
+                final Class<?> clazz = load(PropertyPlaceHolderHelper.simpleValue(className),
classLoader);
                 if (clazz != null) {
                     alternativesManager.addClazzAlternative(clazz, null, null);
                     classes.add(clazz);
@@ -184,15 +204,44 @@ public class CdiScanner implements Scann
                     }
 
                     final Class<?> load = load(name, classLoader);
-                    if (load != null && !classes.contains(name)) {
+                    if (load != null && !classes.contains(load)) {
                         classes.add(load);
                     }
                 }
             }
+
+            addContainerCdiClasses(classLoader, appInfo, ejbJar);
         }
 
     }
 
+    private void addContainerCdiClasses(final ClassLoader loader, final AppInfo app, final
EjbJarInfo ejbJar) {
+        if (!"true".equalsIgnoreCase(app.properties.getProperty("CdiContainer", "true")))
{
+            return;
+        }
+
+        addContainerClasses(app.properties, loader, "BVal");
+
+        if (ejbJar.webapp && "true".equalsIgnoreCase(app.properties.getProperty("Jsf.MyFaces",
"true"))) {
+            addContainerClasses(app.properties, loader, "MyFaces");
+        }
+    }
+
+
+    private void addContainerClasses(final Properties appProps, final ClassLoader loader,
final String key) {
+        if (!"true".equalsIgnoreCase(appProps.getProperty("CdiContainer." + key, "true")))
{
+            return;
+        }
+
+        for (final String clazz : CONTAINER_CLASSES.get("bval")) {
+            try {
+                classes.add(loader.loadClass(clazz));
+            } catch (final Throwable th) { // classnotfoundexception ot noclassdeffounderror
+                // no-op
+            }
+        }
+    }
+
     private static boolean shouldThrowCouldNotLoadException(final StartupObject startupObject)
{
         final AppInfo appInfo = startupObject.getAppInfo();
         return appInfo.webAppAlone || appInfo.webApps.size() == 0 || startupObject.isFromWebApp();

Added: tomee/tomee/trunk/container/openejb-core/src/main/resources/container-cdi-classes.properties
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/resources/container-cdi-classes.properties?rev=1517440&view=auto
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/resources/container-cdi-classes.properties
(added)
+++ tomee/tomee/trunk/container/openejb-core/src/main/resources/container-cdi-classes.properties
Mon Aug 26 07:13:50 2013
@@ -0,0 +1,46 @@
+#
+# 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.
+#
+
+BVal = org.apache.bval.cdi.BValExtension,\
+org.apache.bval.cdi.BValInterceptor,\
+org.apache.bval.cdi.BValBinding
+
+
+# generated from myfaces sources with command:
+# for j in $(for i in $(find . -name *cdi*); do find $i -name *.java; done); do echo $j |
sed 's#./impl/src/main/java/##g' | sed 's#.java##g' | sed 's#/#.#g'; done
+MyFaces = org.apache.myfaces.cdi.util.CDIUtils,\
+org.apache.myfaces.cdi.util.ContextualInstanceInfo,\
+org.apache.myfaces.cdi.util.AbstractContext,\
+org.apache.myfaces.cdi.util.BeanProvider,\
+org.apache.myfaces.cdi.util.AnyLiteral,\
+org.apache.myfaces.cdi.util.ContextualStorage,\
+org.apache.myfaces.cdi.view.ViewScopeContextualStorage,\
+org.apache.myfaces.cdi.view.ViewScopeBeanHolder,\
+org.apache.myfaces.cdi.view.ViewScopeContextImpl,\
+org.apache.myfaces.cdi.view.ViewScopeContextExtension,\
+org.apache.myfaces.cdi.view._ContextualKey,\
+org.apache.myfaces.cdi.view.ViewScopeCDIMap,\
+org.apache.myfaces.cdi.DefaultCDIViewScopeHandler,\
+org.apache.myfaces.cdi.impl.CDIManagedBeanHandlerImpl,\
+org.apache.myfaces.flow.cdi.FlowScopeBeanHolder,\
+org.apache.myfaces.flow.cdi.FlowBuilderCDIExtension,\
+org.apache.myfaces.flow.cdi.FlowScopeMap,\
+org.apache.myfaces.flow.cdi.FlowDefinitionQualifier,\
+org.apache.myfaces.flow.cdi.FlowScopeCDIExtension,\
+org.apache.myfaces.flow.cdi.FlowBuilderFactoryBean,\
+org.apache.myfaces.flow.cdi.DefaultCDIFacesFlowProvider,\
+org.apache.myfaces.flow.cdi.FlowScopedContextImpl



Mime
View raw message