Return-Path: X-Original-To: apmail-openwebbeans-commits-archive@www.apache.org Delivered-To: apmail-openwebbeans-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 431CF10075 for ; Thu, 7 Nov 2013 11:06:00 +0000 (UTC) Received: (qmail 17436 invoked by uid 500); 7 Nov 2013 11:05:57 -0000 Delivered-To: apmail-openwebbeans-commits-archive@openwebbeans.apache.org Received: (qmail 17412 invoked by uid 500); 7 Nov 2013 11:05:54 -0000 Mailing-List: contact commits-help@openwebbeans.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openwebbeans.apache.org Delivered-To: mailing list commits@openwebbeans.apache.org Received: (qmail 17400 invoked by uid 99); 7 Nov 2013 11:05:51 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Nov 2013 11:05:51 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Nov 2013 11:05:50 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 366A92388900; Thu, 7 Nov 2013 11:05:30 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1539593 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/container/ test/java/org/apache/webbeans/newtests/managed/specialized/ Date: Thu, 07 Nov 2013 11:05:30 -0000 To: commits@openwebbeans.apache.org From: rmannibucau@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131107110530.366A92388900@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: rmannibucau Date: Thu Nov 7 11:05:29 2013 New Revision: 1539593 URL: http://svn.apache.org/r1539593 Log: OWB-912 Instance filtering is too restrictive Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/specialized/ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/specialized/SpecializeDeactivationTest.java Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java?rev=1539593&r1=1539592&r2=1539593&view=diff ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java (original) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java Thu Nov 7 11:05:29 2013 @@ -530,11 +530,14 @@ public class InjectionResolver resolvedComponents = findByQualifier(resolvedComponents, injectionPointType, qualifiers); // Ambigious resolution, check for specialization + /* + // super beans are deactivated so it is useless if (resolvedComponents.size() > 1) { //Look for specialization resolvedComponents = findBySpecialization(resolvedComponents); } + */ resolvedBeansByType.put(cacheKey, resolvedComponents); if (logger.isLoggable(Level.FINE)) @@ -690,7 +693,11 @@ public class InjectionResolver if(set.size() > 1) { - throwAmbiguousResolutionException(set); + set = findBySpecialization(set); + if(set.size() > 1) + { + throwAmbiguousResolutionException(set); + } } return (Bean)set.iterator().next(); @@ -716,10 +723,13 @@ public class InjectionResolver return Collections.emptySet(); } + /* + // specialized bean are disabled so no need to refilter if(set.size() > 1) { set = findBySpecialization(set); } + */ return set; } Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/specialized/SpecializeDeactivationTest.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/specialized/SpecializeDeactivationTest.java?rev=1539593&view=auto ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/specialized/SpecializeDeactivationTest.java (added) +++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/specialized/SpecializeDeactivationTest.java Thu Nov 7 11:05:29 2013 @@ -0,0 +1,167 @@ +/* + * 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.newtests.managed.specialized; + +import org.apache.webbeans.newtests.AbstractUnitTest; +import org.junit.Before; +import org.junit.Test; + +import javax.annotation.PostConstruct; +import javax.enterprise.inject.Any; +import javax.enterprise.inject.Instance; +import javax.enterprise.inject.Produces; +import javax.enterprise.inject.Specializes; +import javax.inject.Inject; +import java.util.Arrays; +import java.util.Collections; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class SpecializeDeactivationTest extends AbstractUnitTest +{ + @Inject + private Init init; + + @Before + public void reset() { + Impl1.called = false; + Impl2.called = false; + SpeImpl1.called = false; + } + + @Test + public void normal() + { + startContainer(Arrays.>asList(Init.class, API.class, Impl1.class, Impl2.class), + Collections.emptyList(), true); + + assertEquals(2, init.init()); + assertTrue(Impl1.called); + assertTrue(Impl2.called); + } + + @Test + public void specialize() + { + startContainer(Arrays.>asList(Init.class, API.class, Impl1.class, Impl2.class, SpeImpl1.class), + Collections.emptyList(), true); + + assertEquals(2, init.init()); + assertTrue(SpeImpl1.called); + assertTrue(Impl2.called); + } + + @Test + public void specializeProducers() + { + startContainer(Arrays.>asList(Init.class, API.class, Prod1.class, Prod2.class, Spe1.class), + Collections.emptyList(), true); + + assertEquals(2, init.init()); + assertTrue(SpeImpl1.called); + assertTrue(Impl2.called); + } + + public static interface API + { + void init(); + } + + public static class Prod1 + { + @Produces + public API api1() + { + return new Impl1(); + } + } + + public static class Spe1 extends Prod1 + { + @Produces + @Override + @Specializes + public API api1() + { + return new SpeImpl1(); + } + } + + public static class Prod2 + { + @Produces + public API api1() + { + return new Impl2(); + } + } + + public static class Impl1 implements API + { + public static boolean called = false; + + @Override + public void init() + { + called = true; + } + } + + @Specializes + public static class SpeImpl1 extends Impl1 + { + public static boolean called = false; + + @Override + public void init() + { + called = true; + } + } + + public static class Impl2 implements API + { + public static boolean called = false; + + @Override + public void init() + { + called = true; + } + } + + public static class Init + { + @Inject + @Any + private Instance impls; + + public int init() + { + int i = 0; + for (final API api : impls) + { + api.init(); + i++; + } + return i; + } + } +}