aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mnutt...@apache.org
Subject svn commit: r1360774 - in /aries/trunk/subsystem: subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResource.java subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/DynamicImportTest.java
Date Thu, 12 Jul 2012 16:31:12 GMT
Author: mnuttall
Date: Thu Jul 12 16:31:12 2012
New Revision: 1360774

URL: http://svn.apache.org/viewvc?rev=1360774&view=rev
Log:
Aries-868: First pass at an approach to handling woven packages

Modified:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResource.java
    aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/DynamicImportTest.java

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResource.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResource.java?rev=1360774&r1=1360773&r2=1360774&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResource.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResource.java
Thu Jul 12 16:31:12 2012
@@ -41,12 +41,16 @@ import org.apache.aries.subsystem.core.a
 import org.apache.aries.subsystem.core.archive.SubsystemManifest;
 import org.apache.aries.util.filesystem.FileSystem;
 import org.apache.aries.util.filesystem.IDirectory;
+import org.apache.aries.util.manifest.ManifestHeaderProcessor;
 import org.eclipse.equinox.region.Region;
 import org.eclipse.equinox.region.RegionDigraph;
 import org.eclipse.equinox.region.RegionFilter;
 import org.eclipse.equinox.region.RegionFilterBuilder;
+import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.hooks.weaving.WeavingHook;
 import org.osgi.framework.namespace.IdentityNamespace;
 import org.osgi.framework.wiring.BundleRevision;
 import org.osgi.resource.Capability;
@@ -653,6 +657,31 @@ public class SubsystemResource implement
 			String filter = requirement.getDirectives().get(ImportPackageRequirement.DIRECTIVE_FILTER);
 			builder.allow(policy, filter);
 		}
+		
+		// work around https://www.osgi.org/bugzilla/show_bug.cgi?id=144 
+		// In the first instance, what if the various weaving services were to have a property,

+		// osgi.woven.packages, that was a comma separated list of packages that might be woven

+		// by that hook. 
+		Collection<String> wovenPackages = getWovenPackages();
+		for (String pkg : wovenPackages) { 
+			builder.allow(policy, "(osgi.wiring.package=" + pkg + ")");
+		}
+	}
+	
+	// First pass at this: really just a sketch. 
+	private Collection<String> getWovenPackages() throws InvalidSyntaxException
+	{
+		// Find all weaving services in our region
+		BundleContext bc = Activator.getInstance().getBundleContext();
+		Collection<ServiceReference<WeavingHook>> weavers = bc.getServiceReferences(WeavingHook.class,
null);
+		Collection<String> wovenPackages = new ArrayList<String>();
+		for (ServiceReference<WeavingHook> sr : weavers) { 
+			String someWovenPackages = (String) sr.getProperty("osgi.woven.packages");
+			if (someWovenPackages != null) { 
+				wovenPackages.addAll(ManifestHeaderProcessor.split(someWovenPackages, ","));
+			}
+		}
+		return wovenPackages;
 	}
 	
 	private void setImportIsolationPolicy(RegionFilterBuilder builder, RequireBundleHeader header)
throws InvalidSyntaxException {

Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/DynamicImportTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/DynamicImportTest.java?rev=1360774&r1=1360773&r2=1360774&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/DynamicImportTest.java
(original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/DynamicImportTest.java
Thu Jul 12 16:31:12 2012
@@ -1,10 +1,14 @@
 package org.apache.aries.subsystem.itests;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.ops4j.pax.exam.CoreOptions.options;
-import static org.ops4j.pax.exam.OptionUtils.combine;
 
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.aries.subsystem.itests.hello.api.Hello;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -12,7 +16,11 @@ import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.hooks.weaving.WeavingHook;
+import org.osgi.framework.hooks.weaving.WovenClass;
 import org.osgi.service.subsystem.Subsystem;
 import org.osgi.service.subsystem.SubsystemException;
 
@@ -46,9 +54,6 @@ public class DynamicImportTest extends S
 	@Test
 	public void verifyThatDynamicImportNeedsHandling() throws Exception
 	{
-		
-		System.out.println ("Into verifyThatDynamicImportNeedsHandling");
-		
 		Subsystem subsystem = installSubsystemFromFile ("dynamicImport.esa");
 		try { 
 			startSubsystem(subsystem);
@@ -63,8 +68,34 @@ public class DynamicImportTest extends S
 		}
 	}
 	
+	class TokenWeaver implements WeavingHook {
+		@Override
+		public void weave(WovenClass arg0) {} 
+	}
+	
+	@Test
+	public void testFirstPassWeavingApproach() throws Exception
+	{
+		Dictionary<String, String> props = new Hashtable<String, String>();
+		props.put("osgi.woven.packages", "some.woven.package, org.apache.aries.subsystem.itests.hello.api");
+		ServiceRegistration<?> sr = bundleContext.registerService(WeavingHook.class, new
TokenWeaver(), props);
+		
+		Subsystem subsystem = installSubsystemFromFile ("dynamicImport.esa");
+		startSubsystem(subsystem);
+		
+		BundleContext bc = subsystem.getBundleContext();
+		Hello h = getOsgiService(bc, Hello.class, null, DEFAULT_TIMEOUT);
+		String message = h.saySomething();
+		assertEquals ("Wrong message back", "Hello, this is something", message); // DynamicImportHelloImpl.java
+		
+		stopSubsystem(subsystem);
+		uninstallSubsystem(subsystem);
+		sr.unregister();
+		
+	}
+	
 	@Configuration
-	public static Option[] extraConfig() 
+	public static Option[] extraBundles() 
 	{
 		return options(
 				mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.itest.interfaces")



Mime
View raw message