Author: alien11689 Date: Sat Sep 30 16:29:03 2017 New Revision: 1810223 URL: http://svn.apache.org/viewvc?rev=1810223&view=rev Log: [ARIES-1745] Name beans from factories after method name
Added: aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/produced-bean-by-method-name/ aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/produced-bean-by-method-name/pom.xml aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/produced-bean-by-method-name/src/ aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/produced-bean-by-method-name/src/main/ aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/produced-bean-by-method-name/src/main/java/ aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/produced-bean-by-method-name/src/main/java/p1/ aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/produced-bean-by-method-name/src/main/java/p1/T1.java aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/produced-bean-by-method-name/verify.groovy Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanFromFactory.java Added: aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/produced-bean-by-method-name/pom.xml URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/produced-bean-by-method-name/pom.xml?rev=1810223&view=auto ============================================================================== --- aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/produced-bean-by-method-name/pom.xml (added) +++ aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/produced-bean-by-method-name/pom.xml Sat Sep 30 16:29:03 2017 @@ -0,0 +1,64 @@ +<!-- + 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.aries.blueprint.plugin.itest</groupId> + <artifactId>simple-project</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>jar</packaging> + + <dependencies> + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + <version>1</version> + </dependency> + <dependency> + <groupId>javax.enterprise</groupId> + <artifactId>cdi-api</artifactId> + <version>1.2</version> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>blueprint-maven-plugin</artifactId> + <version>@blueprint-maven-plugin.version@</version> + <executions> + <execution> + <goals> + <goal>add-resource-dir</goal> + <goal>blueprint-generate</goal> + </goals> + </execution> + </executions> + <configuration> + <customParameters> + <blueprint.beanFromFactory.name>fromFactoryMethodName</blueprint.beanFromFactory.name> + </customParameters> + </configuration> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file Added: aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/produced-bean-by-method-name/src/main/java/p1/T1.java URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/produced-bean-by-method-name/src/main/java/p1/T1.java?rev=1810223&view=auto ============================================================================== --- aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/produced-bean-by-method-name/src/main/java/p1/T1.java (added) +++ aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/produced-bean-by-method-name/src/main/java/p1/T1.java Sat Sep 30 16:29:03 2017 @@ -0,0 +1,36 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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 p1; + +import javax.enterprise.inject.Produces; +import javax.inject.Singleton; + +@Singleton +public class T1 { + + @Produces + public String bla1() { + return null; + } + + @Produces + public String bla2() { + return null; + } +} \ No newline at end of file Added: aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/produced-bean-by-method-name/verify.groovy URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/produced-bean-by-method-name/verify.groovy?rev=1810223&view=auto ============================================================================== --- aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/produced-bean-by-method-name/verify.groovy (added) +++ aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/produced-bean-by-method-name/verify.groovy Sat Sep 30 16:29:03 2017 @@ -0,0 +1,30 @@ +/* + * 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. + */ + +def file = new File(basedir, 'target/generated-sources/blueprint/OSGI-INF/blueprint/autowire.xml') +assert file.exists() +def xml = new groovy.util.XmlSlurper().parse(file) +assert xml.name() == 'blueprint' +assert xml.bean.find{ it.@class == 'p1.T1'}.@id == 't1' +assert xml.bean.find{ it.@id == 'bla1'}.'@class' == 'java.lang.String' +assert xml.bean.find{ it.@id == 'bla1'}.'@factory-ref' == 't1' +assert xml.bean.find{ it.@id == 'bla1'}.'@factory-method' == 'bla1' +assert xml.bean.find{ it.@id == 'bla2'}.'@class' == 'java.lang.String' +assert xml.bean.find{ it.@id == 'bla2'}.'@factory-ref' == 't1' +assert xml.bean.find{ it.@id == 'bla2'}.'@factory-method' == 'bla2' Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanFromFactory.java URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanFromFactory.java?rev=1810223&r1=1810222&r2=1810223&view=diff ============================================================================== --- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanFromFactory.java (original) +++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanFromFactory.java Sat Sep 30 16:29:03 2017 @@ -26,6 +26,8 @@ import org.apache.aries.blueprint.plugin import java.lang.reflect.Method; class BeanFromFactory extends Bean { + private static final String BLUEPRINT_BEAN_FROM_FACTORY_NAME_PROPERTY = "blueprint.beanFromFactory.name"; + private static final String BLUEPRINT_BEAN_FROM_FACTORY_NAME_PROPERTY_VALUE = "fromFactoryMethodName"; private final Method producingMethod; BeanFromFactory(Bean factoryBean, Method factoryMethod, ContextEnricher contextEnricher) { @@ -34,9 +36,9 @@ class BeanFromFactory extends Bean { if (forcedId != null) { this.id = forcedId; } -// if (forcedId == null && shouldGetBeanNameFromMethodName(contextEnricher)) { -// this.id = factoryMethod.getName(); -// } + if (forcedId == null && shouldGetBeanNameFromMethodName(contextEnricher)) { + this.id = factoryMethod.getName(); + } this.producingMethod = factoryMethod; setScope(factoryMethod); handleCustomBeanAnnotations(); @@ -45,8 +47,8 @@ class BeanFromFactory extends Bean { } private boolean shouldGetBeanNameFromMethodName(ContextEnricher contextEnricher) { - String beanFromFactoryName = contextEnricher.getBlueprintConfiguration().getCustomParameters().get("beanFromFactory.name"); - return "fromFactoryMethodName".equals(beanFromFactoryName); + String beanFromFactoryName = contextEnricher.getBlueprintConfiguration().getCustomParameters().get(BLUEPRINT_BEAN_FROM_FACTORY_NAME_PROPERTY); + return BLUEPRINT_BEAN_FROM_FACTORY_NAME_PROPERTY_VALUE.equals(beanFromFactoryName); } private void setScope(Method factoryMethod) {