aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From timothyjw...@apache.org
Subject svn commit: r1211078 - in /aries/trunk/application: application-itests/src/test/java/org/apache/aries/application/runtime/itests/ application-itests/src/test/resources/obr/aries.bundle1/ application-itests/src/test/resources/obr/aries.bundle1/OSGI-INF/...
Date Tue, 06 Dec 2011 20:05:53 GMT
Author: timothyjward
Date: Tue Dec  6 20:05:53 2011
New Revision: 1211078

URL: http://svn.apache.org/viewvc?rev=1211078&view=rev
Log:
ARIES-799: Honour collection types specified in blueprint service properties when modelling
blueprint services.

Added:
    aries/trunk/application/application-itests/src/test/resources/obr/aries.bundle1/OSGI-INF/
    aries/trunk/application/application-itests/src/test/resources/obr/aries.bundle1/OSGI-INF/blueprint/
    aries/trunk/application/application-itests/src/test/resources/obr/aries.bundle1/OSGI-INF/blueprint/sample-blueprint.xml
Modified:
    aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/OBRResolverAdvancedTest.java
    aries/trunk/application/application-itests/src/test/resources/obr/aries.bundle1/expectedRepository.xml
    aries/trunk/application/application-modeller-common-test/src/test/java/org/apache/aries/application/modelling/impl/ParserProxyTest.java
    aries/trunk/application/application-modeller-common-test/src/test/resources/appModeller/test1.eba/bundle1.jar/OSGI-INF/blueprint/bp.xml
    aries/trunk/application/application-modeller-common-test/src/test/resources/test.bundle/OSGI-INF/blueprint/bp.xml
    aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/AbstractParserProxy.java
    aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/OBRCapability.java
    aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/RepositoryGeneratorImpl.java

Modified: aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/OBRResolverAdvancedTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/OBRResolverAdvancedTest.java?rev=1211078&r1=1211077&r2=1211078&view=diff
==============================================================================
--- aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/OBRResolverAdvancedTest.java
(original)
+++ aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/OBRResolverAdvancedTest.java
Tue Dec  6 20:05:53 2011
@@ -169,7 +169,8 @@ public class OBRResolverAdvancedTest ext
     //create the bundle
     bundle = ArchiveFixture.newJar()
     .binary("META-INF/MANIFEST.MF", OBRResolverAdvancedTest.class.getClassLoader().getResourceAsStream("obr/aries.bundle1/META-INF/MANIFEST.MF")).end()
-    .binary("OSGI-INF/blueprint/blueprint.xml", OBRResolverAdvancedTest.class.getClassLoader().getResourceAsStream("obr/hello-world-client.xml")).end();
+    .binary("OSGI-INF/blueprint/blueprint.xml", OBRResolverAdvancedTest.class.getClassLoader().getResourceAsStream("obr/hello-world-client.xml")).end()
+    .binary("OSGI-INF/blueprint/anotherBlueprint.xml", OBRResolverAdvancedTest.class.getClassLoader().getResourceAsStream("obr/aries.bundle1/OSGI-INF/blueprint/sample-blueprint.xml")).end();
     fout = new FileOutputStream(REPO_BUNDLE + ".jar");
     bundle.writeOut(fout);
     fout.close();

Added: aries/trunk/application/application-itests/src/test/resources/obr/aries.bundle1/OSGI-INF/blueprint/sample-blueprint.xml
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-itests/src/test/resources/obr/aries.bundle1/OSGI-INF/blueprint/sample-blueprint.xml?rev=1211078&view=auto
==============================================================================
--- aries/trunk/application/application-itests/src/test/resources/obr/aries.bundle1/OSGI-INF/blueprint/sample-blueprint.xml
(added)
+++ aries/trunk/application/application-itests/src/test/resources/obr/aries.bundle1/OSGI-INF/blueprint/sample-blueprint.xml
Tue Dec  6 20:05:53 2011
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+  
+  <bean id="hello" class="org.apache.aries.sample.impl.HelloWorldImpl"/>
+  <service interface="org.apache.aries.sample.HelloWorld" ref="hello">
+    <service-properties>
+      <entry key="priority" value="9"/>
+      <entry key="volume" value="11"/>
+      <entry key="property.list" >
+        <list value-type="java.lang.String">
+          <value>1</value>
+          <value>2</value>
+          <value>3</value>
+          <value>2</value>
+          <value>1</value>
+        </list>
+      </entry>
+      <entry key="property.set" >
+        <set value-type="java.lang.String">
+          <value>1</value>
+          <value>2</value>
+          <value>3</value>
+          <value>2</value>
+          <value>1</value>
+        </set>
+      </entry>
+      <entry key="property.array" >
+        <array value-type="java.lang.String">
+          <value>1</value>
+          <value>2</value>
+          <value>3</value>
+          <value>2</value>
+          <value>1</value>
+        </array>
+      </entry>
+    </service-properties>
+  </service>
+  
+</blueprint>

