aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1724452 - 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/bad/ test/java/org/apache/aries/blu...
Date Wed, 13 Jan 2016 16:24:47 GMT
Author: cschneider
Date: Wed Jan 13 16:24:46 2016
New Revision: 1724452

URL: http://svn.apache.org/viewvc?rev=1724452&view=rev
Log:
[ARIES-1481] Fix inheritance of @OsgiService and @PersistenceContext/Unit fields

@Inject fields are inherited from parent classes, but @OsgiService and
@PersistenceContext/Unit annotations on fields declared in parent classes
are ignored. This commit extracts the field-getting algorithm used for finding
@Inject fields to a utility method which is used for finding fields for the other
annotations.
It also detects clashing field names that would cause blueprint to throw an
exception, instead throwing an exception at blueprint xml generation.

Added:
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/FieldFinder.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean1.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean2.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean3.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/FieldBean4.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/ParentWithField.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/ParentWithInjectedField.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceReferencesParent.java
      - copied, changed from r1724284, aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceReferences.java
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/Context.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/ContextTest.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean1.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ParentBean.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceReferences.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=1724452&r1=1724451&r2=1724452&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
Wed Jan 13 16:24:46 2016
@@ -22,6 +22,7 @@ import java.io.OutputStream;
 import java.lang.reflect.Field;
 import java.util.Arrays;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import javax.persistence.PersistenceContext;
