Author: rmannibucau
Date: Wed Jun  7 11:45:27 2017
New Revision: 1797913

URL: http://svn.apache.org/viewvc?rev=1797913&view=rev
Log:
some basic validation for el names

Modified:
    
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java
    
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
    openwebbeans/trunk/webbeans-tck/testng-dev.xml

Modified: 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java?rev=1797913&r1=1797912&r2=1797913&view=diff
==============================================================================
--- 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java
 (original)
+++ 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java
 Wed Jun  7 11:45:27 2017
@@ -86,7 +86,7 @@ public abstract class BeanAttributesBuil
 
     protected Set<Class<? extends Annotation>> stereotypes;
 
-    protected boolean alternative;
+    protected Boolean alternative;
     
     public static BeanAttributesBuilderFactory forContext(WebBeansContext 
webBeansContext)
     {
@@ -104,6 +104,12 @@ public abstract class BeanAttributesBuil
         this.webBeansContext = webBeansContext;
     }
 
+    public BeanAttributesBuilder<T, A> alternative(final boolean alternative)
+    {
+        this.alternative = alternative;
+        return this;
+    }
+
     public BeanAttributesImpl<T> build()
     {
         // we need to check the stereotypes first because we might need it to 
determine the scope
@@ -568,7 +574,7 @@ public abstract class BeanAttributesBuil
     // these alternatives can be not activated
     protected void defineAlternative()
     {
-        alternative = WebBeansUtil.isAlternative(annotated, stereotypes);
+        alternative = alternative == null || !alternative ? 
WebBeansUtil.isAlternative(annotated, stereotypes) : alternative;
     }
 
 

Modified: 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java?rev=1797913&r1=1797912&r2=1797913&view=diff
==============================================================================
--- 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
 (original)
+++ 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
 Wed Jun  7 11:45:27 2017
@@ -326,6 +326,8 @@ public class BeansDeployer
                 validateDecoratorDecoratedTypes();
                 validateDecoratorGenericTypes();
 
+                validateNames();
+
                 webBeansContext.getNotificationManager().clearCaches();
 
                 // fire event
@@ -367,6 +369,51 @@ public class BeansDeployer
         }
     }
 
+    /**
+     * Ensure "foo" and "foo.bar" conflict and is reported as a 
DeploymentException but foo.bar and foo.dummy don't conflict.
+     */
+    private void validateNames()
+    {
+        final Collection<String> names = new HashSet<>();
+        final Collection<String> partials = new HashSet<>();
+        for (final Bean<?> bean : 
webBeansContext.getBeanManagerImpl().getBeans())
+        {
+            // the skip logic needs some revisit but this validation is not 
useful enough to justify to resolve all alternatives here
+            if (bean.isAlternative())
+            {
+                continue;
+            }
+            if (AbstractProducerBean.class.isInstance(bean) && 
AbstractProducerBean.class.cast(bean).getOwnerComponent().isAlternative())
+            {
+                continue;
+            }
+
+            final String name = bean.getName();
+            if (name != null)
+            {
+                if (name.contains("."))
+                {
+                    final String[] segments = name.split("\\.");
+                    String current = "";
+                    for (int i = 0; i < segments.length - 1; i++)
+                    {
+                        current += (i > 0 ? "." : "") + segments[i];
+                        partials.add(current);
+                        if (names.contains(current))
+                        {
+                            throw new WebBeansDeploymentException("Name '" + 
name + "' is conflicting with '" + current + "'");
+                        }
+                    }
+                }
+
+                if (!names.add(name) || partials.contains(name))
+                {
+                    throw new WebBeansDeploymentException("Name '" + name + "' 
is conflicting");
+                }
+            }
+        }
+    }
+
     private Map<BeanArchiveInformation, Map<AnnotatedType<?>, 
ExtendedBeanAttributes<?>>> getBeanAttributes(
                                 final Map<BeanArchiveInformation, 
List<AnnotatedType<?>>> annotatedTypesPerBda)
     {
@@ -392,7 +439,9 @@ public class BeansDeployer
                     if (isEjb || (ClassUtil.isConcrete(beanClass) || 
WebBeansUtil.isDecorator(at)) && isValidManagedBean(at))
                     {
                         final BeanAttributesImpl tBeanAttributes = 
BeanAttributesBuilder.forContext(webBeansContext).newBeanAttibutes(at, 
onlyScopedBeans).build();
-                        if (tBeanAttributes != null)
+                        if (tBeanAttributes != null &&
+                                (!tBeanAttributes.isAlternative() || 
webBeansContext.getAlternativesManager()
+                                        .isAlternative(at.getJavaClass(), 
tBeanAttributes.getStereotypes())))
                         {
                             final ProcessBeanAttributesImpl<?> 
processBeanAttributes
                                 = 
webBeansContext.getWebBeansUtil().fireProcessBeanAttributes(at, 
at.getJavaClass(), tBeanAttributes);

Modified: openwebbeans/trunk/webbeans-tck/testng-dev.xml
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tck/testng-dev.xml?rev=1797913&r1=1797912&r2=1797913&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-tck/testng-dev.xml (original)
+++ openwebbeans/trunk/webbeans-tck/testng-dev.xml Wed Jun  7 11:45:27 2017
@@ -18,7 +18,9 @@
 <suite name="JSR-346-TCK" verbose="2" configfailurepolicy="continue">
   <test name="JSR-346 TCK">
     <classes>
-          <class 
name="org.jboss.cdi.tck.tests.definition.qualifier.repeatable.RepeatableQualifiersTest"
 />
+          <class 
name="org.jboss.cdi.tck.tests.extensions.lifecycle.processBeanAttributes.VerifyValuesTest"
 />
+          <class 
name="org.jboss.cdi.tck.tests.lookup.byname.ambiguous.AmbiguousELNamesTest" />
+          <class 
name="org.jboss.cdi.tck.tests.lookup.byname.ambiguous.broken.AmbiguousELNamesTest"
 />
       <!--
       <class 
name="org.jboss.cdi.tck.tests.event.parameterized.ParameterizedEventTest" />
       <class name="org.jboss.cdi.tck.tests.event.fires.FireEventTest" />


Reply via email to