incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1052277 - in /incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook: SpiFly/src/org/apache/aries/spifly/ SpiFlyTests/src/org/apache/aries/spifly/ SpiFlyTests/src/org/apache/aries/spifly/impl2_123/ SpiFlyTests/src/org/apache/aries/s...
Date Thu, 23 Dec 2010 14:22:19 GMT
Author: davidb
Date: Thu Dec 23 14:22:18 2010
New Revision: 1052277

URL: http://svn.apache.org/viewvc?rev=1052277&view=rev
Log:
Add bundle version support.

Added:
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/impl2_123/
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/impl2_123/META-INF/
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/impl2_123/META-INF/services/
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/impl2_123/META-INF/services/org.apache.aries.mytest.MySPI
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/impl2_123/MySPIImpl2B.java
Modified:
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/ClientWeavingHook.java
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/Pair.java
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/ClientWeavingHookTest.java

Modified: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/ClientWeavingHook.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/ClientWeavingHook.java?rev=1052277&r1=1052276&r2=1052277&view=diff
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/ClientWeavingHook.java
(original)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/ClientWeavingHook.java
Thu Dec 23 14:22:18 2010
@@ -30,6 +30,7 @@ import org.objectweb.asm.ClassReader;
 import org.objectweb.asm.ClassWriter;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Version;
 import org.osgi.framework.hooks.weaving.WeavingHook;
 import org.osgi.framework.hooks.weaving.WovenClass;
 import org.osgi.service.log.LogService;
@@ -82,9 +83,12 @@ public class ClientWeavingHook implement
 	 * 
 	 * The following attributes are supported:
 	 * <ul>
-	 * <li><tt>bundle</tt> - restrict wiring to the bundle with the specifies
Symbolic Name.
+	 * <li><tt>bundle</tt> - restrict wiring to the bundle with the specifies
Symbolic Name. The attribute value 
+	 * is a list of bundle identifiers separated by a '|' sign. The bundle identifier starts
with the Symbolic name
+	 * and can optionally contain a version suffix. E.g. bundle=impl2:version=1.2.3 or bundle=impl2|impl4.
 
 	 * <li><tt>bundleId</tt> - restrict wiring to the bundle with the specified
bundle ID. Typically used when 
-	 * the service should be forceably picked up from the system bundle (<tt>bundleId=0</tt>).
+	 * the service should be forceably picked up from the system bundle (<tt>bundleId=0</tt>).
Multiple bundle IDs 
+	 * can be specified separated by a '|' sign. 
 	 * </ul>
 	 * 
 	 * @param consumerBundle the consuming bundle.
@@ -161,13 +165,23 @@ public class ClientWeavingHook implement
                 bsn = bsn.trim();
                 if (bsn.length() > 0) {
                     for (String s : bsn.split("\\|")) {
-                        allowedBundles.add(new BundleDescriptor(s));                    
   
+                        int colonIdx = s.indexOf(':');
+                        if (colonIdx > 0) {
+                            String sn = s.substring(0, colonIdx);
+                            String versionSfx = s.substring(colonIdx + 1);
+                            if (versionSfx.startsWith("version=")) {
+                                allowedBundles.add(new BundleDescriptor(sn, 
+                                        Version.parseVersion(versionSfx.substring("version=".length()))));
+                            } else {
+                                allowedBundles.add(new BundleDescriptor(sn));
+                            }
+                        } else {
+                            allowedBundles.add(new BundleDescriptor(s));
+                        }
                     }
                 }
             }
