aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mahrw...@apache.org
Subject svn commit: r1124166 - in /aries/trunk/blueprint: ./ blueprint-annotation-impl/src/main/java/org/apache/aries/blueprint/annotation/impl/ blueprint-annotation-itest/ blueprint-annotation-itest/src/test/java/org/apache/aries/blueprint/itests/ blueprint-s...
Date Wed, 18 May 2011 10:11:42 GMT
Author: mahrwald
Date: Wed May 18 10:11:41 2011
New Revision: 1124166

URL: http://svn.apache.org/viewvc?rev=1124166&view=rev
Log:
ARIES-654: Don't blow up when annotations are in fragments

Added:
    aries/trunk/blueprint/blueprint-sample-fragment/
    aries/trunk/blueprint/blueprint-sample-fragment/pom.xml
    aries/trunk/blueprint/blueprint-sample-fragment/src/
    aries/trunk/blueprint/blueprint-sample-fragment/src/main/
    aries/trunk/blueprint/blueprint-sample-fragment/src/main/java/
    aries/trunk/blueprint/blueprint-sample-fragment/src/main/java/org/
    aries/trunk/blueprint/blueprint-sample-fragment/src/main/java/org/apache/
    aries/trunk/blueprint/blueprint-sample-fragment/src/main/java/org/apache/aries/
    aries/trunk/blueprint/blueprint-sample-fragment/src/main/java/org/apache/aries/blueprint/
    aries/trunk/blueprint/blueprint-sample-fragment/src/main/java/org/apache/aries/blueprint/frament/
    aries/trunk/blueprint/blueprint-sample-fragment/src/main/java/org/apache/aries/blueprint/frament/FragmentBean.java
Modified:
    aries/trunk/blueprint/blueprint-annotation-impl/src/main/java/org/apache/aries/blueprint/annotation/impl/BlueprintAnnotationScannerImpl.java
    aries/trunk/blueprint/blueprint-annotation-itest/pom.xml
    aries/trunk/blueprint/blueprint-annotation-itest/src/test/java/org/apache/aries/blueprint/itests/BlueprintAnnotationTest.java
    aries/trunk/blueprint/pom.xml

Modified: aries/trunk/blueprint/blueprint-annotation-impl/src/main/java/org/apache/aries/blueprint/annotation/impl/BlueprintAnnotationScannerImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-annotation-impl/src/main/java/org/apache/aries/blueprint/annotation/impl/BlueprintAnnotationScannerImpl.java?rev=1124166&r1=1124165&r2=1124166&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-annotation-impl/src/main/java/org/apache/aries/blueprint/annotation/impl/BlueprintAnnotationScannerImpl.java
(original)
+++ aries/trunk/blueprint/blueprint-annotation-impl/src/main/java/org/apache/aries/blueprint/annotation/impl/BlueprintAnnotationScannerImpl.java
Wed May 18 10:11:41 2011
@@ -25,8 +25,11 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
@@ -60,7 +63,6 @@ import org.apache.aries.blueprint.jaxb.T
 import org.apache.aries.blueprint.jaxb.TreferenceListener;
 import org.apache.aries.blueprint.jaxb.TregistrationListener;
 import org.apache.aries.blueprint.jaxb.Tservice;
-import org.apache.aries.blueprint.jaxb.TserviceProperties;
 import org.apache.aries.blueprint.jaxb.TservicePropertyEntry;
 import org.apache.aries.blueprint.jaxb.TtypeConverters;
 import org.apache.aries.blueprint.jaxb.Tvalue;
