aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1088438 - in /aries/trunk: samples/blueprint/helloworld/helloworld-client/src/main/java/org/apache/aries/samples/blueprint/helloworld/client/ samples/blueprint/helloworld/helloworld-client/src/main/resources/OSGI-INF/blueprint/ spi-fly/spi...
Date Sun, 03 Apr 2011 23:33:13 GMT
Author: davidb
Date: Sun Apr  3 23:33:12 2011
New Revision: 1088438

URL: http://svn.apache.org/viewvc?rev=1088438&view=rev
Log:
More SPI-Fly refactoring.

Code base builds again but tests are failing.

Added:
    aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/ConsumerBundleTrackerCustomizer.java
    aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/spifly/AltTestClient.java.todo
      - copied unchanged from r1084722, aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/spifly/AltTestClient.java
    aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizerTest.java
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/mytest/
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/mytest/AltSPI.java
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/mytest/MySPI.java
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/spifly/
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/spifly/dynamic/
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/spifly/dynamic/ClientWeavingHookTest.java
      - copied, changed from r1084722, aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/spifly/ClientWeavingHookTest.java.todo
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/spifly/dynamic/TestClient.java
      - copied, changed from r1084722, aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/spifly/TestClient.java
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/spifly/dynamic/impl1/
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/spifly/dynamic/impl1/MySPIImpl1.java
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/resources/
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/resources/org/
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/resources/org/apache/
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/resources/org/apache/aries/
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/resources/org/apache/aries/spifly/
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/resources/org/apache/aries/spifly/dynamic/
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/resources/org/apache/aries/spifly/dynamic/impl1/
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/resources/org/apache/aries/spifly/dynamic/impl1/META-INF/
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/resources/org/apache/aries/spifly/dynamic/impl1/META-INF/services/
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/resources/org/apache/aries/spifly/dynamic/impl1/META-INF/services/org.apache.aries.mytest.MySPI
Removed:
    aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/mytest/AltSPI.java
    aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/spifly/AltTestClient.java
    aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/spifly/ClientWeavingHookTest.java.todo
    aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizerTest.java.todo
    aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/spifly/TestClient.java
    aries/trunk/spi-fly/spi-fly-core/src/test/resources/org/apache/aries/spifly/impl1/
Modified:
    aries/trunk/samples/blueprint/helloworld/helloworld-client/src/main/java/org/apache/aries/samples/blueprint/helloworld/client/HelloWorldClient.java
    aries/trunk/samples/blueprint/helloworld/helloworld-client/src/main/resources/OSGI-INF/blueprint/config.xml
    aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/BaseActivator.java
    aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/Util.java
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/pom.xml
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/main/java/org/apache/aries/spifly/dynamic/DynamicWeavingActivator.java
    aries/trunk/spi-fly/spi-fly-static-bundle/src/main/java/org/apache/aries/spifly/staticbundle/StaticWeavingActivator.java