-            
-            // TODO bundle version
-            
+                        
             String bid = element.getAttribute("bundleId");
             if (bid != null) {
                 bid = bid.trim();

Modified: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/Pair.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/Pair.java?rev=1052277&r1=1052276&r2=1052277&view=diff
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/Pair.java
(original)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFly/src/org/apache/aries/spifly/Pair.java
Thu Dec 23 14:22:18 2010
@@ -54,7 +54,7 @@ public class Pair <A, B> {
         if (getClass() != obj.getClass())
             return false;
         
-        Pair other = (Pair) obj;
+        Pair<?, ?> other = (Pair<?, ?>) obj;
         if (left == null) {
             if (other.left != null)
                 return false;

Modified: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/ClientWeavingHookTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/ClientWeavingHookTest.java?rev=1052277&r1=1052276&r2=1052277&view=diff
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/ClientWeavingHookTest.java
(original)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/ClientWeavingHookTest.java
Thu Dec 23 14:22:18 2010
@@ -186,11 +186,11 @@ public class ClientWeavingHookTest {
     @Test
     public void testClientSpecifyingProviderVersion() throws Exception {
         Dictionary<String, String> headers = new Hashtable<String, String>();
-        headers.put(SpiFlyConstants.SPI_CONSUMER_HEADER, "java.util.ServiceLoader#load(java.lang.Class);bundle=impl2;version=1.2.3");
+        headers.put(SpiFlyConstants.SPI_CONSUMER_HEADER, "java.util.ServiceLoader#load(java.lang.Class);bundle=impl2:version=1.2.3");
 
         Bundle providerBundle1 = mockProviderBundle("impl1", 1);
         Bundle providerBundle2 = mockProviderBundle("impl2", 2);
-        Bundle providerBundle3 = mockProviderBundle("impl2", 3, new Version(1, 2, 3));
+        Bundle providerBundle3 = mockProviderBundle("impl2_123", 3, new Version(1, 2, 3));
         Activator.activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle1);
         Activator.activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle2);
         Activator.activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle3);
@@ -209,7 +209,7 @@ public class ClientWeavingHookTest {
         Class<?> cls = wc.getDefinedClass();
         Method method = cls.getMethod("test", new Class [] {String.class});
         Object result = method.invoke(cls.newInstance(), "hello");
-        Assert.assertEquals("Only the services from bundle impl2 should be selected", "Updated!Hello!Updated",
result);        
+        Assert.assertEquals("Only the services from bundle impl2 should be selected", "Updated!hello!Updated",
result);        
     }
 
     @Test
@@ -532,7 +532,12 @@ public class ClientWeavingHookTest {
         
         Bundle providerBundle = EasyMock.createMock(Bundle.class);
         EasyMock.expect(providerBundle.adapt(BundleWiring.class)).andReturn(bw).anyTimes();
-        EasyMock.expect(providerBundle.getSymbolicName()).andReturn(subdir).anyTimes();
+        String bsn = subdir;
+        int idx = bsn.indexOf('_');
+        if (idx > 0) {
+            bsn = bsn.substring(0, idx);
+        }
+        EasyMock.expect(providerBundle.getSymbolicName()).andReturn(bsn).anyTimes();
         EasyMock.expect(providerBundle.getBundleId()).andReturn(id).anyTimes();
         EasyMock.expect(providerBundle.getVersion()).andReturn(version).anyTimes();
         EasyMock.replay(providerBundle);

Added: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/impl2_123/META-INF/services/org.apache.aries.mytest.MySPI
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/impl2_123/META-INF/services/org.apache.aries.mytest.MySPI?rev=1052277&view=auto
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/impl2_123/META-INF/services/org.apache.aries.mytest.MySPI
(added)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/impl2_123/META-INF/services/org.apache.aries.mytest.MySPI
Thu Dec 23 14:22:18 2010
@@ -0,0 +1 @@
+org.apache.aries.spifly.impl2_123.MySPIImpl2B
\ No newline at end of file

Added: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/impl2_123/MySPIImpl2B.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/impl2_123/MySPIImpl2B.java?rev=1052277&view=auto
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/impl2_123/MySPIImpl2B.java
(added)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/impl2_123/MySPIImpl2B.java
Thu Dec 23 14:22:18 2010
@@ -0,0 +1,28 @@
+/**
+ * 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.spifly.impl2_123;
+
+import org.apache.aries.mytest.MySPI;
+
+public class MySPIImpl2B implements MySPI {
+    @Override
+    public String someMethod(String s) {
+        return "Updated!" + s + "!Updated";
+    }
+}



Mime
View raw message