Modified: aries/trunk/application/application-itests/src/test/resources/obr/aries.bundle1/expectedRepository.xml
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-itests/src/test/resources/obr/aries.bundle1/expectedRepository.xml?rev=1211078&r1=1211077&r2=1211078&view=diff
==============================================================================
--- aries/trunk/application/application-itests/src/test/resources/obr/aries.bundle1/expectedRepository.xml
(original)
+++ aries/trunk/application/application-itests/src/test/resources/obr/aries.bundle1/expectedRepository.xml
Tue Dec  6 20:05:53 2011
@@ -45,6 +45,17 @@
 <p n="objectClass" t="set" v="aries.ws.eba.export"/>
 <p n="service.ranking" v="0"/>
 </capability>
+<capability name="service">
+<p n="service" v="service"/>
+<p n="objectClass" t="set" v="org.apache.aries.sample.HelloWorld"/>
+<p n="service.ranking" v="0"/>
+<p n="osgi.service.blueprint.compname" v="hello"/>
+<p n="priority" v="9"/>
+<p n="volume" v="11"/>
+<p n="property.list" t="set" v="1, 2, 3, 2, 1"/>
+<p n="property.set" t="set" v="1, 2, 3"/>
+<p n="property.array" t="set" v="1, 2, 3, 2, 1"/>
+</capability>
 <require extend="false" filter="(&amp;(package=org.osgi.framework)(version&gt;=1.3.0))"
multiple="false" name="package" optional="false">Requires package with attributes {package=org.osgi.framework,
version=1.3.0}</require>
 <require extend="false" filter="(&amp;(package=aries.ws.event)(version&gt;=1.0.0))"
multiple="false" name="package" optional="false">Requires package with attributes {package=aries.ws.event,
version=1.0.0}</require>
 <require extend="false" filter="(&amp;(package=aries.wsspi.application.aries)(version&gt;=0.0.0)(company=yang)(mandatory:&lt;*company))"
multiple="false" name="package" optional="false">Requires package with attributes {package=aries.wsspi.application.aries,
version=0.0.0, company=yang}</require>

Modified: aries/trunk/application/application-modeller-common-test/src/test/java/org/apache/aries/application/modelling/impl/ParserProxyTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-modeller-common-test/src/test/java/org/apache/aries/application/modelling/impl/ParserProxyTest.java?rev=1211078&r1=1211077&r2=1211078&view=diff
==============================================================================
--- aries/trunk/application/application-modeller-common-test/src/test/java/org/apache/aries/application/modelling/impl/ParserProxyTest.java
(original)
+++ aries/trunk/application/application-modeller-common-test/src/test/java/org/apache/aries/application/modelling/impl/ParserProxyTest.java
Tue Dec  6 20:05:53 2011
@@ -35,6 +35,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.TreeSet;
 
 import org.apache.aries.application.modelling.ModellingManager;
 import org.apache.aries.application.modelling.ParsedServiceElements;