@@ -101,7 +102,7 @@ public class Generator implements Proper
     private boolean isJpaUsed() {
         boolean jpaUsed = false;
         for (Bean bean : context.getBeans()) {
-        if (bean.persistenceFields.length > 0) {
+        if (bean.persistenceFields.size() > 0) {
             jpaUsed = true;
         }
         }
@@ -182,7 +183,7 @@ public class Generator implements Proper
     }
 
 
-    private void writePersistenceFields(Field[] fields) throws XMLStreamException {
+    private void writePersistenceFields(List<Field> fields) throws XMLStreamException
{
         for (Field field : fields) {
             writePersistenceField(field);
         }

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=1724452&r1=1724451&r2=1724452&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
Wed Jan 13 16:24:46 2016
@@ -30,10 +30,13 @@ import java.util.TreeSet;
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
+import javax.inject.Inject;
 import javax.inject.Singleton;
 import javax.persistence.PersistenceContext;
 import javax.persistence.PersistenceUnit;
 
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 import com.google.common.base.Preconditions;
@@ -43,7 +46,7 @@ public class Bean extends BeanRef {
     public String initMethod;
     public String destroyMethod;
     public SortedSet<Property> properties;
-    public Field[] persistenceFields;
+    public List<Field> persistenceFields;
     public Set<TransactionalDef> transactionDefs = new HashSet<TransactionalDef>();
     public boolean isPrototype;
 
@@ -66,7 +69,7 @@ public class Bean extends BeanRef {
         transactionDefs.addAll(new JavaxTransactionFactory().create(clazz));
         transactionDefs.addAll(new SpringTransactionFactory().create(clazz));
         this.isPrototype = isPrototype(clazz);
-        this.persistenceFields = getPersistenceFields();
+        this.persistenceFields = new FieldFinder(PersistenceContext.class, PersistenceUnit.class).findFields(clazz);
         properties = new TreeSet<Property>();
     }
 
@@ -75,29 +78,8 @@ public class Bean extends BeanRef {
         return clazz.getAnnotation(Singleton.class) == null && clazz.getAnnotation(Component.class)
== null;
     }
 
-    private Field[] getPersistenceFields() {
-        List<Field> persistenceFields = new ArrayList<Field>();
-        Field[] fields = clazz.getDeclaredFields();
-        for (Field field : fields) {
-            PersistenceContext persistenceContext = field.getAnnotation(PersistenceContext.class);
-            PersistenceUnit persistenceUnit = field.getAnnotation(PersistenceUnit.class);
-            if (persistenceContext !=null || persistenceUnit != null) {
-                 persistenceFields.add(field);
-            }
-        }
-        return persistenceFields.toArray(new Field[]{});
-    }
-
     public void resolve(Matcher matcher) {
-        Class<?> curClass = this.clazz;
-        while (curClass != null && curClass != Object.class) {
-            resolveProperties(matcher, curClass);
-            curClass = curClass.getSuperclass();
-        }
-    }
-
-    private void resolveProperties(Matcher matcher, Class<?> curClass) {
-        for (Field field : curClass.getDeclaredFields()) {
+        for (Field field : new FieldFinder(Value.class, Autowired.class, Inject.class).findFields(clazz))
{
             Property prop = Property.create(matcher, field);
             if (prop != null) {
                 properties.add(prop);

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java?rev=1724452&r1=1724451&r2=1724452&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java
Wed Jan 13 16:24:46 2016
@@ -79,11 +79,8 @@ public class Context implements Matcher
     }
 
     private void addServiceRefs(Class<?> clazz) {
-        for (Field field : clazz.getDeclaredFields()) {
-            OsgiService osgiService = field.getAnnotation(OsgiService.class);
-            if (osgiService != null) {
-                reg.add(new OsgiServiceRef(field));
-            }
+        for (Field field : new FieldFinder(OsgiService.class).findFields(clazz)) {
+            reg.add(new OsgiServiceRef(field));
         }
     }
 
@@ -92,7 +89,7 @@ public class Context implements Matcher
             bean.resolve(this);
         }
     }
-    
+
     public BeanRef getMatching(BeanRef template) {
         for (BeanRef bean : reg) {
             if (bean.matches(template)) {

Added: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/FieldFinder.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/FieldFinder.java?rev=1724452&view=auto
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/FieldFinder.java
(added)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/FieldFinder.java
Wed Jan 13 16:24:46 2016
@@ -0,0 +1,98 @@
+/**
+ * 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.aries.blueprint.plugin.model;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Multimap;
+import com.google.common.collect.Sets;
+
+/**
+ * Class to find uniquely-named fields declared in a class hierarchy with specified annotations.
+ */
+public final class FieldFinder {
+    private final Class<? extends Annotation>[] requiredAnnotations;
+
+    /**
+     * @param requiredAnnotations if not empty, a field must have one of these annotations
for it to be found.
+     */
+    @SafeVarargs
+    public FieldFinder(Class<? extends Annotation>... requiredAnnotations) {
+        this.requiredAnnotations = requiredAnnotations;
+    }
+
+    /**
+     * @param originalClazz the class in which to find fields (including those defined in
parent classes).
+     * @return fields in the given class (including parent classes) that match this finder's
annotations requirements.
+     * @throws UnsupportedOperationException if any field matching the annotations requirement
shares its name with a
+     * field declared elsewhere in the class hierarchy.
+     */
+    public List<Field> findFields(Class<?> originalClazz) {
+        Multimap<String, Field> fieldsByName = HashMultimap.create();
+        Set<String> acceptedFieldNames = Sets.newHashSet();
+        Class<?> clazz = originalClazz;
+
+        // For each parent class of clazz...
+        while(clazz != null && clazz != Object.class) {
+            for (Field field : clazz.getDeclaredFields()) {
+                // ...add all declared fields
+                fieldsByName.put(field.getName(), field);
+
+                // ...and if it meets the annotation requirement, add the field name to the
set of accepted field names
+                if (hasAnyRequiredAnnotation(field))
+                    acceptedFieldNames.add(field.getName());
+            }
+            clazz = clazz.getSuperclass();
+        }
+
+        // Add all accepted fields to acceptedFields
+        List<Field> acceptedFields = Lists.newArrayList();
+        for (String acceptedFieldName : acceptedFieldNames) {
+            Collection<Field> acceptedFieldsWithSameName = fieldsByName.get(acceptedFieldName);
+
+            // Check that each field name is defined no more than once
+            if (acceptedFieldsWithSameName.size() > 1) {
+                String header = String.format("Field '%s' in bean class '%s' has been defined
multiple times in:",
+                                              acceptedFieldName, originalClazz.getName());
+                StringBuilder msgBuilder = new StringBuilder(header);
+                for (Field field : acceptedFieldsWithSameName)
+                    msgBuilder.append("\n\t- ").append(field.getDeclaringClass().getName());
+                throw new UnsupportedOperationException(msgBuilder.toString());
+            } else {
+                acceptedFields.addAll(acceptedFieldsWithSameName);
+            }
+        }
+        return acceptedFields;
+    }
+
+    private boolean hasAnyRequiredAnnotation(Field field) {
+        if (requiredAnnotations.length == 0)
+            return true;
+        for (Class<? extends Annotation> requiredAnnotation : requiredAnnotations)
+            if (field.getAnnotation(requiredAnnotation) != null)
+                return true;
+        return false;
+    }
+}

Added: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean1.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean1.java?rev=1724452&view=auto
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean1.java
(added)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean1.java
Wed Jan 13 16:24:46 2016
@@ -0,0 +1,13 @@
+package org.apache.aries.blueprint.plugin.bad;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.apache.aries.blueprint.plugin.test.MyBean1;
+
+@Singleton
+public class BadFieldBean1 extends ParentWithField
+{
+    @Inject
+    private MyBean1 field;
+}

Added: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean2.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean2.java?rev=1724452&view=auto
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean2.java
(added)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean2.java
Wed Jan 13 16:24:46 2016
@@ -0,0 +1,13 @@
+package org.apache.aries.blueprint.plugin.bad;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.apache.aries.blueprint.plugin.test.MyBean1;
+
+@Singleton
+public class BadFieldBean2 extends ParentWithInjectedField
+{
+    @Inject
+    private MyBean1 field;
+}

Added: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean3.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean3.java?rev=1724452&view=auto
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean3.java
(added)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean3.java
Wed Jan 13 16:24:46 2016
@@ -0,0 +1,11 @@
+package org.apache.aries.blueprint.plugin.bad;
+
+import javax.inject.Singleton;
+
+import org.apache.aries.blueprint.plugin.test.MyBean1;
+
+@Singleton
+public class BadFieldBean3 extends ParentWithInjectedField
+{
+    private MyBean1 field;
+}

Added: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/FieldBean4.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/FieldBean4.java?rev=1724452&view=auto
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/FieldBean4.java
(added)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/FieldBean4.java
Wed Jan 13 16:24:46 2016
@@ -0,0 +1,11 @@
+package org.apache.aries.blueprint.plugin.bad;
+
+import javax.inject.Singleton;
+
+import org.apache.aries.blueprint.plugin.test.MyBean1;
+
+@Singleton
+public class FieldBean4 extends ParentWithField
+{
+    private MyBean1 field;
+}

Added: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/ParentWithField.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/ParentWithField.java?rev=1724452&view=auto
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/ParentWithField.java
(added)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/ParentWithField.java
Wed Jan 13 16:24:46 2016
@@ -0,0 +1,8 @@
+package org.apache.aries.blueprint.plugin.bad;
+
+import org.apache.aries.blueprint.plugin.test.MyBean1;
+
+public class ParentWithField
+{
+    private MyBean1 field;
+}

Added: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/ParentWithInjectedField.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/ParentWithInjectedField.java?rev=1724452&view=auto
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/ParentWithInjectedField.java
(added)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/ParentWithInjectedField.java
Wed Jan 13 16:24:46 2016
@@ -0,0 +1,11 @@
+package org.apache.aries.blueprint.plugin.bad;
+
+import javax.inject.Inject;
+
+import org.apache.aries.blueprint.plugin.test.MyBean1;
+
+public class ParentWithInjectedField
+{
+    @Inject
+    private MyBean1 field;
+}

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java?rev=1724452&r1=1724451&r2=1724452&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java
Wed Jan 13 16:24:46 2016
@@ -30,6 +30,10 @@ import javax.inject.Named;
 import org.apache.aries.blueprint.plugin.bad.BadBean1;
 import org.apache.aries.blueprint.plugin.bad.BadBean2;
 import org.apache.aries.blueprint.plugin.bad.BadBean3;
+import org.apache.aries.blueprint.plugin.bad.BadFieldBean1;
+import org.apache.aries.blueprint.plugin.bad.BadFieldBean2;
+import org.apache.aries.blueprint.plugin.bad.BadFieldBean3;
+import org.apache.aries.blueprint.plugin.bad.FieldBean4;
 import org.apache.aries.blueprint.plugin.test.MyBean1;
 import org.apache.aries.blueprint.plugin.test.MyBean3;
 import org.apache.aries.blueprint.plugin.test.MyBean4;
@@ -49,9 +53,9 @@ public class BeanTest {
         assertEquals("myBean1", bean.id); // Name derived from class name
         assertEquals("init", bean.initMethod);
         assertEquals("destroy", bean.destroyMethod);
-        Assert.assertEquals(2, bean.persistenceFields.length);
-        assertEquals("em", bean.persistenceFields[0].getName());
-        assertEquals("emf", bean.persistenceFields[1].getName());
+        Assert.assertEquals(2, bean.persistenceFields.size());
+        assertEquals("em", bean.persistenceFields.get(0).getName());
+        assertEquals("emf", bean.persistenceFields.get(1).getName());
         assertEquals(1, bean.properties.size());
         assertFalse(bean.isPrototype);
         Property prop = bean.properties.iterator().next();
@@ -76,7 +80,7 @@ public class BeanTest {
         assertEquals("myBean3", bean.id); // Name derived from class name
         assertNull("There should be no initMethod", bean.initMethod);
         assertNull("There should be no destroyMethod", bean.destroyMethod);
-        assertEquals("There should be no persistence fields", 0, bean.persistenceFields.length);
+        assertEquals("There should be no persistence fields", 0, bean.persistenceFields.size());
         assertEquals(5, bean.properties.size());
         assertTrue(bean.isPrototype);
 
@@ -99,7 +103,7 @@ public class BeanTest {
         assertEquals("Name should be defined using @Named", definedName, bean.id);
         assertNull("There should be no initMethod", bean.initMethod);
         assertNull("There should be no destroyMethod", bean.destroyMethod);
-        assertEquals("There should be no persistence fields", 0, bean.persistenceFields.length);
+        assertEquals("There should be no persistence fields", 0, bean.persistenceFields.size());
         assertTrue("There should be no transaction definition", bean.transactionDefs.isEmpty());
         assertEquals("There should be no properties", 0, bean.properties.size());
         assertTrue(bean.isPrototype);
@@ -132,4 +136,24 @@ public class BeanTest {
     public void testSpringNestedTransactionNotSupported() {
         new Bean(BadBean3.class);
     }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testBadFieldBean1() {
+        new Context(BadFieldBean1.class).resolve();
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testBadFieldBean2() {
+        new Context(BadFieldBean2.class).resolve();
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testBadFieldBean3() {
+        new Context(BadFieldBean3.class).resolve();
+    }
+
+    @Test
+    public void testFieldBean4() {
+        new Context(FieldBean4.class).resolve();
+    }
 }

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/ContextTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/ContextTest.java?rev=1724452&r1=1724451&r2=1724452&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/ContextTest.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/ContextTest.java
Wed Jan 13 16:24:46 2016
@@ -25,6 +25,7 @@ import org.apache.aries.blueprint.plugin
 import org.apache.aries.blueprint.plugin.test.MyProduced;
 import org.apache.aries.blueprint.plugin.test.ServiceB;
 import org.apache.aries.blueprint.plugin.test.ServiceReferences;
+import org.apache.aries.blueprint.plugin.test.ServiceReferencesParent;
 import org.junit.Assert;
 import org.junit.Test;
 import org.osgi.framework.Bundle;
@@ -40,29 +41,29 @@ public class ContextTest {
         Assert.assertEquals(1, context.getBeans().size());
         Assert.assertEquals(0, context.getServiceRefs().size());
     }
-    
+
     @Test
     public void testLists2()  {
         Context context = new Context(ServiceReferences.class);
         Assert.assertEquals(1, context.getBeans().size());
         Assert.assertEquals(3, context.getServiceRefs().size());
     }
-    
+
     @Test
     public void testMatching() throws NoSuchFieldException, SecurityException  {
         Context context = new Context(ServiceReferences.class);
-        BeanRef matching = context.getMatching(new BeanRef(ServiceReferences.class.getDeclaredField("serviceB")));
+        BeanRef matching = context.getMatching(new BeanRef(ServiceReferencesParent.class.getDeclaredField("serviceB")));
         Assert.assertEquals(OsgiServiceRef.class, matching.getClass());
         Assert.assertEquals(ServiceB.class, matching.clazz);
         Assert.assertEquals("serviceB-typeB1", matching.id);
     }
-    
+
     private void assertSpecialRef(String expectedId, Class<?> clazz) {
         Context context = new Context();
         BeanRef ref = context.getMatching(new BeanRef(clazz));
         assertEquals(expectedId, ref.id);
     }
-    
+
     @Test
     public void testSpecialRefs() {
         assertSpecialRef("blueprintBundleContext", BundleContext.class);
@@ -70,7 +71,7 @@ public class ContextTest {
         assertSpecialRef("blueprintContainer", BlueprintContainer.class);
         assertSpecialRef("blueprintConverter", Converter.class);
     }
-    
+
     @Test
     public void testProduced() throws NoSuchFieldException, SecurityException  {
         Context context = new Context(MyFactoryBean.class);
@@ -80,5 +81,5 @@ public class ContextTest {
         Assert.assertEquals("myFactoryBean", matching.factoryBean.id);
         Assert.assertEquals("create", matching.factoryMethod);
     }
-    
+
 }

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean1.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean1.java?rev=1724452&r1=1724451&r2=1724452&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean1.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean1.java
Wed Jan 13 16:24:46 2016
@@ -20,27 +20,13 @@ package org.apache.aries.blueprint.plugi
 
 import javax.annotation.PostConstruct;
 import javax.inject.Singleton;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import javax.persistence.PersistenceUnit;
 import javax.transaction.Transactional;
 import javax.transaction.Transactional.TxType;
 
-import org.springframework.beans.factory.annotation.Autowired;
-
 @Singleton
 @Transactional(value=TxType.REQUIRES_NEW)
 public class MyBean1 extends ParentBean {
 
-    @Autowired
-    ServiceA bean2;
-
-    @PersistenceContext(unitName="person")
-    EntityManager em;
-
-    @PersistenceUnit(unitName="person")
-    EntityManager emf;
-
     public void overridenInit() {
         // By overriding the method and removing the annotation, this method has lost its
         // @PostConstruct method because it isn't @Inherited

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ParentBean.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ParentBean.java?rev=1724452&r1=1724451&r2=1724452&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ParentBean.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ParentBean.java
Wed Jan 13 16:24:46 2016
@@ -20,10 +20,24 @@ package org.apache.aries.blueprint.plugi
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceUnit;
 import javax.transaction.Transactional;
 
+import org.springframework.beans.factory.annotation.Autowired;
+
 public class ParentBean {
 
+    @Autowired
+    ServiceA bean2;
+
+    @PersistenceContext(unitName="person")
+    EntityManager em;
+
+    @PersistenceUnit(unitName="person")
+    EntityManager emf;
+
     @PostConstruct
     public void overridenInit() {
     }

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceReferences.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceReferences.java?rev=1724452&r1=1724451&r2=1724452&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceReferences.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceReferences.java
Wed Jan 13 16:24:46 2016
@@ -19,17 +19,9 @@
  */
 package org.apache.aries.blueprint.plugin.test;
 
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import org.ops4j.pax.cdi.api.OsgiService;
 import org.springframework.stereotype.Component;
 
 @Component
-public class ServiceReferences {
-    @Inject @OsgiService(filter="(type=B1)") ServiceB serviceB;
-    
-    @Named("serviceB2Id") @Inject @OsgiService(filter="(type=B2)") ServiceB serviceB2;
-    
-    @Inject @OsgiService(filter="(type=B3)") ServiceB serviceB3;
+public class ServiceReferences extends ServiceReferencesParent {
+
 }

Copied: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceReferencesParent.java
(from r1724284, aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceReferences.java)
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceReferencesParent.java?p2=aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceReferencesParent.java&p1=aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceReferences.java&r1=1724284&r2=1724452&rev=1724452&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceReferences.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceReferencesParent.java
Wed Jan 13 16:24:46 2016
@@ -1,4 +1,3 @@
-
 /**
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -23,13 +22,12 @@ import javax.inject.Inject;
 import javax.inject.Named;
 
 import org.ops4j.pax.cdi.api.OsgiService;
-import org.springframework.stereotype.Component;
 
-@Component
-public class ServiceReferences {
+public class ServiceReferencesParent
+{
     @Inject @OsgiService(filter="(type=B1)") ServiceB serviceB;
-    
+
     @Named("serviceB2Id") @Inject @OsgiService(filter="(type=B2)") ServiceB serviceB2;
-    
+
     @Inject @OsgiService(filter="(type=B3)") ServiceB serviceB3;
 }



Mime
View raw message