You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by da...@apache.org on 2010/12/23 14:37:56 UTC
svn commit: r1052267 - in
/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook:
SpiFly/src/org/apache/aries/spifly/ClientWeavingHook.java
SpiFlyTests/src/org/apache/aries/spifly/ClientWeavingHookTest.java
Author: davidb
Date: Thu Dec 23 13:37:56 2010
New Revision: 1052267
URL: http://svn.apache.org/viewvc?rev=1052267&view=rev
Log:
Additional tests passing.
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/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=1052267&r1=1052266&r2=1052267&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 13:37:56 2010
@@ -158,7 +158,12 @@ public class ClientWeavingHook implement
String bsn = element.getAttribute("bundle");
if (bsn != null) {
- allowedBundles.add(new BundleDescriptor(bsn));
+ bsn = bsn.trim();
+ if (bsn.length() > 0) {
+ for (String s : bsn.split("\\|")) {
+ allowedBundles.add(new BundleDescriptor(s));
+ }
+ }
}
// TODO bundle version
@@ -166,12 +171,16 @@ public class ClientWeavingHook implement
String bid = element.getAttribute("bundleId");
if (bid != null) {
bid = bid.trim();
- for (Bundle b : consumerBundle.getBundleContext().getBundles()) {
- if (("" + b.getBundleId()).equals(bid)) {
- allowedBundles.add(new BundleDescriptor(b.getSymbolicName()));
- break;
+ if (bid.length() > 0) {
+ for (String s : bid.split("\\|")) {
+ for (Bundle b : consumerBundle.getBundleContext().getBundles()) {
+ if (("" + b.getBundleId()).equals(s)) {
+ allowedBundles.add(new BundleDescriptor(b.getSymbolicName()));
+ break;
+ }
+ }
}
- }
+ }
}
// TODO fix log message
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=1052267&r1=1052266&r2=1052267&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 13:37:56 2010
@@ -213,6 +213,70 @@ public class ClientWeavingHookTest {
}
@Test
+ public void testClientMultipleTargetBundles() throws Exception {
+ Dictionary<String, String> headers = new Hashtable<String, String>();
+ 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);
+
+ Bundle consumerBundle = mockConsumerBundle(headers, providerBundle1, providerBundle2, providerBundle4);
+ Bundle spiFlyBundle = mockSpiFlyBundle(consumerBundle, providerBundle1, providerBundle2, providerBundle4);
+ WeavingHook wh = new ClientWeavingHook(spiFlyBundle.getBundleContext());
+
+ // 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
+ // 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);
+ }
+
+ @Test
+ public void testClientMultipleTargetBundles2() throws Exception {
+ Dictionary<String, String> headers = new Hashtable<String, String>();
+ 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);
+
+ Bundle consumerBundle = mockConsumerBundle(headers, providerBundle1, providerBundle2, providerBundle4);
+ Bundle spiFlyBundle = mockSpiFlyBundle(consumerBundle, providerBundle1, providerBundle2, providerBundle4);
+ WeavingHook wh = new ClientWeavingHook(spiFlyBundle.getBundleContext());
+
+ // 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
+ // 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);
+ }
+
+ @Test
public void testClientSpecificProviderLoadArgument() throws Exception {
Dictionary<String, String> headers = new Hashtable<String, String>();
headers.put(SpiFlyConstants.SPI_CONSUMER_HEADER,