@@ -218,6 +219,10 @@ public class ParserProxyTest {
     Map<String, Object> props = new HashMap<String, Object>();
     props.put ("priority", "9");
     props.put("volume", "11");
+    props.put("property.list", Arrays.asList("1", "2", "3", "2", "1"));
+    //Deliberately miss off duplicate entries and reorder, the parser should still match
this
+    props.put("property.set", new TreeSet<String>(Arrays.asList("2", "3", "1")));
+    props.put("property.array", new String[]{"1", "2", "3", "2", "1"});
     props.put("osgi.service.blueprint.compname", "myBean");
     expectedResults.add(_modellingManager.getExportedService("myService", 0, Arrays.asList("foo.bar.MyService"),
props));
 

Modified: aries/trunk/application/application-modeller-common-test/src/test/resources/appModeller/test1.eba/bundle1.jar/OSGI-INF/blueprint/bp.xml
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-modeller-common-test/src/test/resources/appModeller/test1.eba/bundle1.jar/OSGI-INF/blueprint/bp.xml?rev=1211078&r1=1211077&r2=1211078&view=diff
==============================================================================
--- aries/trunk/application/application-modeller-common-test/src/test/resources/appModeller/test1.eba/bundle1.jar/OSGI-INF/blueprint/bp.xml
(original)
+++ aries/trunk/application/application-modeller-common-test/src/test/resources/appModeller/test1.eba/bundle1.jar/OSGI-INF/blueprint/bp.xml
Tue Dec  6 20:05:53 2011
@@ -28,6 +28,33 @@
   	<service-properties>
   	  <entry key="priority" value="9"/>
   	  <entry key="volume" value="11"/>
+  	  <entry key="property.list" >
+        <list value-type="java.lang.String">
+          <value>1</value>
+          <value>2</value>
+          <value>3</value>
+          <value>2</value>
+          <value>1</value>
+        </list>
+      </entry>
+      <entry key="property.set" >
+        <set value-type="java.lang.String">
+          <value>1</value>
+          <value>2</value>
+          <value>3</value>
+          <value>2</value>
+          <value>1</value>
+        </set>
+      </entry>
+      <entry key="property.array" >
+        <array value-type="java.lang.String">
+          <value>1</value>
+          <value>2</value>
+          <value>3</value>
+          <value>2</value>
+          <value>1</value>
+        </array>
+      </entry>
   	</service-properties>
   </service>
   

Modified: aries/trunk/application/application-modeller-common-test/src/test/resources/test.bundle/OSGI-INF/blueprint/bp.xml
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-modeller-common-test/src/test/resources/test.bundle/OSGI-INF/blueprint/bp.xml?rev=1211078&r1=1211077&r2=1211078&view=diff
==============================================================================
--- aries/trunk/application/application-modeller-common-test/src/test/resources/test.bundle/OSGI-INF/blueprint/bp.xml
(original)
+++ aries/trunk/application/application-modeller-common-test/src/test/resources/test.bundle/OSGI-INF/blueprint/bp.xml
Tue Dec  6 20:05:53 2011
@@ -25,10 +25,37 @@
   </bean>
   
   <service id="myService" ref="myBean" interface="foo.bar.MyService">
-  	<service-properties>
-  	  <entry key="priority" value="9"/>
-  	  <entry key="volume" value="11"/>
-  	</service-properties>
+    <service-properties>
+      <entry key="priority" value="9"/>
+      <entry key="volume" value="11"/>
+      <entry key="property.list" >
+        <list value-type="java.lang.String">
+          <value>1</value>
+          <value>2</value>
+          <value>3</value>
+          <value>2</value>
+          <value>1</value>
+        </list>
+      </entry>
+      <entry key="property.set" >
+        <set value-type="java.lang.String">
+          <value>1</value>
+          <value>2</value>
+          <value>3</value>
+          <value>2</value>
+          <value>1</value>
+        </set>
+      </entry>
+      <entry key="property.array" >
+        <array value-type="java.lang.String">
+          <value>1</value>
+          <value>2</value>
+          <value>3</value>
+          <value>2</value>
+          <value>1</value>
+        </array>
+      </entry>
+    </service-properties>
   </service>
   
   <!-- Services for which we can generate no name should not be exposed -->

Modified: aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/AbstractParserProxy.java
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/AbstractParserProxy.java?rev=1211078&r1=1211077&r2=1211078&view=diff
==============================================================================
--- aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/AbstractParserProxy.java
(original)
+++ aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/AbstractParserProxy.java
Tue Dec  6 20:05:53 2011
@@ -9,8 +9,10 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Queue;
 import java.util.Set;
 
 import org.apache.aries.application.InvalidAttributeException;
@@ -123,13 +125,7 @@ abstract public class AbstractParserProx
 	          
 	          Metadata value = entry.getValue();
 	          if (value instanceof CollectionMetadata) { 
-	            List<Metadata> values = ((CollectionMetadata)value).getValues();
-	            String[] theseValues = new String[values.size()];
-	            for (int i=0; i < values.size(); i++) { 
-	              Metadata m = values.get(i); 
-	              theseValues[i] = ((ValueMetadata)m).getStringValue();
-	            }
-	            serviceProps.put(key, theseValues);
+	            processMultiValueProperty(serviceProps, key, value);
 	          } else { 
 	            serviceProps.put(key, ((ValueMetadata)entry.getValue()).getStringValue());
 	          }
@@ -170,9 +166,46 @@ abstract public class AbstractParserProx
 	    }
 	    _logger.debug(LOG_EXIT, "parseAllServiceElements", new Object[]{result});
 	    return result; 
