Author: struberg
Date: Sun Oct 16 13:48:43 2011
New Revision: 1184824
URL: http://svn.apache.org/viewvc?rev=1184824&view=rev
Log:
OWB-624 prevent dupplicated processing of manually added AnnotatedTypes
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/BeforeBeanDiscoveryTest.java
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=1184824&r1=1184823&r2=1184824&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
Sun Oct 16 13:48:43 2011
@@ -62,6 +62,7 @@ import org.apache.webbeans.exception.Web
import
org.apache.webbeans.exception.inject.InconsistentSpecializationException;
import org.apache.webbeans.intercept.webbeans.WebBeansInterceptor;
import org.apache.webbeans.logger.WebBeansLogger;
+import org.apache.webbeans.portable.AnnotatedElementFactory;
import org.apache.webbeans.portable.events.ProcessAnnotatedTypeImpl;
import org.apache.webbeans.portable.events.ProcessInjectionTargetImpl;
import org.apache.webbeans.portable.events.discovery.AfterBeanDiscoveryImpl;
@@ -479,14 +480,27 @@ public class BeansDeployer
//Iterating over each class
if (classIndex != null)
{
+ AnnotatedElementFactory annotatedElementFactory =
webBeansContext.getAnnotatedElementFactory();
+ List<AnnotatedType<?>> additionalAnnotatedTypes =
webBeansContext.getBeanManagerImpl()
+
.getAdditionalAnnotatedTypes();
+
for(Class<?> implClass : classIndex)
{
//Define annotation type
- AnnotatedType<?> annotatedType =
webBeansContext.getAnnotatedElementFactory().newAnnotatedType(implClass);
+ AnnotatedType<?> annotatedType =
annotatedElementFactory.newAnnotatedType(implClass);
if (null != annotatedType)
{
deploySingleAnnotatedType(implClass, annotatedType);
+
+ if (additionalAnnotatedTypes.contains(annotatedType))
+ {
+ // if the implClass already gets processed as part of
the
+ // standard BDA scanning, then we don't need to
'additionally'
+ // deploy it anymore.
+ additionalAnnotatedTypes.remove(annotatedType);
+ }
+
}
else
{
@@ -510,14 +524,14 @@ public class BeansDeployer
private void deployAdditionalAnnotatedTypes()
{
BeanManagerImpl beanManager = webBeansContext.getBeanManagerImpl();
-
+
List<AnnotatedType<?>> annotatedTypes =
beanManager.getAdditionalAnnotatedTypes();
for(AnnotatedType<?> type : annotatedTypes)
{
Class implClass = type.getJavaClass();
-
- deploySingleAnnotatedType(implClass, type);
+
+ deploySingleAnnotatedType(implClass, type);
}
}
Modified:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/BeforeBeanDiscoveryTest.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/BeforeBeanDiscoveryTest.java?rev=1184824&r1=1184823&r2=1184824&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/BeforeBeanDiscoveryTest.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/BeforeBeanDiscoveryTest.java
Sun Oct 16 13:48:43 2011
@@ -35,7 +35,6 @@ import org.junit.Test;
public class BeforeBeanDiscoveryTest extends AbstractUnitTest
{
- @SuppressWarnings("serial")
@Test
public void testAddAdditionalAnnotatedType()
{
@@ -57,4 +56,27 @@ public class BeforeBeanDiscoveryTest ext
shutDownContainer();
}
+
+ @Test
+ public void testAddAdditionalAnnotatedTypeWithPresentClass()
+ {
+ Collection<String> beanXmls = new ArrayList<String>();
+
+ Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+ beanClasses.add(MyBean.class);
+
+ addExtension(new AddAdditionalAnnotatedTypeExtension());
+
+ startContainer(beanClasses, beanXmls);
+
+ Bean<?> bean = getBeanManager().getBeans(MyBean.class, new
AnnotationLiteral<Default>()
+ {
+ }).iterator().next();
+
+ // Bean should not be null, as we added it as an additional annotated
+ // type during before bean discovery in the extension
+ Assert.assertNotNull(bean);
+
+ shutDownContainer();
+ }
}