@@ -73,7 +75,7 @@ import org.osgi.service.packageadmin.Pac
 
 public class BlueprintAnnotationScannerImpl implements
         BlueprintAnnotationScanner {
-    private BundleContext context;
+    private final BundleContext context;
 
     public BlueprintAnnotationScannerImpl(BundleContext bc) {
         this.context = bc;
@@ -167,10 +169,11 @@ public class BlueprintAnnotationScannerI
     private Tblueprint generateBlueprintModel(Bundle bundle) {
         BundleAnnotationFinder baf = createBundleAnnotationFinder(bundle);
 
-        List<Class> blueprintClasses = baf.findAnnotatedClasses(Blueprint.class);
-        List<Class> beanClasses = baf.findAnnotatedClasses(Bean.class);
-        List<Class> refListenerClasses = baf.findAnnotatedClasses(ReferenceListener.class);
-        List<Class> regListenerClasses = baf.findAnnotatedClasses(RegistrationListener.class);
+        // we don't trust baf when it comes to returning classes just once (ARIES-654)
+        Set<Class> blueprintClasses = new LinkedHashSet<Class>(baf.findAnnotatedClasses(Blueprint.class));
+        Set<Class> beanClasses = new HashSet<Class>(baf.findAnnotatedClasses(Bean.class));
+        Set<Class> refListenerClasses = new HashSet<Class>(baf.findAnnotatedClasses(ReferenceListener.class));
+        Set<Class> regListenerClasses = new HashSet<Class>(baf.findAnnotatedClasses(RegistrationListener.class));
         Map<String, TreferenceListener> reflMap = new HashMap<String, TreferenceListener>();
         Map<String, TregistrationListener> reglMap = new HashMap<String, TregistrationListener>();
         
@@ -179,7 +182,7 @@ public class BlueprintAnnotationScannerI
         
         if (!blueprintClasses.isEmpty()) {
             // use the first annotated blueprint annotation
-            Blueprint blueprint = (Blueprint)blueprintClasses.get(0).getAnnotation(Blueprint.class);
+            Blueprint blueprint = (Blueprint)blueprintClasses.iterator().next().getAnnotation(Blueprint.class);
             tblueprint.setDefaultActivation(blueprint.defaultActivation());
             tblueprint.setDefaultAvailability(blueprint.defaultAvailability());
             tblueprint.setDefaultTimeout(convertToBigInteger(blueprint.defaultTimeout()));
@@ -301,12 +304,12 @@ public class BlueprintAnnotationScannerI
                 if (fields[i].isAnnotationPresent(Inject.class)) { 
                     if (fields[i].isAnnotationPresent(Reference.class)) {
                         // the field is also annotated with @Reference
-                        Reference ref = (Reference)fields[i].getAnnotation(Reference.class);
+                        Reference ref = fields[i].getAnnotation(Reference.class);
                         Treference tref = generateTref(ref, reflMap);
                         components.add(tref);
                     } else if (fields[i].isAnnotationPresent(ReferenceList.class)) {
                         // the field is also annotated with @ReferenceList
-                        ReferenceList ref = (ReferenceList)fields[i].getAnnotation(ReferenceList.class);
+                        ReferenceList ref = fields[i].getAnnotation(ReferenceList.class);
                         TreferenceList tref = generateTrefList(ref, reflMap);
                         components.add(tref);
                         

Modified: aries/trunk/blueprint/blueprint-annotation-itest/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-annotation-itest/pom.xml?rev=1124166&r1=1124165&r2=1124166&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-annotation-itest/pom.xml (original)
+++ aries/trunk/blueprint/blueprint-annotation-itest/pom.xml Wed May 18 10:11:41 2011
@@ -87,6 +87,12 @@
         </dependency>        
         <dependency>
             <groupId>org.apache.aries.blueprint</groupId>
+            <artifactId>org.apache.aries.blueprint.sample-fragment</artifactId>
+            <version>0.3.2-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>        
+        <dependency>
+            <groupId>org.apache.aries.blueprint</groupId>
             <artifactId>org.apache.aries.blueprint.testbundlea</artifactId>
             <scope>test</scope>
             <version>0.3.2-SNAPSHOT</version>

Modified: aries/trunk/blueprint/blueprint-annotation-itest/src/test/java/org/apache/aries/blueprint/itests/BlueprintAnnotationTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-annotation-itest/src/test/java/org/apache/aries/blueprint/itests/BlueprintAnnotationTest.java?rev=1124166&r1=1124165&r2=1124166&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-annotation-itest/src/test/java/org/apache/aries/blueprint/itests/BlueprintAnnotationTest.java
(original)
+++ aries/trunk/blueprint/blueprint-annotation-itest/src/test/java/org/apache/aries/blueprint/itests/BlueprintAnnotationTest.java
Wed May 18 10:11:41 2011
@@ -31,6 +31,7 @@ import static org.ops4j.pax.exam.CoreOpt
 import java.text.SimpleDateFormat;
 import java.util.Currency;
 import java.util.Hashtable;
+import java.util.List;
 import java.util.Set;
 
 import org.apache.aries.blueprint.sample.Bar;
@@ -39,7 +40,7 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
-import org.osgi.framework.Bundle;
+import org.osgi.framework.*;
 import org.osgi.service.blueprint.container.BlueprintContainer;
 import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
@@ -52,9 +53,9 @@ public class BlueprintAnnotationTest ext
         BlueprintContainer blueprintContainer = getBlueprintContainerForBundle(
                  bundleContext, "org.apache.aries.blueprint.sample-annotation",
                 5000);
-
+    
         assertNotNull(blueprintContainer);
-
+    
         Object obj = blueprintContainer.getComponentInstance("bar");
         assertNotNull(obj);
         assertEquals(Bar.class, obj.getClass());
@@ -74,7 +75,9 @@ public class BlueprintAnnotationTest ext
 
         assertTrue(foo.isInitialized());
         assertFalse(foo.isDestroyed());
-
+        
+        assertNotNull(blueprintContainer.getComponentInstance("fragment"));
+    
        obj = getOsgiService(bundleContext, Foo.class, null, 5000);
         assertNotNull(obj);
         assertEquals(foo.toString(), obj.toString());
@@ -104,6 +107,7 @@ public class BlueprintAnnotationTest ext
             mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint"),
             mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.annotation.impl"),
             mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.sample-annotation"),
+            mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.sample-fragment"),
             //mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.sample"),
             mavenBundle("org.osgi", "org.osgi.compendium"),
             //org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),

Added: aries/trunk/blueprint/blueprint-sample-fragment/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-sample-fragment/pom.xml?rev=1124166&view=auto
==============================================================================
--- aries/trunk/blueprint/blueprint-sample-fragment/pom.xml (added)
+++ aries/trunk/blueprint/blueprint-sample-fragment/pom.xml Wed May 18 10:11:41 2011
@@ -0,0 +1,91 @@
+<!--
+    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/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.aries</groupId>
+        <artifactId>java5-parent</artifactId>
+        <version>0.4</version>
+        <relativePath />
+    </parent>
+
+    <groupId>org.apache.aries.blueprint</groupId>
+    <artifactId>org.apache.aries.blueprint.sample-fragment</artifactId>
+    <name>Apache Aries Blueprint Sample Fragment for Testing Annotation</name>
+    <version>0.3.2-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+    <description>
+        Example blueprint application, mostly used for annotation tests.
+    </description>
+
+     <scm>
+         <connection>scm:svn:http://svn.apache.org/repos/asf/aries/trunk/blueprint/blueprint-sample-annotation</connection>
+         <developerConnection>scm:svn:https://svn.apache.org/repos/asf/aries/trunk/blueprint/blueprint-sample-annotation</developerConnection>
+         <url>http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-sample-annotation</url>
+     </scm>
+
+    <properties>
+		<aries.osgi.export>
+			org.apache.aries.blueprint.fragment;-noimport:=true
+		</aries.osgi.export>
+        <aries.osgi.import>
+            org.apache.aries.blueprint.annotation,
+            *
+        </aries.osgi.import>
+        <aries.osgi.private.pkg />
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.eclipse</groupId>
+            <artifactId>osgi</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.aries.blueprint</groupId>
+            <artifactId>org.apache.aries.blueprint.api</artifactId>
+            <version>0.3.2-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.aries.blueprint</groupId>
+            <artifactId>org.apache.aries.blueprint.annotation.api</artifactId>
+            <version>0.3.2-SNAPSHOT</version>
+        </dependency>
+    </dependencies>
+
+	<build>
+		<pluginManagement>
+			<plugins>
+				<plugin>
+					<groupId>org.apache.felix</groupId>
+					<artifactId>maven-bundle-plugin</artifactId>
+					<extensions>true</extensions>
+					<inherited>true</inherited>
+					<configuration>
+						<excludeDependencies>${aries.osgi.exclude.dependencies}</excludeDependencies>
+						<instructions>
+							<Fragment-Host>org.apache.aries.blueprint.sample-annotation</Fragment-Host>
+						</instructions>
+					</configuration>
+				</plugin>
+
+			</plugins>
+		</pluginManagement>
+	</build>
+    
+
+</project>

Added: aries/trunk/blueprint/blueprint-sample-fragment/src/main/java/org/apache/aries/blueprint/frament/FragmentBean.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-sample-fragment/src/main/java/org/apache/aries/blueprint/frament/FragmentBean.java?rev=1124166&view=auto
==============================================================================
--- aries/trunk/blueprint/blueprint-sample-fragment/src/main/java/org/apache/aries/blueprint/frament/FragmentBean.java
(added)
+++ aries/trunk/blueprint/blueprint-sample-fragment/src/main/java/org/apache/aries/blueprint/frament/FragmentBean.java
Wed May 18 10:11:41 2011
@@ -0,0 +1,23 @@
+/**
+ *  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.fragment;
+
+import org.apache.aries.blueprint.annotation.Bean;
+
+@Bean(id="fragment")
+public class FragmentBean {}
+

Modified: aries/trunk/blueprint/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/pom.xml?rev=1124166&r1=1124165&r2=1124166&view=diff
==============================================================================
--- aries/trunk/blueprint/pom.xml (original)
+++ aries/trunk/blueprint/pom.xml Wed May 18 10:11:41 2011
@@ -45,6 +45,7 @@
         <module>blueprint-annotation-api</module>
         <module>blueprint-annotation-impl</module>
         <module>blueprint-sample-annotation</module>
+        <module>blueprint-sample-fragment</module>
         <module>blueprint-testbundlea</module>
         <module>blueprint-testbundleb</module>
         <module>blueprint-testquiescebundle</module>



Mime
View raw message