-	  }	  
+	  }
+    private void processMultiValueProperty(Map<String, Object> serviceProps,
+        String key, Metadata value) {
+      List<Metadata> values = ((CollectionMetadata)value).getValues();
+      Class<?> collectionClass = ((CollectionMetadata)value).getCollectionClass();
+      Object collectionValue;
+      
+      if(Collection.class.isAssignableFrom(collectionClass)) {
+        Collection<String> theseValues = getCollectionFromClass(collectionClass);
+        for(Metadata m : values) {
+          theseValues.add(((ValueMetadata)m).getStringValue());
+        }
+        collectionValue = theseValues;
+      } else {
+        String[] theseValues = new String[values.size()];
+        for (int i=0; i < values.size(); i++) { 
+          Metadata m = values.get(i); 
+          theseValues[i] = ((ValueMetadata)m).getStringValue();
+        }
+        collectionValue = theseValues;
+      }
+      serviceProps.put(key, collectionValue);
+    }	  
 	  
-	  /**
+	  private Collection<String> getCollectionFromClass(Class<?> collectionClass)
{
+	    
+	    if(List.class.isAssignableFrom(collectionClass)) {
+	      return new ArrayList<String>();
+	    } else if (Set.class.isAssignableFrom(collectionClass)) {
+	      return new HashSet<String>();
+	    } else if (Queue.class.isAssignableFrom(collectionClass)) {
+	      //This covers Queue and Deque, which is caught by the isAssignableFrom check
+	      //as a sub-interface of Queue
+	      return new LinkedList<String>();
+	    } else {
+	      throw new IllegalArgumentException(collectionClass.getName());
+	    }
+	  }
+	  
+    /**
 	   * Extract References metadata from a ComponentDefinitionRegistry. 
 	   * @param cdr                       ComponentDefinitionRegistry
 	   * @return List<WrappedReferenceMetadata>

Modified: aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/OBRCapability.java
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/OBRCapability.java?rev=1211078&r1=1211077&r2=1211078&view=diff
==============================================================================
--- aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/OBRCapability.java
(original)
+++ aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/OBRCapability.java
Tue Dec  6 20:05:53 2011
@@ -25,6 +25,7 @@ import static org.apache.aries.applicati
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -99,6 +100,12 @@ public class OBRCapability implements Ca
           if (value instanceof String[]) {
             String newValue = Arrays.toString((String[])value);
             value = newValue.substring(1, newValue.length() - 1);
+          } else if (value instanceof Collection) {
+            //We can't rely on Collections having a sensible toString() as it isn't
+            //part of the API (although all base Java ones do). We can use an array
+            //to get consistency
+            String newValue = Arrays.toString(((Collection<?>)value).toArray());
+            value = newValue.substring(1, newValue.length() - 1);
           }
           
           return String.valueOf(value);
@@ -112,7 +119,7 @@ public class OBRCapability implements Ca
           if (Constants.VERSION_ATTRIBUTE.equals(name) || (Constants.BUNDLE_VERSION_ATTRIBUTE.equals(name)))
{
             type =  "version";
           } else if (Constants.OBJECTCLASS.equals(name) || (Constants.MANDATORY_DIRECTIVE
+ ":").equals(name) ||
-              entry.getValue() instanceof String[])
+              entry.getValue() instanceof String[] || entry.getValue() instanceof Collection)
             type = "set";
           return type;
         }

Modified: aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/RepositoryGeneratorImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/RepositoryGeneratorImpl.java?rev=1211078&r1=1211077&r2=1211078&view=diff
==============================================================================
--- aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/RepositoryGeneratorImpl.java
(original)
+++ aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/RepositoryGeneratorImpl.java
Tue Dec  6 20:05:53 2011
@@ -157,7 +157,7 @@ public final class RepositoryGeneratorIm
       String name = (String) entry.getName();
       String objectAttrs = entry.getValue();
 
-      String type = getType(name);
+      String type = (entry.getType() == null) ? getType(name) : entry.getType();
 
       // remove the beginning " and tailing "
       if (objectAttrs.startsWith("\"") && objectAttrs.endsWith("\""))



Mime
View raw message