aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alien11...@apache.org
Subject svn commit: r1746944 - in /aries/trunk/blueprint/blueprint-maven-plugin/src: main/java/org/apache/aries/blueprint/plugin/ main/java/org/apache/aries/blueprint/plugin/model/ test/java/org/apache/aries/blueprint/plugin/
Date Sun, 05 Jun 2016 19:41:46 GMT
Author: alien11689
Date: Sun Jun  5 19:41:46 2016
New Revision: 1746944

URL: http://svn.apache.org/viewvc?rev=1746944&view=rev
Log:
[ARIES-1563] Add field-injection attribute only if bean needs it

Modified:
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java?rev=1746944&r1=1746943&r2=1746944&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java
Sun Jun  5 19:41:46 2016
@@ -145,7 +145,9 @@ public class Generator implements Proper
         writer.writeStartElement("bean");
         writer.writeAttribute("id", bean.id);
         writer.writeAttribute("class", bean.clazz.getName());
-        writer.writeAttribute("ext", NS_EXT, "field-injection", "true");
+        if(bean.needFieldInjection()) {
+            writer.writeAttribute("ext", NS_EXT, "field-injection", "true");
+        }
         if (bean.isPrototype) {
             writer.writeAttribute("scope", "prototype");
         }

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=1746944&r1=1746943&r2=1746944&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
Sun Jun  5 19:41:46 2016
@@ -200,4 +200,12 @@ public class Bean extends BeanRef {
     }
 
 
+    public boolean needFieldInjection() {
+        for (Property property : properties) {
+            if (property.isField) {
+                return true;
+            }
+        }
+        return false;
+    }
 }

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java?rev=1746944&r1=1746943&r2=1746944&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java
Sun Jun  5 19:41:46 2016
@@ -29,14 +29,16 @@ import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 
 public class Property implements Comparable<Property> {
-    public String name;
-    public String ref;
-    public String value;
+    public final String name;
+    public final String ref;
+    public final String value;
+    public final boolean isField;
 
-    public Property(String name, String ref, String value) {
+    public Property(String name, String ref, String value, boolean isField) {
         this.name = name;
         this.ref = ref;
         this.value = value;
+        this.isField = isField;
     }
 
     public static Property create(Matcher matcher, Field field) {
@@ -44,9 +46,9 @@ public class Property implements Compara
         if (needsInject(field)) {
             BeanRef matching = matcher.getMatching(new BeanRef(field));
             String ref = (matching == null) ? getRefName(field) : matching.id;
-            return new Property(field.getName(), ref, null);
+            return new Property(field.getName(), ref, null, true);
         } else if (value != null) {
-            return new Property(field.getName(), null, cleanValue(value.value()));
+            return new Property(field.getName(), null, cleanValue(value.value()), true);
         } else {
             // Field is not a property
             return null;
@@ -61,14 +63,14 @@ public class Property implements Compara
 
         Value value = method.getAnnotation(Value.class);
         if (value != null) {
-            return new Property(propertyName, null, cleanValue(value.value()));
+            return new Property(propertyName, null, cleanValue(value.value()), false);
         }
 
         if (needsInject(method)) {
             BeanRef beanRef = new BeanRef(method);
             BeanRef matching = matcher.getMatching(beanRef);
             String ref = (matching == null) ? beanRef.id : matching.id;
-            return new Property(propertyName, ref, null);
+            return new Property(propertyName, ref, null, false);
         }
 
         return null;

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=1746944&r1=1746943&r2=1746944&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
Sun Jun  5 19:41:46 2016
@@ -164,6 +164,7 @@ public class GeneratorTest {
     public void testGenerateBeanWithConstructorInjection() throws Exception {
         // Bean with constructor injection
         Node myBean5 = getBeanById("myBean5");
+        assertXpathDoesNotExist(myBean5, "@field-injection");
         assertXpathEquals(myBean5, "argument[1]/@ref", "my2");
         assertXpathEquals(myBean5, "argument[2]/@ref", "my1");
         assertXpathEquals(myBean5, "argument[3]/@ref", "serviceABImpl");
@@ -266,6 +267,7 @@ public class GeneratorTest {
     @Test
     public void testSetterInjection() throws Exception {
         Node bean1 = getBeanById("beanWithSetters");
+        assertXpathDoesNotExist(bean1, "@field-injection");
 
         assertXpathDoesNotExist(bean1, "property[@name='useless']");
         assertXpathDoesNotExist(bean1, "property[@name='iOnlyHaveSetPrefix']");



Mime
View raw message