Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E35A51860A for ; Fri, 3 Jul 2015 15:33:01 +0000 (UTC) Received: (qmail 61226 invoked by uid 500); 3 Jul 2015 15:33:01 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 61196 invoked by uid 500); 3 Jul 2015 15:33:01 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 61144 invoked by uid 99); 3 Jul 2015 15:33:01 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Jul 2015 15:33:01 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 5B4C8D1F12 for ; Fri, 3 Jul 2015 15:33:01 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.21 X-Spam-Level: * X-Spam-Status: No, score=1.21 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.571, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id M8EJSaS7vRLh for ; Fri, 3 Jul 2015 15:33:00 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with SMTP id 99E664C16D for ; Fri, 3 Jul 2015 15:32:52 +0000 (UTC) Received: (qmail 60903 invoked by uid 99); 3 Jul 2015 15:32:52 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Jul 2015 15:32:52 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D8872E361D; Fri, 3 Jul 2015 15:32:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.incubator.apache.org Date: Fri, 03 Jul 2015 15:32:56 -0000 Message-Id: In-Reply-To: <9345ed959fad4b3b89436bc332f06d8e@git.apache.org> References: <9345ed959fad4b3b89436bc332f06d8e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [06/28] incubator-ignite git commit: # ignite-gg-10416 Exclude nested beans only if exclude properties exists(visor). # ignite-gg-10416 Exclude nested beans only if exclude properties exists(visor). Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/0acdc2f9 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/0acdc2f9 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/0acdc2f9 Branch: refs/heads/ignite-648 Commit: 0acdc2f9f56d1c1f104de82211b38e36388ddb43 Parents: e5fba8b Author: Andrey Authored: Thu Jun 18 18:15:53 2015 +0700 Committer: Andrey Committed: Thu Jun 18 18:21:49 2015 +0700 ---------------------------------------------------------------------- .../util/spring/IgniteSpringHelperImpl.java | 93 +++++++++++--------- .../IgniteExcludeInConfigurationTest.java | 78 ++++++++++++++++ .../IgniteStartExcludesConfigurationTest.java | 80 ----------------- .../testsuites/IgniteSpringTestSuite.java | 2 +- 4 files changed, 129 insertions(+), 124 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0acdc2f9/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java b/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java index df53ca7..6cfca36 100644 --- a/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java +++ b/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java @@ -421,63 +421,70 @@ public class IgniteSpringHelperImpl implements IgniteSpringHelper { private static GenericApplicationContext prepareSpringContext(final String... excludedProps){ GenericApplicationContext springCtx = new GenericApplicationContext(); - BeanFactoryPostProcessor postProc = new BeanFactoryPostProcessor() { - /** - * @param def Registered BeanDefinition. - * @throws BeansException in case of errors. - */ - private void processNested(BeanDefinition def) throws BeansException { - MutablePropertyValues vals = def.getPropertyValues(); - - for (PropertyValue val : new ArrayList<>(vals.getPropertyValueList())) { - for (String excludedProp : excludedProps) { - if (val.getName().equals(excludedProp)) { - vals.removePropertyValue(val); - - return; + if (excludedProps.length > 0) { + BeanFactoryPostProcessor postProc = new BeanFactoryPostProcessor() { + /** + * @param def Registered BeanDefinition. + * @throws BeansException in case of errors. + */ + private void processNested(BeanDefinition def) throws BeansException { + Iterator iterVals = def.getPropertyValues().getPropertyValueList().iterator(); + + while (iterVals.hasNext()) { + PropertyValue val = iterVals.next(); + + for (String excludedProp : excludedProps) { + if (val.getName().equals(excludedProp)) { + iterVals.remove(); + + return; + } } - } - if (val.getValue() instanceof Collection) { - Collection nestedVals = (Collection) val.getValue(); + if (val.getValue() instanceof Iterable) { + Iterator iterNested = ((Iterable)val.getValue()).iterator(); - for (Object item : new ArrayList<>(nestedVals)) - if (item instanceof BeanDefinitionHolder) { - BeanDefinitionHolder holder = (BeanDefinitionHolder)item; + while (iterNested.hasNext()) { + Object item = iterNested.next(); - try { - if (holder.getBeanDefinition().getBeanClassName() != null) - Class.forName(holder.getBeanDefinition().getBeanClassName()); + if (item instanceof BeanDefinitionHolder) { + BeanDefinitionHolder h = (BeanDefinitionHolder)item; - processNested(holder.getBeanDefinition()); - } - catch (ClassNotFoundException ignored) { - nestedVals.remove(item); + try { + if (h.getBeanDefinition().getBeanClassName() != null) + Class.forName(h.getBeanDefinition().getBeanClassName()); + + processNested(h.getBeanDefinition()); + } + catch (ClassNotFoundException ignored) { + iterNested.remove(); + } } } + } } } - } - /** {@inheritDoc} */ - @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) - throws BeansException { - for (String beanName : beanFactory.getBeanDefinitionNames()) - try { - BeanDefinition def = beanFactory.getBeanDefinition(beanName); + @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) + throws BeansException { + for (String beanName : beanFactory.getBeanDefinitionNames()) { + try { + BeanDefinition def = beanFactory.getBeanDefinition(beanName); - if (def.getBeanClassName() != null) - Class.forName(def.getBeanClassName()); + if (def.getBeanClassName() != null) + Class.forName(def.getBeanClassName()); - processNested(def); - } - catch (ClassNotFoundException ignored) { - ((BeanDefinitionRegistry)beanFactory).removeBeanDefinition(beanName); + processNested(def); + } + catch (ClassNotFoundException ignored) { + ((BeanDefinitionRegistry)beanFactory).removeBeanDefinition(beanName); + } } - } - }; + } + }; - springCtx.addBeanFactoryPostProcessor(postProc); + springCtx.addBeanFactoryPostProcessor(postProc); + } return springCtx; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0acdc2f9/modules/spring/src/test/java/org/apache/ignite/spring/IgniteExcludeInConfigurationTest.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/apache/ignite/spring/IgniteExcludeInConfigurationTest.java b/modules/spring/src/test/java/org/apache/ignite/spring/IgniteExcludeInConfigurationTest.java new file mode 100644 index 0000000..1edca77 --- /dev/null +++ b/modules/spring/src/test/java/org/apache/ignite/spring/IgniteExcludeInConfigurationTest.java @@ -0,0 +1,78 @@ +/* + * 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.ignite.spring; + +import org.apache.ignite.cache.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.internal.util.spring.*; +import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.testframework.junits.common.*; + +import java.net.*; +import java.util.*; + +import static org.apache.ignite.internal.IgniteComponentType.*; + +/** + * Checks excluding properties, beans with not existing classes in spring. + */ +public class IgniteExcludeInConfigurationTest extends GridCommonAbstractTest { + private URL cfgLocation = U.resolveIgniteUrl( + "modules/spring/src/test/java/org/apache/ignite/spring/sprint-exclude.xml"); + + /** Spring should exclude properties by list and ignore beans with class not existing in classpath. */ + public void testExclude() throws Exception { + IgniteSpringHelper spring = SPRING.create(false); + + Collection cfgs = spring.loadConfigurations(cfgLocation, "typeMetadata").get1(); + + assertNotNull(cfgs); + assertEquals(1, cfgs.size()); + + IgniteConfiguration cfg = cfgs.iterator().next(); + + assertEquals(1, cfg.getCacheConfiguration().length); + assertNull(cfg.getCacheConfiguration()[0].getTypeMetadata()); + + cfgs = spring.loadConfigurations(cfgLocation, "keyType").get1(); + + assertNotNull(cfgs); + assertEquals(1, cfgs.size()); + + cfg = cfgs.iterator().next(); + + assertEquals(1, cfg.getCacheConfiguration().length); + + Collection typeMetadatas = cfg.getCacheConfiguration()[0].getTypeMetadata(); + + assertEquals(1, typeMetadatas.size()); + assertNull(typeMetadatas.iterator().next().getKeyType()); + } + + /** Spring should fail if bean class not exist in classpath. */ + public void testFail() throws Exception { + IgniteSpringHelper spring = SPRING.create(false); + + try { + assertNotNull(spring.loadConfigurations(cfgLocation).get1()); + } catch (Exception e) { + assertTrue(X.hasCause(e, ClassNotFoundException.class)); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0acdc2f9/modules/spring/src/test/java/org/apache/ignite/spring/IgniteStartExcludesConfigurationTest.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/apache/ignite/spring/IgniteStartExcludesConfigurationTest.java b/modules/spring/src/test/java/org/apache/ignite/spring/IgniteStartExcludesConfigurationTest.java deleted file mode 100644 index f1332e0..0000000 --- a/modules/spring/src/test/java/org/apache/ignite/spring/IgniteStartExcludesConfigurationTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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.ignite.spring; - -import org.apache.ignite.cache.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.internal.util.spring.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.testframework.junits.common.*; - -import java.net.*; -import java.util.*; - -import static org.apache.ignite.internal.IgniteComponentType.*; - -/** - * Checks exclude properties in spring, exclude beans with not existing classes. - */ -public class IgniteStartExcludesConfigurationTest extends GridCommonAbstractTest { - /** Tests spring exclude properties. */ - public void testExcludes() throws Exception { - URL cfgLocation = U.resolveIgniteUrl( - "modules/spring/src/test/java/org/apache/ignite/spring/sprint-exclude.xml"); - - IgniteSpringHelper spring = SPRING.create(false); - - Collection cfgs = spring.loadConfigurations(cfgLocation, "typeMetadata").get1(); - - assert cfgs != null && cfgs.size() == 1; - - IgniteConfiguration cfg = cfgs.iterator().next(); - - assert cfg.getCacheConfiguration().length == 1; - - assert cfg.getCacheConfiguration()[0].getTypeMetadata() == null; - - cfgs = spring.loadConfigurations(cfgLocation, "keyType").get1(); - - assert cfgs != null && cfgs.size() == 1; - - cfg = cfgs.iterator().next(); - - assert cfg.getCacheConfiguration().length == 1; - - Collection typeMetadatas = cfg.getCacheConfiguration()[0].getTypeMetadata(); - - assert typeMetadatas.size() == 1; - - assert typeMetadatas.iterator().next().getKeyType() == null; - - cfgs = spring.loadConfigurations(cfgLocation).get1(); - - assert cfgs != null && cfgs.size() == 1; - - cfg = cfgs.iterator().next(); - - assert cfg.getCacheConfiguration().length == 1; - - typeMetadatas = cfg.getCacheConfiguration()[0].getTypeMetadata(); - - assert typeMetadatas.size() == 1; - - assert "java.lang.Integer".equals(typeMetadatas.iterator().next().getKeyType()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0acdc2f9/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java b/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java index 3ff927a..75d29fb 100644 --- a/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java +++ b/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java @@ -40,7 +40,7 @@ public class IgniteSpringTestSuite extends TestSuite { suite.addTest(IgniteResourceSelfTestSuite.suite()); - suite.addTest(new TestSuite(IgniteStartExcludesConfigurationTest.class)); + suite.addTest(new TestSuite(IgniteExcludeInConfigurationTest.class)); // Tests moved to this suite since they require Spring functionality. suite.addTest(new TestSuite(GridP2PUserVersionChangeSelfTest.class));