openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1776382 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/third/ test/java/org/apache/webbeans/test/component/third/
Date Thu, 29 Dec 2016 07:50:01 GMT
Author: rmannibucau
Date: Thu Dec 29 07:50:00 2016
New Revision: 1776382

URL: http://svn.apache.org/viewvc?rev=1776382&view=rev
Log:
OWB-1164 applying patch from John D. Ament to add @Any to 3rd party beans, thanks John

Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/third/ThirdpartyBeanAttributesImpl.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/third/
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/third/ThirdPartyExtension.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/third/ThirdPartyProgrammaticLookupTest.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/third/ThirdpartyBeanImpl.java

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/third/ThirdpartyBeanAttributesImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/third/ThirdpartyBeanAttributesImpl.java?rev=1776382&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/third/ThirdpartyBeanAttributesImpl.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/third/ThirdpartyBeanAttributesImpl.java
Thu Dec 29 07:50:00 2016
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ */
+package org.apache.webbeans.component.third;
+
+import org.apache.webbeans.annotation.AnyLiteral;
+import org.apache.webbeans.component.BeanAttributesImpl;
+
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.spi.BeanAttributes;
+import java.lang.annotation.Annotation;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+class ThirdpartyBeanAttributesImpl<T> extends BeanAttributesImpl<T>
+{
+    private final Set<Annotation> qualifiers;
+    ThirdpartyBeanAttributesImpl(BeanAttributes<T> beanAttributes)
+    {
+        super(beanAttributes, false);
+        this.qualifiers = calculateQualifiers(beanAttributes);
+    }
+
+    @Override
+    public Set<Annotation> getQualifiers()
+    {
+        return qualifiers;
+    }
+
+    private Set<Annotation> calculateQualifiers(BeanAttributes<T> beanAttributes)
+    {
+        final Set<Annotation> originalQualifiers = beanAttributes.getQualifiers() ==
null ?
+                Collections.<Annotation>emptySet() : beanAttributes.getQualifiers();
+        final Set<Annotation> newQualifiers = new HashSet<>(originalQualifiers);
+        boolean foundAny = false;
+        for(Annotation a : originalQualifiers)
+        {
+            if(a instanceof Any)
+            {
+                foundAny = true;
+                break;
+            }
+        }
+        if(!foundAny)
+        {
+            newQualifiers.add(AnyLiteral.INSTANCE);
+        }
+        return newQualifiers;
+    }
+}

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/third/ThirdpartyBeanImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/third/ThirdpartyBeanImpl.java?rev=1776382&r1=1776381&r2=1776382&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/third/ThirdpartyBeanImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/third/ThirdpartyBeanImpl.java
Thu Dec 29 07:50:00 2016
@@ -27,7 +27,6 @@ import javax.enterprise.inject.spi.Injec
 import javax.enterprise.inject.spi.Producer;
 
 import org.apache.webbeans.component.AbstractOwbBean;
-import org.apache.webbeans.component.BeanAttributesImpl;
 import org.apache.webbeans.component.WebBeansType;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
@@ -40,7 +39,7 @@ public class ThirdpartyBeanImpl<T> exten
     {
         super(webBeansContext,
               WebBeansType.THIRDPARTY,
-              new BeanAttributesImpl<T>(bean, false),
+              new ThirdpartyBeanAttributesImpl<>(bean),
               bean.getBeanClass(),
               bean.isNullable());
         

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/third/ThirdPartyExtension.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/third/ThirdPartyExtension.java?rev=1776382&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/third/ThirdPartyExtension.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/third/ThirdPartyExtension.java
Thu Dec 29 07:50:00 2016
@@ -0,0 +1,119 @@
+/*
+ * 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.
+ */
+package org.apache.webbeans.test.component.third;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.InjectionPoint;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+
+import static java.util.Collections.emptySet;
+
+public class ThirdPartyExtension implements Extension
+{
+    public void addThirdPartyBean(@Observes AfterBeanDiscovery afterBeanDiscovery)
+    {
+        afterBeanDiscovery.addBean(new Bean<SomeFakeBean>()
+        {
+            @Override
+            public Set<Type> getTypes()
+            {
+                Set<Type> types = new HashSet<Type>();
+                types.add(Object.class);
+                types.add(SomeFakeBean.class);
+                return types;
+            }
+
+            @Override
+            public Set<Annotation> getQualifiers()
+            {
+                return emptySet();
+            }
+
+            @Override
+            public Class<? extends Annotation> getScope()
+            {
+                return Dependent.class;
+            }
+
+            @Override
+            public String getName()
+            {
+                return null;
+            }
+
+            @Override
+            public Set<Class<? extends Annotation>> getStereotypes()
+            {
+                return emptySet();
+            }
+
+            @Override
+            public boolean isAlternative()
+            {
+                return false;
+            }
+
+            @Override
+            public SomeFakeBean create(CreationalContext<SomeFakeBean> creationalContext)
+            {
+                return new SomeFakeBean();
+            }
+
+            @Override
+            public void destroy(SomeFakeBean someFakeBean, CreationalContext<SomeFakeBean>
creationalContext)
+            {
+
+            }
+
+            @Override
+            public Set<InjectionPoint> getInjectionPoints()
+            {
+                return emptySet();
+            }
+
+            @Override
+            public Class<?> getBeanClass()
+            {
+                return SomeFakeBean.class;
+            }
+
+            @Override
+            public boolean isNullable()
+            {
+                return false;
+            }
+        });
+    }
+
+    public static class SomeFakeBean
+    {
+        public String doProcess()
+        {
+            return "processed";
+        }
+    }
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/third/ThirdPartyProgrammaticLookupTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/third/ThirdPartyProgrammaticLookupTest.java?rev=1776382&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/third/ThirdPartyProgrammaticLookupTest.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/third/ThirdPartyProgrammaticLookupTest.java
Thu Dec 29 07:50:00 2016
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+package org.apache.webbeans.test.component.third;
+
+import org.apache.webbeans.test.AbstractUnitTest;
+import org.junit.Test;
+
+import javax.enterprise.inject.spi.CDI;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class ThirdPartyProgrammaticLookupTest extends AbstractUnitTest
+{
+    @Test
+    public void shouldLoadThirdPartyWithQualifiers()
+    {
+        addExtension(new ThirdPartyExtension());
+        startContainer();
+        ThirdPartyExtension.SomeFakeBean someFakeBean = CDI.current().select(ThirdPartyExtension.SomeFakeBean.class).get();
+        assertNotNull(someFakeBean);
+        assertEquals("processed",someFakeBean.doProcess());
+        shutDownContainer();
+    }
+
+}



Mime
View raw message