aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1738115 - in /aries/trunk/blueprint/blueprint-maven-plugin/src: main/java/org/apache/aries/blueprint/plugin/model/ test/java/org/apache/aries/blueprint/plugin/ test/java/org/apache/aries/blueprint/plugin/test/
Date Thu, 07 Apr 2016 09:19:53 GMT
Author: cschneider
Date: Thu Apr  7 09:19:53 2016
New Revision: 1738115

URL: http://svn.apache.org/viewvc?rev=1738115&view=rev
Log:
[ARIES-1521] Inject constructor parameters without @Inject when class has only one constructor

Added:
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean6.java
Modified:
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean5.java

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java?rev=1738115&r1=1738114&r2=1738115&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
Thu Apr  7 09:19:53 2016
@@ -6,9 +6,9 @@
  * 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>
+ * <p/>
  * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ * <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
@@ -90,10 +90,11 @@ public class Bean extends BeanRef {
     }
 
     private void resolveConstructorArguments(Matcher matcher) {
-        for (Constructor constructor : clazz.getDeclaredConstructors()) {
+        Constructor<?>[] declaredConstructors = clazz.getDeclaredConstructors();
+        for (Constructor constructor : declaredConstructors) {
             Annotation inject = constructor.getAnnotation(Inject.class);
             Annotation autowired = constructor.getAnnotation(Autowired.class);
-            if (inject != null || autowired != null) {
+            if (inject != null || autowired != null || declaredConstructors.length == 1)
{
                 Class[] parameterTypes = constructor.getParameterTypes();
                 Annotation[][] parameterAnnotations = constructor.getParameterAnnotations();
                 for (int i = 0; i < parameterTypes.length; ++i) {

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java?rev=1738115&r1=1738114&r2=1738115&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java
Thu Apr  7 09:19:53 2016
@@ -172,6 +172,13 @@ public class GeneratorTest {
     }
 
     @Test
+    public void testGenerateBeanWithConstructorInjectionWithoutInjectAnnotation() throws
Exception {
+        // Bean with constructor injection
+        Node myBean6 = getBeanById("myBean6");
+        assertEquals("my2", xpath.evaluate("argument[1]/@ref", myBean6));
+    }
+
+    @Test
     public void testGenerateReferenceWithComponentName() throws Exception {
         Node ser1 = getReferenceById("ser1");
         assertEquals("myRef", xpath.evaluate("@component-name", ser1));

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean5.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean5.java?rev=1738115&r1=1738114&r2=1738115&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean5.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean5.java
Thu Apr  7 09:19:53 2016
@@ -6,9 +6,9 @@
  * 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>
+ * <p/>
  * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ * <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
@@ -59,4 +59,7 @@ public class MyBean5 {
         this.myReference2 = myReference2;
         this.serviceAAnnotated = serviceAAnnotated;
     }
+
+    public MyBean5() {
+    }
 }

Added: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean6.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean6.java?rev=1738115&view=auto
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean6.java
(added)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean6.java
Thu Apr  7 09:19:53 2016
@@ -0,0 +1,32 @@
+/**
+ * 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 org.apache.aries.blueprint.plugin.test;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+@Singleton
+public class MyBean6 {
+
+    private final ServiceA serviceA1;
+
+    public MyBean6(@Named("my2") ServiceA serviceA1) {
+        this.serviceA1 = serviceA1;
+    }
+}



Mime
View raw message