Modified: aries/trunk/samples/blueprint/helloworld/helloworld-client/src/main/java/org/apache/aries/samples/blueprint/helloworld/client/HelloWorldClient.java
URL: http://svn.apache.org/viewvc/aries/trunk/samples/blueprint/helloworld/helloworld-client/src/main/java/org/apache/aries/samples/blueprint/helloworld/client/HelloWorldClient.java?rev=1088438&r1=1088437&r2=1088438&view=diff
==============================================================================
--- aries/trunk/samples/blueprint/helloworld/helloworld-client/src/main/java/org/apache/aries/samples/blueprint/helloworld/client/HelloWorldClient.java (original)
+++ aries/trunk/samples/blueprint/helloworld/helloworld-client/src/main/java/org/apache/aries/samples/blueprint/helloworld/client/HelloWorldClient.java Sun Apr  3 23:33:12 2011
@@ -26,8 +26,8 @@ public class HelloWorldClient {
 
         public void startUp() {
                 System.out.println("========>>>>Client HelloWorld: About to execute a method from the Hello World service");
-                helloWorldService.hello();
-                System.out.println("========>>>>Client HelloWorld: ... if you didn't just see a Hello World message something went wrong");
+                // helloWorldService.hello();
+                // System.out.println("========>>>>Client HelloWorld: ... if you didn't just see a Hello World message something went wrong");
         }
 
         public HelloWorldService getHelloWorldService() {

Modified: aries/trunk/samples/blueprint/helloworld/helloworld-client/src/main/resources/OSGI-INF/blueprint/config.xml
URL: http://svn.apache.org/viewvc/aries/trunk/samples/blueprint/helloworld/helloworld-client/src/main/resources/OSGI-INF/blueprint/config.xml?rev=1088438&r1=1088437&r2=1088438&view=diff
==============================================================================
--- aries/trunk/samples/blueprint/helloworld/helloworld-client/src/main/resources/OSGI-INF/blueprint/config.xml (original)
+++ aries/trunk/samples/blueprint/helloworld/helloworld-client/src/main/resources/OSGI-INF/blueprint/config.xml Sun Apr  3 23:33:12 2011
@@ -15,12 +15,13 @@
                 License.
         -->
 <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
-
+    <!--
         <reference id="helloservice"
                 interface="org.apache.aries.samples.blueprint.helloworld.api.HelloWorldService" />
+                <property name="helloWorldService" ref="helloservice" />
+                -->
 
         <bean id="helloclient" class="org.apache.aries.samples.blueprint.helloworld.client.HelloWorldClient"
                 init-method="startUp">
-                <property name="helloWorldService" ref="helloservice" />
         </bean>
 </blueprint>

Modified: aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/BaseActivator.java
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/BaseActivator.java?rev=1088438&r1=1088437&r2=1088438&view=diff
==============================================================================
--- aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/BaseActivator.java (original)
+++ aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/BaseActivator.java Sun Apr  3 23:33:12 2011
@@ -34,7 +34,6 @@ import java.util.concurrent.CopyOnWriteA
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.log.LogService;
 import org.osgi.util.tracker.BundleTracker;
@@ -42,76 +41,59 @@ import org.osgi.util.tracker.ServiceTrac
 
 public abstract class BaseActivator implements BundleActivator {
     private static final Set<WeavingData> NON_WOVEN_BUNDLE = Collections.emptySet();
-    
-    // Static access to the activator used by the woven code, therefore 
+
+    // Static access to the activator used by the woven code, therefore
     // this bundle must be a singleton.
     // TODO see if we can get rid of the static access.
-    static BaseActivator activator;
-    
+    public static BaseActivator activator;
+
     private BundleContext bundleContext;
     private LogServiceTracker logServiceTracker;
     private List<LogService> logServices = new CopyOnWriteArrayList<LogService>();
-    private BundleTracker consumerBundleTracker; 
+    private BundleTracker consumerBundleTracker;
     private BundleTracker providerBundleTracker;
 
-    private final ConcurrentMap<Bundle, Set<WeavingData>> bundleWeavingData = 
+    private final ConcurrentMap<Bundle, Set<WeavingData>> bundleWeavingData =
         new ConcurrentHashMap<Bundle, Set<WeavingData>>();
 
-    private final ConcurrentMap<String, SortedMap<Long, Bundle>> registeredProviders = 
+    private final ConcurrentMap<String, SortedMap<Long, Bundle>> registeredProviders =
             new ConcurrentHashMap<String, SortedMap<Long, Bundle>>();
 
-    private final ConcurrentMap<Bundle, Map<ConsumerRestriction, List<BundleDescriptor>>> consumerRestrictions = 
+    private final ConcurrentMap<Bundle, Map<ConsumerRestriction, List<BundleDescriptor>>> consumerRestrictions =
             new ConcurrentHashMap<Bundle, Map<ConsumerRestriction, List<BundleDescriptor>>>();
-    
+
     public synchronized void start(BundleContext context, final String consumerHeaderName) throws Exception {
         bundleContext = context;
-        
+
         logServiceTracker = new LogServiceTracker(context);
         logServiceTracker.open();
 
         providerBundleTracker = new BundleTracker(context,
                 Bundle.ACTIVE, new ProviderBundleTrackerCustomizer(this, context.getBundle()));
         providerBundleTracker.open();
-        
-        consumerBundleTracker = new BundleTracker(context, Bundle.INSTALLED, null) {
-            @Override
-            public Object addingBundle(Bundle bundle, BundleEvent event) {
-                processBundle(bundle, consumerHeaderName);                    
-                
-                return super.addingBundle(bundle, event);
-            }
-
-            @Override
-            public void modifiedBundle(Bundle bundle, BundleEvent event, Object object) {
-                removedBundle(bundle, event, object);
-                addingBundle(bundle, event);
-            }
 
-            @Override
-            public void removedBundle(Bundle bundle, BundleEvent event, Object object) {
-                bundleWeavingData.remove(bundle);
-            }
-        };
+        consumerBundleTracker = new BundleTracker(context,
+                Bundle.INSTALLED, new ConsumerBundleTrackerCustomizer(this, consumerHeaderName));
         consumerBundleTracker.open();
-        
+
         for (Bundle bundle : context.getBundles()) {
-            processBundle(bundle, consumerHeaderName);
+            addWeavingData(bundle, consumerHeaderName);
         }
-        
+
         activator = this;
     }
 
-    private void processBundle(Bundle bundle, String consumerHeaderName) {
+    public void addWeavingData(Bundle bundle, String consumerHeaderName) {
         if (bundleWeavingData.containsKey(bundle)) {
             // This bundle was already processed
             return;
         }
-        
+
         Object consumerHeader = bundle.getHeaders().get(consumerHeaderName);
         if (consumerHeader instanceof String) {
             Set<WeavingData> wd = ConsumerHeaderProcessor.processHeader((String) consumerHeader);
             bundleWeavingData.put(bundle, Collections.unmodifiableSet(wd));
-            
+
             for (WeavingData w : wd) {
                 registerConsumerBundle(bundle, w.getArgRestrictions(), w.getAllowedBundles());
             }
@@ -120,10 +102,14 @@ public abstract class BaseActivator impl
         }
     }
 
+    public void removeWeavingData(Bundle bundle) {
+        bundleWeavingData.remove(bundle);
+    }
+
     @Override
     public synchronized void stop(BundleContext context) throws Exception {
         activator = null;
-        
+
         consumerBundleTracker.close();
         providerBundleTracker.close();
         logServiceTracker.close();
@@ -144,20 +130,20 @@ public abstract class BaseActivator impl
             }
         }
     }
-    
+
     public Set<WeavingData> getWeavingData(Bundle b) {
         // Simply return the value as it's already an unmovable set.
         Set<WeavingData> wd = bundleWeavingData.get(b);
-        if (wd == null) 
+        if (wd == null)
             return null;
-        
-        if (wd.size() == 0) 
+
+        if (wd.size() == 0)
             return null;
-        
+
         return wd;
     }
 
-    public void registerProviderBundle(String registrationClassName, Bundle bundle) {        
+    public void registerProviderBundle(String registrationClassName, Bundle bundle) {
         registeredProviders.putIfAbsent(registrationClassName, Collections.synchronizedSortedMap(new TreeMap<Long, Bundle>()));
         SortedMap<Long, Bundle> map = registeredProviders.get(registrationClassName);
         map.put(bundle.getBundleId(), bundle);
@@ -167,7 +153,7 @@ public abstract class BaseActivator impl
         SortedMap<Long, Bundle> map = registeredProviders.get(name);
         return map == null ? Collections.<Bundle>emptyList() : map.values();
     }
-    
+
     // TODO unRegisterProviderBundle();
     public void registerConsumerBundle( Bundle consumerBundle,
             Set<ConsumerRestriction> restrictions, List<BundleDescriptor> allowedBundles) {
@@ -185,13 +171,13 @@ public abstract class BaseActivator impl
             // Null means: no restrictions
             return null;
         }
-        
+
         for (Map.Entry<ConsumerRestriction, List<BundleDescriptor>> entry : restrictions.entrySet()) {
             if (entry.getKey().matches(className, methodName, args)) {
                 return getBundles(entry.getValue());
             }
         }
-        
+
         // Empty collection: nothing matches
         return Collections.emptySet();
     }
@@ -200,7 +186,7 @@ public abstract class BaseActivator impl
         if (descriptors == null) {
             return null;
         }
-        
+
         List<Bundle> bundles = new ArrayList<Bundle>();
         for (Bundle b : bundleContext.getBundles()) {
             for (BundleDescriptor desc : descriptors) {
@@ -215,7 +201,7 @@ public abstract class BaseActivator impl
     }
 
     // TODO unRegisterConsumerBundle();
-    
+
     private class LogServiceTracker extends ServiceTracker {
         public LogServiceTracker(BundleContext context) {
             super(context, LogService.class.getName(), null);
@@ -231,6 +217,6 @@ public abstract class BaseActivator impl
         @Override
         public void removedService(ServiceReference reference, Object service) {
             logServices.remove(service);
-        }        
+        }
     }
 }

Added: aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/ConsumerBundleTrackerCustomizer.java
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/ConsumerBundleTrackerCustomizer.java?rev=1088438&view=auto
==============================================================================
--- aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/ConsumerBundleTrackerCustomizer.java (added)
+++ aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/ConsumerBundleTrackerCustomizer.java Sun Apr  3 23:33:12 2011
@@ -0,0 +1,50 @@
+/**
+ * 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;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleEvent;
+import org.osgi.util.tracker.BundleTrackerCustomizer;
+
+public class ConsumerBundleTrackerCustomizer implements BundleTrackerCustomizer {
+    private final BaseActivator activator;
+    private final String headerName;
+    
+    public ConsumerBundleTrackerCustomizer(BaseActivator baseActivator, String consumerHeaderName) {
+        activator = baseActivator;
+        headerName = consumerHeaderName;
+    }
+
+    @Override
+    public Object addingBundle(Bundle bundle, BundleEvent event) {
+        activator.addWeavingData(bundle, headerName);                    
+        return bundle;
+    }
+
+    @Override
+    public void modifiedBundle(Bundle bundle, BundleEvent event, Object object) {
+        removedBundle(bundle, event, object);
+        addingBundle(bundle, event);
+    }
+
+    @Override
+    public void removedBundle(Bundle bundle, BundleEvent event, Object object) {
+        activator.removeWeavingData(bundle);
+    }
+}

Modified: aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/Util.java
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/Util.java?rev=1088438&r1=1088437&r2=1088438&view=diff
==============================================================================
--- aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/Util.java (original)
+++ aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/Util.java Sun Apr  3 23:33:12 2011
@@ -18,7 +18,6 @@
  */
 package org.apache.aries.spifly;
 
-import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Enumeration;
@@ -32,22 +31,22 @@ import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleReference;
 import org.osgi.service.log.LogService;
 
-/** 
+/**
  * Methods used from ASM-generated code. They store, change and reset the thread context classloader.
  * The methods are static to make it easy to access them from generated code.
  */
 public class Util {
     static ThreadLocal<ClassLoader> storedClassLoaders = new ThreadLocal<ClassLoader>();
-    
+
     public static void storeContextClassloader() {
         storedClassLoaders.set(Thread.currentThread().getContextClassLoader());
     }
-    
+
     public static void restoreContextClassloader() {
         Thread.currentThread().setContextClassLoader(storedClassLoaders.get());
         storedClassLoaders.set(null);
     }
-        
+
     public static void fixContextClassloader(String cls, String method, Class<?> clsArg, ClassLoader bundleLoader) {
         if (!(bundleLoader instanceof BundleReference)) {
             BaseActivator.activator.log(LogService.LOG_WARNING, "Classloader of consuming bundle doesn't implement BundleReference: " + bundleLoader);
@@ -55,8 +54,8 @@ public class Util {
         }
 
         BundleReference br = ((BundleReference) bundleLoader);
-        System.out.println("~~~ cls: " + cls + " method: " + method + " clarg:" + clsArg + " cl:" + bundleLoader + " clientBundle: " + br.getBundle().getSymbolicName());        
-        
+        System.out.println("~~~ cls: " + cls + " method: " + method + " clarg:" + clsArg + " cl:" + bundleLoader + " clientBundle: " + br.getBundle().getSymbolicName());
+
         ClassLoader cl = findContextClassloader(br.getBundle(), cls, method, clsArg);
         if (cl != null) {
             BaseActivator.activator.log(LogService.LOG_INFO, "Temporarily setting Thread Context Classloader to: " + cl);
@@ -65,10 +64,10 @@ public class Util {
             BaseActivator.activator.log(LogService.LOG_WARNING, "No classloader found for " + cls + ":" + method + "(" + clsArg + ")");
         }
     }
-    
+
     private static ClassLoader findContextClassloader(Bundle consumerBundle, String className, String methodName, Class<?> clsArg) {
         BaseActivator activator = BaseActivator.activator;
-        
+
         String requestedClass;
         Map<Pair<Integer, String>, String> args;
         if (ServiceLoader.class.getName().equals(className) && "load".equals(methodName)) {
@@ -82,7 +81,7 @@ public class Util {
 
         Collection<Bundle> bundles = new ArrayList<Bundle>(activator.findProviderBundles(requestedClass));
         activator.log(LogService.LOG_DEBUG, "Found bundles providing " + requestedClass + ": " + bundles);
-                
+
         Collection<Bundle> allowedBundles = activator.findConsumerRestrictions(consumerBundle, className, methodName, args);
 
         if (allowedBundles != null) {
@@ -92,7 +91,7 @@ public class Util {
                 }
             }
         }
-        
+
         switch (bundles.size()) {
         case 0:
             return null;
@@ -100,7 +99,7 @@ public class Util {
             Bundle bundle = bundles.iterator().next();
             return getBundleClassLoader(bundle);
 //            BundleWiring wiring = bundle.adapt(BundleWiring.class);
-//            return wiring.getClassLoader();            
+//            return wiring.getClassLoader();
         default:
             List<ClassLoader> loaders = new ArrayList<ClassLoader>();
             for (Bundle b : bundles) {
@@ -111,7 +110,7 @@ public class Util {
             return new MultiDelegationClassloader(loaders.toArray(new ClassLoader[loaders.size()]));
         }
     }
-    
+
     @SuppressWarnings("unchecked")
     private static ClassLoader getBundleClassLoader(Bundle b) {
         // In 4.3 this can be done much easier by using the BundleWiring...
@@ -121,11 +120,14 @@ public class Util {
             String path = paths.nextElement();
             if (path.endsWith(".class")) {
                 String className = path.substring(0,path.length() - ".class".length());
+                if (className.startsWith("/"))
+                    className = className.substring(1);
+
                 className = className.replace('/', '.');
                 try {
                     Class<?> cls = b.loadClass(className);
                     return cls.getClassLoader();
-                } catch (ClassNotFoundException e) {                    
+                } catch (ClassNotFoundException e) {
                     // try the next class
                 }
             }

Added: aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizerTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizerTest.java?rev=1088438&view=auto
==============================================================================
--- aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizerTest.java (added)
+++ aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizerTest.java Sun Apr  3 23:33:12 2011
@@ -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.spifly;
+
+import java.net.URL;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+
+import org.apache.aries.spifly.api.SpiFlyConstants;
+import org.apache.aries.spifly.impl1.MySPIImpl1;
+import org.easymock.EasyMock;
+import org.junit.Assert;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+public class ProviderBundleTrackerCustomizerTest {
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testAddingRemovedBundle() throws Exception {        
+        Bundle spiBundle = EasyMock.createMock(Bundle.class);
+        EasyMock.replay(spiBundle);
+        BaseActivator a = new BaseActivator() {
+            @Override
+            public void start(BundleContext context) throws Exception {}            
+        };        
+        
+        ProviderBundleTrackerCustomizer customizer = new ProviderBundleTrackerCustomizer(a, spiBundle);
+        
+        ServiceRegistration sreg = EasyMock.createMock(ServiceRegistration.class);
+        sreg.unregister();
+        EasyMock.expectLastCall();
+        EasyMock.replay(sreg);
+
+        // The bundle context for the test SPI bundle
+        BundleContext implBC = EasyMock.createMock(BundleContext.class);
+        EasyMock.<Object>expect(implBC.registerService(
+                EasyMock.eq("org.apache.aries.mytest.MySPI"), 
+                EasyMock.isA(MySPIImpl1.class), 
+                (Dictionary<String,?>) EasyMock.anyObject())).andReturn(sreg);
+        EasyMock.replay(implBC);
+
+        // The test impl bundle
+        Bundle implBundle = EasyMock.createNiceMock(Bundle.class);
+        EasyMock.expect(implBundle.getBundleContext()).andReturn(implBC);
+        
+        Dictionary<String, String> headers = new Hashtable<String, String>();
+        // Specify the headers for the test bundle
+        headers.put(SpiFlyConstants.SPI_PROVIDER_HEADER, "*");
+        EasyMock.expect(implBundle.getHeaders()).andReturn(headers);
+        
+        // List the resources found at META-INF/services in the test bundle
+        URL res = getClass().getResource("impl1/META-INF/services/org.apache.aries.mytest.MySPI");
+        Assert.assertNotNull("precondition", res);
+        EasyMock.expect(implBundle.findEntries("META-INF/services", "*", false)).andReturn(
+                Collections.enumeration(Collections.singleton(res)));
+        
+        Class<?> cls = getClass().getClassLoader().loadClass("org.apache.aries.spifly.impl1.MySPIImpl1");
+        EasyMock.<Object>expect(implBundle.loadClass("org.apache.aries.spifly.impl1.MySPIImpl1")).andReturn(cls);
+        
+        EasyMock.replay(implBundle);
+        
+        Assert.assertEquals("Precondition", 0, a.findProviderBundles("org.apache.aries.mytest.MySPI").size());
+        // Call addingBundle();
+        List<ServiceRegistration> registrations = customizer.addingBundle(implBundle, null);
+        Collection<Bundle> bundles = a.findProviderBundles("org.apache.aries.mytest.MySPI");
+        Assert.assertEquals(1, bundles.size());
+        Assert.assertSame(implBundle, bundles.iterator().next());
+        
+        // The bc.registerService() call should now have been made
+        EasyMock.verify(implBC);
+        
+        // Call removedBundle();
+        customizer.removedBundle(implBundle, null, registrations);
+        // sreg.unregister() should have been called.
+        EasyMock.verify(sreg);
+    }
+}

Modified: aries/trunk/spi-fly/spi-fly-dynamic-bundle/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-dynamic-bundle/pom.xml?rev=1088438&r1=1088437&r2=1088438&view=diff
==============================================================================
--- aries/trunk/spi-fly/spi-fly-dynamic-bundle/pom.xml (original)
+++ aries/trunk/spi-fly/spi-fly-dynamic-bundle/pom.xml Sun Apr  3 23:33:12 2011
@@ -48,6 +48,17 @@ JRE through META-INF/services resources)
             <groupId>org.apache.aries.spifly</groupId>
             <artifactId>org.apache.aries.spifly.core</artifactId>
             <version>${project.version}</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.osgi</groupId>
+                    <artifactId>org.osgi.core</artifactId>                    
+                </exclusion>
+
+                <exclusion>
+                    <groupId>org.osgi</groupId>
+                    <artifactId>org.osgi.compendium</artifactId>                    
+                </exclusion>
+            </exclusions>
         </dependency>
 
         <dependency>
@@ -64,6 +75,13 @@ JRE through META-INF/services resources)
             <scope>system</scope>
             <systemPath>${basedir}/../spi-fly-deps/target/downloaded/org.eclipse.osgi_3.7.0.jar</systemPath>
         </dependency>
+
+        <dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymock</artifactId>
+            <version>3.0</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>

Modified: aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/main/java/org/apache/aries/spifly/dynamic/DynamicWeavingActivator.java
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/main/java/org/apache/aries/spifly/dynamic/DynamicWeavingActivator.java?rev=1088438&r1=1088437&r2=1088438&view=diff
==============================================================================
--- aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/main/java/org/apache/aries/spifly/dynamic/DynamicWeavingActivator.java (original)
+++ aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/main/java/org/apache/aries/spifly/dynamic/DynamicWeavingActivator.java Sun Apr  3 23:33:12 2011
@@ -1,3 +1,21 @@
+/**
+ * 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.dynamic;
 
 import org.apache.aries.spifly.BaseActivator;
@@ -8,12 +26,12 @@ import org.osgi.framework.ServiceRegistr
 import org.osgi.framework.hooks.weaving.WeavingHook;
 
 public class DynamicWeavingActivator extends BaseActivator implements BundleActivator {
-    private ServiceRegistration<WeavingHook> weavingHookService;
+    private ServiceRegistration weavingHookService;
 
     @Override
     public synchronized void start(BundleContext context) throws Exception {
         WeavingHook wh = new ClientWeavingHook(context, this);
-        weavingHookService = context.registerService(WeavingHook.class, wh, null);
+        weavingHookService = context.registerService(WeavingHook.class.getName(), wh, null);
         
         super.start(context, SpiFlyConstants.SPI_CONSUMER_HEADER);
     }

Added: aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/mytest/AltSPI.java
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/mytest/AltSPI.java?rev=1088438&view=auto
==============================================================================
--- aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/mytest/AltSPI.java (added)
+++ aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/mytest/AltSPI.java Sun Apr  3 23:33:12 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.mytest;
+
+public interface AltSPI {
+    long square(long l);
+}

Added: aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/mytest/MySPI.java
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/mytest/MySPI.java?rev=1088438&view=auto
==============================================================================
--- aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/mytest/MySPI.java (added)
+++ aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/mytest/MySPI.java Sun Apr  3 23:33:12 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.mytest;
+
+public interface MySPI {
+    String someMethod(String s);
+}

Copied: aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/spifly/dynamic/ClientWeavingHookTest.java (from r1084722, aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/spifly/ClientWeavingHookTest.java.todo)
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/spifly/dynamic/ClientWeavingHookTest.java?p2=aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/spifly/dynamic/ClientWeavingHookTest.java&p1=aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/spifly/ClientWeavingHookTest.java.todo&r1=1084722&r2=1088438&rev=1088438&view=diff
==============================================================================
--- aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/spifly/ClientWeavingHookTest.java.todo (original)
+++ aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/spifly/dynamic/ClientWeavingHookTest.java Sun Apr  3 23:33:12 2011
@@ -16,25 +16,31 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.aries.spifly;
+package org.apache.aries.spifly.dynamic;
 
+import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileReader;
 import java.io.IOException;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
-import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.security.ProtectionDomain;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.List;
 
+import org.apache.aries.spifly.BaseActivator;
+import org.apache.aries.spifly.Streams;
 import org.apache.aries.spifly.api.SpiFlyConstants;
 import org.easymock.EasyMock;
+import org.easymock.IAnswer;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -48,43 +54,50 @@ import org.osgi.framework.hooks.weaving.
 import org.osgi.framework.wiring.BundleWiring;
 
 public class ClientWeavingHookTest {
+    DynamicWeavingActivator activator;
+
     @Before
     public void setUp() {
-        Activator.activator = new Activator();
+        activator = new DynamicWeavingActivator();
+        BaseActivator.activator = activator;
     }
-    
+
     @After
     public void tearDown() {
-        Activator.activator = null;
+        BaseActivator.activator = null;
+        activator = null;
     }
-        
+
     @Test
     public void testClientWeavingHookBasicServiveLoaderUsage() throws Exception {
         Dictionary<String, String> consumerHeaders = new Hashtable<String, String>();
         consumerHeaders.put(SpiFlyConstants.SPI_CONSUMER_HEADER, "*");
 
         // Register the bundle that provides the SPI implementation.
-        Bundle providerBundle = mockProviderBundle("impl1", 1);        
-        Activator.activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle);
+        Bundle providerBundle = mockProviderBundle("impl1", 1);
+        activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle);
 
         Bundle consumerBundle = mockConsumerBundle(consumerHeaders, providerBundle);
-        Bundle spiFlyBundle = mockSpiFlyBundle("spifly", Version.parseVersion("1.9.4"), consumerBundle, providerBundle);                      
+        activator.addWeavingData(consumerBundle, SpiFlyConstants.SPI_CONSUMER_HEADER);
+
+        Bundle spiFlyBundle = mockSpiFlyBundle("spifly", Version.parseVersion("1.9.4"), consumerBundle, providerBundle);
+        WeavingHook wh = new ClientWeavingHook(spiFlyBundle.getBundleContext(), activator);
 
-        WeavingHook wh = new ClientWeavingHook(spiFlyBundle.getBundleContext());
-        
         // Weave the TestClient class.
         URL clsUrl = getClass().getResource("TestClient.class");
         Assert.assertNotNull("Precondition", clsUrl);
-        WovenClass wc = new MyWovenClass(clsUrl, "org.apache.aries.spifly.TestClient", consumerBundle);
+
+        String clientClassName = "org.apache.aries.spifly.dynamic.TestClient";
+        WovenClass wc = new MyWovenClass(clsUrl, clientClassName, consumerBundle);
         Assert.assertEquals("Precondition", 0, wc.getDynamicImports().size());
         wh.weave(wc);
         Assert.assertEquals(1, wc.getDynamicImports().size());
         String di1 = "org.apache.aries.spifly;bundle-symbolic-name=spifly;bundle-version=1.9.4";
         String di2 = "org.apache.aries.spifly;bundle-version=1.9.4;bundle-symbolic-name=spifly";
         String di = wc.getDynamicImports().get(0);
-        Assert.assertTrue("Weaving should have added a dynamic import", di1.equals(di) || di2.equals(di));        
-                        
-        // Invoke the woven class and check that it propertly sets the TCCL so that the 
+        Assert.assertTrue("Weaving should have added a dynamic import", di1.equals(di) || di2.equals(di));
+
+        // Invoke the woven class and check that it propertly sets the TCCL so that the
         // META-INF/services/org.apache.aries.mytest.MySPI file from impl1 is visible.
         Class<?> cls = wc.getDefinedClass();
         Method method = cls.getMethod("test", new Class [] {String.class});
@@ -94,14 +107,14 @@ public class ClientWeavingHookTest {
 
     @Test
     public void testClientWeavingHookAltServiceLoaderLoadUnprocessed() throws Exception {
-        Bundle spiFlyBundle = mockSpiFlyBundle();               
-       
+        Bundle spiFlyBundle = mockSpiFlyBundle();
+
         Dictionary<String, String> headers = new Hashtable<String, String>();
         headers.put(SpiFlyConstants.SPI_CONSUMER_HEADER, "*");
         Bundle consumerBundle = mockConsumerBundle(headers, spiFlyBundle);
 
-        WeavingHook wh = new ClientWeavingHook(spiFlyBundle.getBundleContext());
-        
+        WeavingHook wh = new ClientWeavingHook(spiFlyBundle.getBundleContext(), activator);
+
         // Weave the TestClient class.
         URL clsUrl = getClass().getResource("UnaffectedTestClient.class");
         Assert.assertNotNull("Precondition", clsUrl);
@@ -109,14 +122,14 @@ public class ClientWeavingHookTest {
         Assert.assertEquals("Precondition", 0, wc.getDynamicImports().size());
         wh.weave(wc);
 
-        Assert.assertEquals("The client is not affected so no additional imports should have been added", 
+        Assert.assertEquals("The client is not affected so no additional imports should have been added",
             0, wc.getDynamicImports().size());
-                
+
         // ok the weaving is done, now prepare the registry for the call
-        Bundle providerBundle = mockProviderBundle("impl1", 1);        
-        Activator.activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle);
-        
-        // Invoke the woven class and check that it propertly sets the TCCL so that the 
+        Bundle providerBundle = mockProviderBundle("impl1", 1);
+        activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle);
+
+        // Invoke the woven class and check that it propertly sets the TCCL so that the
         // META-INF/services/org.apache.aries.mytest.MySPI file from impl1 is visible.
         Class<?> cls = wc.getDefinedClass();
         Method method = cls.getMethod("test", new Class [] {String.class});
@@ -132,7 +145,7 @@ public class ClientWeavingHookTest {
         headers.put(SpiFlyConstants.SPI_CONSUMER_HEADER, "*");
         Bundle consumerBundle = mockConsumerBundle(headers, spiFlyBundle);
 
-        WeavingHook wh = new ClientWeavingHook(spiFlyBundle.getBundleContext());
+        WeavingHook wh = new ClientWeavingHook(spiFlyBundle.getBundleContext(), activator);
 
         // Weave the TestClient class.
         URL clsUrl = getClass().getResource("TestClient.class");
@@ -141,19 +154,19 @@ public class ClientWeavingHookTest {
 
         Bundle providerBundle1 = mockProviderBundle("impl1", 1);
         Bundle providerBundle2 = mockProviderBundle("impl2", 2);
-        
+
         // Register in reverse order to make sure the order in which bundles are sorted is correct
-        Activator.activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle2);
-        Activator.activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle1);
+        activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle2);
+        activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle1);
 
-        // Invoke the woven class and check that it propertly sets the TCCL so that the 
+        // Invoke the woven class and check that it propertly sets the TCCL so that the
         // META-INF/services/org.apache.aries.mytest.MySPI files from impl1 and impl2 are visible.
         Class<?> cls = wc.getDefinedClass();
         Method method = cls.getMethod("test", new Class [] {String.class});
         Object result = method.invoke(cls.newInstance(), "hello");
-        Assert.assertEquals("All three services should be invoked in the correct order", "ollehHELLO5", result);        
+        Assert.assertEquals("All three services should be invoked in the correct order", "ollehHELLO5", result);
     }
-    
+
     @Test
     public void testClientSpecifyingProvider() throws Exception {
         Dictionary<String, String> headers = new Hashtable<String, String>();
@@ -161,26 +174,26 @@ public class ClientWeavingHookTest {
 
         Bundle providerBundle1 = mockProviderBundle("impl1", 1);
         Bundle providerBundle2 = mockProviderBundle("impl2", 2);
-        Activator.activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle1);
-        Activator.activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle2);
+        activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle1);
+        activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle2);
 
         Bundle consumerBundle = mockConsumerBundle(headers, providerBundle1, providerBundle2);
-        Bundle spiFlyBundle = mockSpiFlyBundle(consumerBundle, providerBundle1, providerBundle2);        
-        WeavingHook wh = new ClientWeavingHook(spiFlyBundle.getBundleContext());
+        Bundle spiFlyBundle = mockSpiFlyBundle(consumerBundle, providerBundle1, providerBundle2);
+        WeavingHook wh = new ClientWeavingHook(spiFlyBundle.getBundleContext(), activator);
 
         // Weave the TestClient class.
         URL clsUrl = getClass().getResource("TestClient.class");
         WovenClass wc = new MyWovenClass(clsUrl, "org.apache.aries.spifly.TestClient", consumerBundle);
         wh.weave(wc);
 
-        // Invoke the woven class and check that it propertly sets the TCCL so that the 
+        // Invoke the woven class and check that it propertly sets the TCCL so that the
         // META-INF/services/org.apache.aries.mytest.MySPI file from impl2 is visible.
         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", "HELLO5", result);        
+        Assert.assertEquals("Only the services from bundle impl2 should be selected", "HELLO5", result);
     }
-    
+
     @Test
     public void testClientSpecifyingProviderVersion() throws Exception {
         Dictionary<String, String> headers = new Hashtable<String, String>();
@@ -189,122 +202,122 @@ public class ClientWeavingHookTest {
         Bundle providerBundle1 = mockProviderBundle("impl1", 1);
         Bundle providerBundle2 = mockProviderBundle("impl2", 2);
         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);
+        activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle1);
+        activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle2);
+        activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle3);
 
         Bundle consumerBundle = mockConsumerBundle(headers, providerBundle1, providerBundle2, providerBundle3);
-        Bundle spiFlyBundle = mockSpiFlyBundle(consumerBundle, providerBundle1, providerBundle2, providerBundle3);        
-        WeavingHook wh = new ClientWeavingHook(spiFlyBundle.getBundleContext());
+        Bundle spiFlyBundle = mockSpiFlyBundle(consumerBundle, providerBundle1, providerBundle2, providerBundle3);
+        WeavingHook wh = new ClientWeavingHook(spiFlyBundle.getBundleContext(), activator);
 
         // Weave the TestClient class.
         URL clsUrl = getClass().getResource("TestClient.class");
         WovenClass wc = new MyWovenClass(clsUrl, "org.apache.aries.spifly.TestClient", consumerBundle);
         wh.weave(wc);
 
-        // Invoke the woven class and check that it propertly sets the TCCL so that the 
+        // Invoke the woven class and check that it propertly sets the TCCL so that the
         // META-INF/services/org.apache.aries.mytest.MySPI file from impl2 is visible.
         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
     public void testClientMultipleTargetBundles() throws Exception {
         Dictionary<String, String> headers = new Hashtable<String, String>();
-        headers.put(SpiFlyConstants.SPI_CONSUMER_HEADER, 
+        headers.put(SpiFlyConstants.SPI_CONSUMER_HEADER,
                 "java.util.ServiceLoader#load(java.lang.Class);bundle=impl1|impl4");
 
         Bundle providerBundle1 = mockProviderBundle("impl1", 1);
         Bundle providerBundle2 = mockProviderBundle("impl2", 2);
         Bundle providerBundle4 = mockProviderBundle("impl4", 4);
-        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.AltSPI", providerBundle2);
-        Activator.activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle4);        
-        Activator.activator.registerProviderBundle("org.apache.aries.mytest.AltSPI", providerBundle4);        
+        activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle1);
+        activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle2);
+        activator.registerProviderBundle("org.apache.aries.mytest.AltSPI", providerBundle2);
+        activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle4);
+        activator.registerProviderBundle("org.apache.aries.mytest.AltSPI", providerBundle4);
 
         Bundle consumerBundle = mockConsumerBundle(headers, providerBundle1, providerBundle2, providerBundle4);
-        Bundle spiFlyBundle = mockSpiFlyBundle(consumerBundle, providerBundle1, providerBundle2, providerBundle4);        
-        WeavingHook wh = new ClientWeavingHook(spiFlyBundle.getBundleContext());
+        Bundle spiFlyBundle = mockSpiFlyBundle(consumerBundle, providerBundle1, providerBundle2, providerBundle4);
+        WeavingHook wh = new ClientWeavingHook(spiFlyBundle.getBundleContext(), activator);
 
         // Weave the TestClient class.
         URL clsUrl = getClass().getResource("TestClient.class");
         WovenClass wc = new MyWovenClass(clsUrl, "org.apache.aries.spifly.TestClient", consumerBundle);
         wh.weave(wc);
 
-        // Invoke the woven class and check that it propertly sets the TCCL so that the 
+        // Invoke the woven class and check that it propertly sets the TCCL so that the
         // META-INF/services/org.apache.aries.mytest.MySPI file from impl2 is visible.
         Class<?> cls = wc.getDefinedClass();
         Method method = cls.getMethod("test", new Class [] {String.class});
         Object result = method.invoke(cls.newInstance(), "hello");
-        Assert.assertEquals("All providers should be selected for this one", "ollehimpl4", result);        
+        Assert.assertEquals("All providers should be selected for this one", "ollehimpl4", result);
     }
-    
+
     @Test
     public void testClientMultipleTargetBundles2() throws Exception {
         Dictionary<String, String> headers = new Hashtable<String, String>();
-        headers.put(SpiFlyConstants.SPI_CONSUMER_HEADER, 
+        headers.put(SpiFlyConstants.SPI_CONSUMER_HEADER,
                 "java.util.ServiceLoader#load(java.lang.Class);bundleId=1|4");
 
         Bundle providerBundle1 = mockProviderBundle("impl1", 1);
         Bundle providerBundle2 = mockProviderBundle("impl2", 2);
         Bundle providerBundle4 = mockProviderBundle("impl4", 4);
-        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.AltSPI", providerBundle2);
-        Activator.activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle4);        
-        Activator.activator.registerProviderBundle("org.apache.aries.mytest.AltSPI", providerBundle4);        
+        activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle1);
+        activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle2);
+        activator.registerProviderBundle("org.apache.aries.mytest.AltSPI", providerBundle2);
+        activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle4);
+        activator.registerProviderBundle("org.apache.aries.mytest.AltSPI", providerBundle4);
 
         Bundle consumerBundle = mockConsumerBundle(headers, providerBundle1, providerBundle2, providerBundle4);
-        Bundle spiFlyBundle = mockSpiFlyBundle(consumerBundle, providerBundle1, providerBundle2, providerBundle4);        
-        WeavingHook wh = new ClientWeavingHook(spiFlyBundle.getBundleContext());
+        Bundle spiFlyBundle = mockSpiFlyBundle(consumerBundle, providerBundle1, providerBundle2, providerBundle4);
+        WeavingHook wh = new ClientWeavingHook(spiFlyBundle.getBundleContext(), activator);
 
         // Weave the TestClient class.
         URL clsUrl = getClass().getResource("TestClient.class");
         WovenClass wc = new MyWovenClass(clsUrl, "org.apache.aries.spifly.TestClient", consumerBundle);
         wh.weave(wc);
 
-        // Invoke the woven class and check that it propertly sets the TCCL so that the 
+        // Invoke the woven class and check that it propertly sets the TCCL so that the
         // META-INF/services/org.apache.aries.mytest.MySPI file from impl2 is visible.
         Class<?> cls = wc.getDefinedClass();
         Method method = cls.getMethod("test", new Class [] {String.class});
         Object result = method.invoke(cls.newInstance(), "hello");
-        Assert.assertEquals("All providers should be selected for this one", "ollehimpl4", result);        
+        Assert.assertEquals("All providers should be selected for this one", "ollehimpl4", result);
     }
 
     @Test
     public void testClientSpecificProviderLoadArgument() throws Exception {
         Dictionary<String, String> headers = new Hashtable<String, String>();
-        headers.put(SpiFlyConstants.SPI_CONSUMER_HEADER, 
+        headers.put(SpiFlyConstants.SPI_CONSUMER_HEADER,
                 "java.util.ServiceLoader#load(java.lang.Class[org.apache.aries.mytest.MySPI])," +
                 "java.util.ServiceLoader#load(java.lang.Class[org.apache.aries.mytest.AltSPI]);bundle=impl4");
 
         Bundle providerBundle1 = mockProviderBundle("impl1", 1);
         Bundle providerBundle2 = mockProviderBundle("impl2", 2);
         Bundle providerBundle4 = mockProviderBundle("impl4", 4);
-        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.AltSPI", providerBundle2);
-        Activator.activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle4);        
-        Activator.activator.registerProviderBundle("org.apache.aries.mytest.AltSPI", providerBundle4);        
+        activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle1);
+        activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle2);
+        activator.registerProviderBundle("org.apache.aries.mytest.AltSPI", providerBundle2);
+        activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle4);
+        activator.registerProviderBundle("org.apache.aries.mytest.AltSPI", providerBundle4);
 
         Bundle consumerBundle = mockConsumerBundle(headers, providerBundle1, providerBundle2, providerBundle4);
-        Bundle spiFlyBundle = mockSpiFlyBundle(consumerBundle, providerBundle1, providerBundle2, providerBundle4);        
-        WeavingHook wh = new ClientWeavingHook(spiFlyBundle.getBundleContext());
+        Bundle spiFlyBundle = mockSpiFlyBundle(consumerBundle, providerBundle1, providerBundle2, providerBundle4);
+        WeavingHook wh = new ClientWeavingHook(spiFlyBundle.getBundleContext(), activator);
 
         // Weave the TestClient class.
         URL clsUrl = getClass().getResource("TestClient.class");
         WovenClass wc = new MyWovenClass(clsUrl, "org.apache.aries.spifly.TestClient", consumerBundle);
         wh.weave(wc);
 
-        // Invoke the woven class and check that it propertly sets the TCCL so that the 
+        // Invoke the woven class and check that it propertly sets the TCCL so that the
         // META-INF/services/org.apache.aries.mytest.MySPI file from impl2 is visible.
         Class<?> cls = wc.getDefinedClass();
         Method method = cls.getMethod("test", new Class [] {String.class});
         Object result = method.invoke(cls.newInstance(), "hello");
-        Assert.assertEquals("All providers should be selected for this one", "ollehHELLO5impl4", result);        
+        Assert.assertEquals("All providers should be selected for this one", "ollehHELLO5impl4", result);
 
         // Weave the AltTestClient class.
         URL cls2Url = getClass().getResource("AltTestClient.class");
@@ -315,46 +328,46 @@ public class ClientWeavingHookTest {
         Class<?> cls2 = wc2.getDefinedClass();
         Method method2 = cls2.getMethod("test", new Class [] {long.class});
         Object result2 = method2.invoke(cls2.newInstance(), 4096);
-        Assert.assertEquals("Only the services from bundle impl4 should be selected", -4096L*4096L, result2);        
+        Assert.assertEquals("Only the services from bundle impl4 should be selected", -4096L*4096L, result2);
     }
-    
+
     @Test
     public void testClientSpecifyingDifferentMethodsLimitedToDifferentProviders() throws Exception {
         Dictionary<String, String> headers1 = new Hashtable<String, String>();
-        headers1.put(SpiFlyConstants.SPI_CONSUMER_HEADER, 
+        headers1.put(SpiFlyConstants.SPI_CONSUMER_HEADER,
                 "javax.xml.parsers.DocumentBuilderFactory#newInstance();bundle=impl3," +
                 "java.util.ServiceLoader#load(java.lang.Class[org.apache.aries.mytest.MySPI]);bundle=impl4");
 
         Dictionary<String, String> headers2 = new Hashtable<String, String>();
-        headers2.put(SpiFlyConstants.SPI_CONSUMER_HEADER, 
+        headers2.put(SpiFlyConstants.SPI_CONSUMER_HEADER,
                 "javax.xml.parsers.DocumentBuilderFactory#newInstance();bundle=system.bundle," +
                 "java.util.ServiceLoader#load;bundle=impl1");
 
         Dictionary<String, String> headers3 = new Hashtable<String, String>();
-        headers3.put(SpiFlyConstants.SPI_CONSUMER_HEADER, 
+        headers3.put(SpiFlyConstants.SPI_CONSUMER_HEADER,
                 "org.acme.blah#someMethod();bundle=mybundle");
 
         Bundle providerBundle1 = mockProviderBundle("impl1", 1);
         Bundle providerBundle2 = mockProviderBundle("impl2", 2);
         Bundle providerBundle3 = mockProviderBundle("impl3", 3);
         Bundle providerBundle4 = mockProviderBundle("impl4", 4);
-        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.AltSPI", providerBundle2);
-        Activator.activator.registerProviderBundle("javax.xml.parsers.DocumentBuilderFactory", providerBundle3);
-        Activator.activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle4);        
-        Activator.activator.registerProviderBundle("org.apache.aries.mytest.AltSPI", providerBundle4);
-        
+        activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle1);
+        activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle2);
+        activator.registerProviderBundle("org.apache.aries.mytest.AltSPI", providerBundle2);
+        activator.registerProviderBundle("javax.xml.parsers.DocumentBuilderFactory", providerBundle3);
+        activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle4);
+        activator.registerProviderBundle("org.apache.aries.mytest.AltSPI", providerBundle4);
+
         Bundle consumerBundle1 = mockConsumerBundle(headers1, providerBundle1, providerBundle2, providerBundle3, providerBundle4);
         Bundle consumerBundle2 = mockConsumerBundle(headers2, providerBundle1, providerBundle2, providerBundle3, providerBundle4);
         Bundle consumerBundle3 = mockConsumerBundle(headers3, providerBundle1, providerBundle2, providerBundle3, providerBundle4);
         Bundle spiFlyBundle = mockSpiFlyBundle(consumerBundle1, consumerBundle2, consumerBundle3,
                 providerBundle1, providerBundle2, providerBundle3, providerBundle4);
-        WeavingHook wh = new ClientWeavingHook(spiFlyBundle.getBundleContext());
-        
-        testConsumerBundleWeaving(consumerBundle1, wh, "impl4", "org.apache.aries.spifly.impl3.MyAltDocumentBuilderFactory");                
-        testConsumerBundleWeaving(consumerBundle2, wh, "olleh", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");                
-        testConsumerBundleWeaving(consumerBundle3, wh, "", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");                
+        WeavingHook wh = new ClientWeavingHook(spiFlyBundle.getBundleContext(), activator);
+
+        testConsumerBundleWeaving(consumerBundle1, wh, "impl4", "org.apache.aries.spifly.impl3.MyAltDocumentBuilderFactory");
+        testConsumerBundleWeaving(consumerBundle2, wh, "olleh", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
+        testConsumerBundleWeaving(consumerBundle3, wh, "", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
     }
 
     private void testConsumerBundleWeaving(Bundle consumerBundle, WeavingHook wh, String testClientResult, String jaxpClientResult) throws Exception {
@@ -362,24 +375,24 @@ public class ClientWeavingHookTest {
         URL clsUrl = getClass().getResource("TestClient.class");
         WovenClass wc = new MyWovenClass(clsUrl, "org.apache.aries.spifly.TestClient", consumerBundle);
         wh.weave(wc);
-        
-        // Invoke the woven class and check that it propertly sets the TCCL so that the 
+
+        // Invoke the woven class and check that it propertly sets the TCCL so that the
         // META-INF/services/org.apache.aries.mytest.MySPI file from impl2 is visible.
         Class<?> cls = wc.getDefinedClass();
         Method method = cls.getMethod("test", new Class [] {String.class});
         Object result = method.invoke(cls.newInstance(), "hello");
-        Assert.assertEquals(testClientResult, result);        
-        
+        Assert.assertEquals(testClientResult, result);
+
         URL clsUrl2 = getClass().getResource("JaxpClient.class");
         WovenClass wc2 = new MyWovenClass(clsUrl2, "org.apache.aries.spifly.JaxpClient", consumerBundle);
         wh.weave(wc2);
-        
+
         Class<?> cls2 = wc2.getDefinedClass();
         Method method2 = cls2.getMethod("test", new Class [] {});
         Class<?> result2 = (Class<?>) method2.invoke(cls2.newInstance());
         Assert.assertEquals(jaxpClientResult, result2.getName());
     }
-        
+
     @Test
     public void testJAXPClientWantsJREImplementation1() throws Exception {
         Bundle systembundle = mockSystemBundle();
@@ -388,63 +401,63 @@ public class ClientWeavingHookTest {
         headers.put(SpiFlyConstants.SPI_CONSUMER_HEADER, "javax.xml.parsers.DocumentBuilderFactory#newInstance()");
         Bundle consumerBundle = mockConsumerBundle(headers, systembundle);
 
-        WeavingHook wh = new ClientWeavingHook(mockSpiFlyBundle(consumerBundle, systembundle).getBundleContext());
+        WeavingHook wh = new ClientWeavingHook(mockSpiFlyBundle(consumerBundle, systembundle).getBundleContext(), activator);
 
         URL clsUrl = getClass().getResource("JaxpClient.class");
         WovenClass wc = new MyWovenClass(clsUrl, "org.apache.aries.spifly.JaxpClient", consumerBundle);
         wh.weave(wc);
-        
+
         Class<?> cls = wc.getDefinedClass();
         Method method = cls.getMethod("test", new Class [] {});
         Class<?> result = (Class<?>) method.invoke(cls.newInstance());
-        Assert.assertEquals("JAXP implementation from JRE", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl", result.getName());                
+        Assert.assertEquals("JAXP implementation from JRE", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl", result.getName());
     }
-    
+
     // If there is an alternate implementation it should always be favoured over the JRE one
     @Test
     public void testJAXPClientWantsAltImplementation1() throws Exception {
         Bundle systembundle = mockSystemBundle();
 
         Bundle providerBundle = mockProviderBundle("impl3", 1);
-        Activator.activator.registerProviderBundle("javax.xml.parsers.DocumentBuilderFactory", providerBundle);
+        activator.registerProviderBundle("javax.xml.parsers.DocumentBuilderFactory", providerBundle);
 
         Dictionary<String, String> headers = new Hashtable<String, String>();
         headers.put(SpiFlyConstants.SPI_CONSUMER_HEADER, "javax.xml.parsers.DocumentBuilderFactory#newInstance()");
         Bundle consumerBundle = mockConsumerBundle(headers, providerBundle, systembundle);
 
-        WeavingHook wh = new ClientWeavingHook(mockSpiFlyBundle(consumerBundle, providerBundle, systembundle).getBundleContext());
+        WeavingHook wh = new ClientWeavingHook(mockSpiFlyBundle(consumerBundle, providerBundle, systembundle).getBundleContext(), activator);
 
         URL clsUrl = getClass().getResource("JaxpClient.class");
         WovenClass wc = new MyWovenClass(clsUrl, "org.apache.aries.spifly.JaxpClient", consumerBundle);
         wh.weave(wc);
-        
+
         Class<?> cls = wc.getDefinedClass();
         Method method = cls.getMethod("test", new Class [] {});
         Class<?> result = (Class<?>) method.invoke(cls.newInstance());
-        Assert.assertEquals("JAXP implementation from JRE", "org.apache.aries.spifly.impl3.MyAltDocumentBuilderFactory", result.getName());                
+        Assert.assertEquals("JAXP implementation from JRE", "org.apache.aries.spifly.impl3.MyAltDocumentBuilderFactory", result.getName());
     }
 
     @Test
     public void testJAXPClientWantsJREImplementation2() throws Exception {
         Bundle systembundle = mockSystemBundle();
-        
+
         Bundle providerBundle = mockProviderBundle("impl3", 1);
-        Activator.activator.registerProviderBundle("javax.xml.parsers.DocumentBuilderFactory", providerBundle);
+        activator.registerProviderBundle("javax.xml.parsers.DocumentBuilderFactory", providerBundle);
 
         Dictionary<String, String> headers = new Hashtable<String, String>();
         headers.put(SpiFlyConstants.SPI_CONSUMER_HEADER, "javax.xml.parsers.DocumentBuilderFactory#newInstance();bundleId=0");
         Bundle consumerBundle = mockConsumerBundle(headers, providerBundle, systembundle);
 
-        WeavingHook wh = new ClientWeavingHook(mockSpiFlyBundle(consumerBundle, providerBundle, systembundle).getBundleContext());
+        WeavingHook wh = new ClientWeavingHook(mockSpiFlyBundle(consumerBundle, providerBundle, systembundle).getBundleContext(), activator);
 
         URL clsUrl = getClass().getResource("JaxpClient.class");
         WovenClass wc = new MyWovenClass(clsUrl, "org.apache.aries.spifly.JaxpClient", consumerBundle);
         wh.weave(wc);
-        
+
         Class<?> cls = wc.getDefinedClass();
         Method method = cls.getMethod("test", new Class [] {});
         Class<?> result = (Class<?>) method.invoke(cls.newInstance());
-        Assert.assertEquals("JAXP implementation from JRE", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl", result.getName());                
+        Assert.assertEquals("JAXP implementation from JRE", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl", result.getName());
     }
 
     @Test
@@ -452,28 +465,28 @@ public class ClientWeavingHookTest {
         Bundle systembundle = mockSystemBundle();
 
         Bundle providerBundle = mockProviderBundle("impl3", 1);
-        Activator.activator.registerProviderBundle("javax.xml.parsers.DocumentBuilderFactory", providerBundle);
+        activator.registerProviderBundle("javax.xml.parsers.DocumentBuilderFactory", providerBundle);
 
         Dictionary<String, String> headers = new Hashtable<String, String>();
         headers.put(SpiFlyConstants.SPI_CONSUMER_HEADER, "javax.xml.parsers.DocumentBuilderFactory#newInstance();bundle=impl3");
         Bundle consumerBundle = mockConsumerBundle(headers, providerBundle, systembundle);
-        
-        WeavingHook wh = new ClientWeavingHook(mockSpiFlyBundle(consumerBundle, providerBundle, systembundle).getBundleContext());
+
+        WeavingHook wh = new ClientWeavingHook(mockSpiFlyBundle(consumerBundle, providerBundle, systembundle).getBundleContext(), activator);
 
         URL clsUrl = getClass().getResource("JaxpClient.class");
         WovenClass wc = new MyWovenClass(clsUrl, "org.apache.aries.spifly.JaxpClient", consumerBundle);
         wh.weave(wc);
-        
+
         Class<?> cls = wc.getDefinedClass();
         Method method = cls.getMethod("test", new Class [] {});
         Class<?> result = (Class<?>) method.invoke(cls.newInstance());
-        Assert.assertEquals("JAXP implementation from alternative bundle", "org.apache.aries.spifly.impl3.MyAltDocumentBuilderFactory", result.getName());                        
+        Assert.assertEquals("JAXP implementation from alternative bundle", "org.apache.aries.spifly.impl3.MyAltDocumentBuilderFactory", result.getName());
     }
-    
+
     private Bundle mockSpiFlyBundle(Bundle ... bundles) throws Exception {
         return mockSpiFlyBundle("spifly", new Version(1, 0, 0), bundles);
     }
-    
+
     private Bundle mockSpiFlyBundle(String bsn, Version version, Bundle ... bundles) throws Exception {
         Bundle spiFlyBundle = EasyMock.createMock(Bundle.class);
 
@@ -490,22 +503,23 @@ public class ClientWeavingHookTest {
         EasyMock.replay(spiFlyBundle);
 
         // Set the bundle context for testing purposes
-        Field bcField = Activator.class.getDeclaredField("bundleContext");
+        Field bcField = BaseActivator.class.getDeclaredField("bundleContext");
         bcField.setAccessible(true);
-        bcField.set(Activator.activator, spiFlyBundle.getBundleContext());
-        
+        bcField.set(activator, spiFlyBundle.getBundleContext());
+
         return spiFlyBundle;
     }
 
     private Bundle mockProviderBundle(String subdir, long id) throws Exception {
         return mockProviderBundle(subdir, id, Version.emptyVersion);
     }
-    
+
     private Bundle mockProviderBundle(String subdir, long id, Version version) throws Exception {
         URL url = getClass().getResource("/" + getClass().getName().replace('.', '/') + ".class");
         File classFile = new File(url.getFile());
         File baseDir = new File(classFile.getParentFile(), subdir);
         File directory = new File(baseDir, "/META-INF/services");
+        final List<String> classNames = new ArrayList<String>();
 
         // Do a directory listing of the applicable META-INF/services directory
         List<String> resources = new ArrayList<String>();
@@ -513,8 +527,9 @@ public class ClientWeavingHookTest {
             String fileName = f.getName();
             if (fileName.startsWith(".") || fileName.endsWith("."))
                 continue;
-            
-            
+
+            classNames.addAll(getClassNames(f));
+
             // Needs to be something like: META-INF/services/org.apache.aries.mytest.MySPI
             String path = f.getAbsolutePath().substring(baseDir.getAbsolutePath().length());
             path = path.replace('\\', '/');
@@ -523,16 +538,20 @@ public class ClientWeavingHookTest {
             }
             resources.add(path);
         }
-            
-        // Set up the classloader that will be used by the ASM-generated code as the TCCL. 
+
+        // Set up the classloader that will be used by the ASM-generated code as the TCCL.
         // It can load a META-INF/services file
-        ClassLoader cl = new TestImplClassLoader(subdir, resources.toArray(new String [] {}));
-        
+        final ClassLoader cl = new TestImplClassLoader(subdir, resources.toArray(new String [] {}));
+
         // The BundleWiring API is used on the bundle by the generated code to obtain its classloader
         BundleWiring bw = EasyMock.createMock(BundleWiring.class);
         EasyMock.expect(bw.getClassLoader()).andReturn(cl).anyTimes();
         EasyMock.replay(bw);
-        
+
+        List<String> classResources = new ArrayList<String>();
+        for(String className : classNames) {
+            classResources.add("/" + className.replace('.', '/') + ".class");
+        }
         Bundle providerBundle = EasyMock.createMock(Bundle.class);
         EasyMock.expect(providerBundle.adapt(BundleWiring.class)).andReturn(bw).anyTimes();
         String bsn = subdir;
@@ -543,21 +562,47 @@ public class ClientWeavingHookTest {
         EasyMock.expect(providerBundle.getSymbolicName()).andReturn(bsn).anyTimes();
         EasyMock.expect(providerBundle.getBundleId()).andReturn(id).anyTimes();
         EasyMock.expect(providerBundle.getVersion()).andReturn(version).anyTimes();
+        EasyMock.expect(providerBundle.getEntryPaths("/")).andReturn(Collections.enumeration(classResources)).anyTimes();
+        EasyMock.<Class<?>>expect(providerBundle.loadClass(EasyMock.anyObject(String.class))).andAnswer(new IAnswer<Class<?>>() {
+            @Override
+            public Class<?> answer() throws Throwable {
+                String  name = (String) EasyMock.getCurrentArguments()[0];
+                if (!classNames.contains(name)) {
+                    throw new ClassCastException(name);
+                }
+                return cl.loadClass(name);
+            }
+        }).anyTimes();
         EasyMock.replay(providerBundle);
         return providerBundle;
     }
 
+    private Collection<String> getClassNames(File f) throws IOException {
+        List<String> names = new ArrayList<String>();
+
+        BufferedReader br = new BufferedReader(new FileReader(f));
+        try {
+            String line = null;
+            while((line = br.readLine()) != null) {
+                names.add(line.trim());
+            }
+        } finally {
+            br.close();
+        }
+        return names;
+    }
+
     private Bundle mockConsumerBundle(Dictionary<String, String> headers, Bundle ... otherBundles) {
-        // Create a mock object for the client bundle which holds the code that uses ServiceLoader.load() 
+        // Create a mock object for the client bundle which holds the code that uses ServiceLoader.load()
         // or another SPI invocation.
         BundleContext bc = EasyMock.createMock(BundleContext.class);
-        
+
         Bundle consumerBundle = EasyMock.createMock(Bundle.class);
         EasyMock.expect(consumerBundle.getSymbolicName()).andReturn("testConsumer").anyTimes();
         EasyMock.expect(consumerBundle.getHeaders()).andReturn(headers).anyTimes();
         EasyMock.expect(consumerBundle.getBundleContext()).andReturn(bc).anyTimes();
         EasyMock.expect(consumerBundle.getBundleId()).andReturn(Long.MAX_VALUE).anyTimes();
-        EasyMock.replay(consumerBundle);        
+        EasyMock.replay(consumerBundle);
 
         List<Bundle> allBundles = new ArrayList<Bundle>(Arrays.asList(otherBundles));
         allBundles.add(consumerBundle);
@@ -566,23 +611,23 @@ public class ClientWeavingHookTest {
 
         return consumerBundle;
     }
-    
+
     private Bundle mockSystemBundle() {
         Bundle systemBundle = EasyMock.createMock(Bundle.class);
         EasyMock.expect(systemBundle.getBundleId()).andReturn(0L).anyTimes();
         EasyMock.expect(systemBundle.getSymbolicName()).andReturn("system.bundle").anyTimes();
         EasyMock.replay(systemBundle);
-        
+
         return systemBundle;
     }
-            
+
     public static class TestImplClassLoader extends URLClassLoader {
         private final List<String> resources;
         private final String prefix;
-        
+
         public TestImplClassLoader(String subdir, String ... resources) {
             super(new URL [] {}, TestImplClassLoader.class.getClassLoader());
-            
+
             this.prefix = TestImplClassLoader.class.getPackage().getName().replace('.', '/') + "/" + subdir + "/";
             this.resources = Arrays.asList(resources);
         }
@@ -604,7 +649,7 @@ public class ClientWeavingHookTest {
                 return super.findResources(name);
             }
         }
-    }    
+    }
 
     private static class MyWovenClass implements WovenClass {
         byte [] bytes;
@@ -612,7 +657,7 @@ public class ClientWeavingHookTest {
         final Bundle bundleContainingOriginalClass;
         List<String> dynamicImports = new ArrayList<String>();
         boolean weavingComplete = false;
-        
+
         private MyWovenClass(URL clazz, String name, Bundle bundle) throws Exception {
             bytes = Streams.suck(clazz.openStream());
             className = name;
@@ -668,20 +713,20 @@ public class ClientWeavingHookTest {
             return bw;
         }
     }
-    
+
     private static class MyWovenClassClassLoader extends ClassLoader implements BundleReference {
         private final String className;
         private final Bundle bundle;
         private final byte [] bytes;
-        
+
         public MyWovenClassClassLoader(String className, byte[] bytes, ClassLoader parent, Bundle bundle) {
             super(parent);
-            
+
             this.className = className;
             this.bundle = bundle;
-            this.bytes = bytes;            
+            this.bytes = bytes;
         }
-        
+
         @Override
         protected synchronized Class<?> loadClass(String name, boolean resolve)
                 throws ClassNotFoundException {
@@ -701,5 +746,5 @@ public class ClientWeavingHookTest {
         public Bundle getBundle() {
             return bundle;
         }
-    }    
+    }
 }

Copied: aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/spifly/dynamic/TestClient.java (from r1084722, aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/spifly/TestClient.java)
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/spifly/dynamic/TestClient.java?p2=aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/spifly/dynamic/TestClient.java&p1=aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/spifly/TestClient.java&r1=1084722&r2=1088438&rev=1088438&view=diff
==============================================================================
--- aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/spifly/TestClient.java (original)
+++ aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/spifly/dynamic/TestClient.java Sun Apr  3 23:33:12 2011
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.aries.spifly;
+package org.apache.aries.spifly.dynamic;
 
 import java.util.ServiceLoader;
 

Added: aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/spifly/dynamic/impl1/MySPIImpl1.java
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/spifly/dynamic/impl1/MySPIImpl1.java?rev=1088438&view=auto
==============================================================================
--- aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/spifly/dynamic/impl1/MySPIImpl1.java (added)
+++ aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/java/org/apache/aries/spifly/dynamic/impl1/MySPIImpl1.java Sun Apr  3 23:33:12 2011
@@ -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.dynamic.impl1;
+
+import org.apache.aries.mytest.MySPI;
+
+public class MySPIImpl1 implements MySPI{
+    @Override
+    public String someMethod(String s) {
+        return new StringBuilder(s).reverse().toString();
+    }
+}

Added: aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/resources/org/apache/aries/spifly/dynamic/impl1/META-INF/services/org.apache.aries.mytest.MySPI
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/resources/org/apache/aries/spifly/dynamic/impl1/META-INF/services/org.apache.aries.mytest.MySPI?rev=1088438&view=auto
==============================================================================
--- aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/resources/org/apache/aries/spifly/dynamic/impl1/META-INF/services/org.apache.aries.mytest.MySPI (added)
+++ aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/test/resources/org/apache/aries/spifly/dynamic/impl1/META-INF/services/org.apache.aries.mytest.MySPI Sun Apr  3 23:33:12 2011
@@ -0,0 +1 @@
+org.apache.aries.spifly.impl1.MySPIImpl1

Modified: aries/trunk/spi-fly/spi-fly-static-bundle/src/main/java/org/apache/aries/spifly/staticbundle/StaticWeavingActivator.java
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-static-bundle/src/main/java/org/apache/aries/spifly/staticbundle/StaticWeavingActivator.java?rev=1088438&r1=1088437&r2=1088438&view=diff
==============================================================================
--- aries/trunk/spi-fly/spi-fly-static-bundle/src/main/java/org/apache/aries/spifly/staticbundle/StaticWeavingActivator.java (original)
+++ aries/trunk/spi-fly/spi-fly-static-bundle/src/main/java/org/apache/aries/spifly/staticbundle/StaticWeavingActivator.java Sun Apr  3 23:33:12 2011
@@ -1,3 +1,21 @@
+/**
+ * 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.staticbundle;
 
 import org.apache.aries.spifly.BaseActivator;



Mime
View raw message