aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tjwat...@apache.org
Subject svn commit: r1609285 - in /aries/trunk/subsystem: subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/
Date Wed, 09 Jul 2014 20:18:31 GMT
Author: tjwatson
Date: Wed Jul  9 20:18:31 2014
New Revision: 1609285

URL: http://svn.apache.org/r1609285
Log:
ARIES-1222: Should make osgi.ee and osgi.native capabilities available to all subsystems

Modified:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/DependencyCalculator.java
    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/ResolutionTest.java
    aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/DependencyCalculator.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/DependencyCalculator.java?rev=1609285&r1=1609284&r2=1609285&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/DependencyCalculator.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/DependencyCalculator.java
Wed Jul  9 20:18:31 2014
@@ -23,6 +23,7 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.osgi.framework.Constants;
+import org.osgi.framework.namespace.ExecutionEnvironmentNamespace;
 import org.osgi.framework.namespace.IdentityNamespace;
 import org.osgi.resource.Capability;
 import org.osgi.resource.Requirement;
@@ -34,6 +35,8 @@ import org.osgi.service.resolver.Resolut
 import org.osgi.service.resolver.Resolver;
 
 public class DependencyCalculator {
+	// TODO replace with NativeNamespace constant in R6.
+	static final String NATIVE_NAMESPACE = "osgi.native";
 	private static class ResolveContext extends
 			org.osgi.service.resolver.ResolveContext {
 		private final Collection<Resource> resources;
@@ -45,11 +48,15 @@ public class DependencyCalculator {
 		@Override
 		public List<Capability> findProviders(Requirement requirement) {
 			ArrayList<Capability> capabilities = new ArrayList<Capability>();
-			for (Resource resource : resources)
-				for (Capability capability : resource
-						.getCapabilities(requirement.getNamespace()))
-					if (ResourceHelper.matches(requirement, capability))
-						capabilities.add(capability);
+			// never check local resources for osgi.ee or osgi.native capabilities
+			if (!(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE.equals(requirement.getNamespace())

+					|| NATIVE_NAMESPACE.equals(requirement.getNamespace()))) {
+				for (Resource resource : resources)
+					for (Capability capability : resource
+							.getCapabilities(requirement.getNamespace()))
+						if (ResourceHelper.matches(requirement, capability))
+							capabilities.add(capability);
+			}
 			if (capabilities.isEmpty())
 				capabilities.add(new MissingCapability(requirement));
 			capabilities.trimToSize();

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=1609285&r1=1609284&r2=1609285&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
Wed Jul  9 20:18:31 2014
@@ -54,6 +54,7 @@ import org.osgi.framework.BundleExceptio
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.hooks.weaving.WeavingHook;
+import org.osgi.framework.namespace.ExecutionEnvironmentNamespace;
 import org.osgi.framework.namespace.IdentityNamespace;
 import org.osgi.framework.wiring.BundleRevision;
 import org.osgi.resource.Capability;
@@ -505,6 +506,12 @@ public class SubsystemResource implement
 			public List<Capability> findProviders(Requirement requirement) {
 				List<Capability> result = new ArrayList<Capability>();
 				try {
+					// Only check the system repository for osgi.ee and osgi.native
+					if (ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE.equals(requirement.getNamespace())

+							|| DependencyCalculator.NATIVE_NAMESPACE.equals(requirement.getNamespace())) {
+						addDependenciesFromSystemRepository(requirement, result);
+						return result;
+					}
 					if (addDependenciesFromContentRepository(requirement, result))
 						return result;
 					if (addDependenciesFromPreferredProviderRepository(requirement, result))
@@ -725,6 +732,9 @@ public class SubsystemResource implement
 			setImportIsolationPolicy(builder, (SubsystemImportServiceHeader)header);
 			header = getSubsystemManifest().getRequireBundleHeader();
 			setImportIsolationPolicy(builder, (RequireBundleHeader)header);
+			// Always add access to osgi.ee and osgi.native namespaces
+			setImplicitAccessToNativeAndEECapabilities(builder);
+
 		}
 		RegionFilter regionFilter = builder.build();
 		from.connectRegion(to, regionFilter);
@@ -793,6 +803,12 @@ public class SubsystemResource implement
 		}
 	}
 	
+
+	private void setImplicitAccessToNativeAndEECapabilities(RegionFilterBuilder builder) {
+		builder.allowAll(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE);
+		builder.allowAll(DependencyCalculator.NATIVE_NAMESPACE);
+	}
+
 	private void setImportIsolationPolicy(RegionFilterBuilder builder, SubsystemImportServiceHeader
header) throws InvalidSyntaxException {
 		if (header == null)
 			return;

Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/ResolutionTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/ResolutionTest.java?rev=1609285&r1=1609284&r2=1609285&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/ResolutionTest.java
(original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/ResolutionTest.java
Wed Jul  9 20:18:31 2014
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertTru
 import static org.junit.Assert.fail;
 
 import java.io.IOException;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -57,6 +58,15 @@ public class ResolutionTest extends Subs
 	 */
 	private static final String APPLICATION_C = "application.c.esa";
 	/*
+	 * Subsystem-SymbolicName: application.d.esa
+	 * Subsystem-Content: bundle.f.jar
+	 */
+	private static final String APPLICATION_D = "application.d.esa";
+	/* Subsystem-SymbolicName: application.e.esa
+	 * Subsystem-Content: bundle.g.jar
+	 */
+	private static final String APPLICATION_E = "application.e.esa";
+	/*
 	 * Bundle-SymbolicName: bundle.a.jar
 	 * Require-Capability: a
 	 */
@@ -82,6 +92,24 @@ public class ResolutionTest extends Subs
 	 * Bundle-RequiredExecutionEnvironment: J2SE-1.4, J2SE-1.5,		J2SE-1.6,JavaSE-1.7
 	 */
 	private static final String BUNDLE_E = "bundle.e.jar";
+
+	/*
+	 * Bundle-SymbolicName: bundle.f.jar
+	 * Bundle-NativeCode: \
+	 *   native.file; osname=Linux; processor=x86, \
+	 *   native.file; osname=Linux; processor=x86-64, \
+	 *   native.file; osname=Win32; processor=x86, \
+	 *   native.file; osname=Win32; processor=x86-64, \
+	 *   native.file; osname="mac os x"; processor=x86-64
+	 */
+	private static final String BUNDLE_F = "bundle.f.jar";
+
+	/*
+	 * Bundle-SymbolicName: bundle.f.jar
+	 * Bundle-NativeCode: \
+	 *   native.file; osname=noMatch; processor=noMatch
+	 */
+	private static final String BUNDLE_G = "bundle.g.jar";
 	
 	@Before
 	public void createApplications() throws Exception {
@@ -93,9 +121,13 @@ public class ResolutionTest extends Subs
 		createBundleC();
 		createBundleD();
 		createBundleE();
+		createBundleF();
+		createBundleG();
 		createApplicationA();
 		createApplicationB();
 		createApplicationC();
+		createApplicationD();
+		createApplicationE();
 		createdApplications = true;
 	}
 	
@@ -131,7 +163,29 @@ public class ResolutionTest extends Subs
 		attributes.put(SubsystemConstants.SUBSYSTEM_SYMBOLICNAME, APPLICATION_C);
 		createManifest(APPLICATION_C + ".mf", attributes);
 	}
-	
+
+	private static void createApplicationD() throws IOException {
+		createApplicationDManifest();
+		createSubsystem(APPLICATION_D, BUNDLE_F);
+	}
+
+	private static void createApplicationDManifest() throws IOException {
+		Map<String, String> attributes = new HashMap<String, String>();
+		attributes.put(SubsystemConstants.SUBSYSTEM_SYMBOLICNAME, APPLICATION_D);
+		createManifest(APPLICATION_D + ".mf", attributes);
+	}
+
+	private static void createApplicationE() throws IOException {
+		createApplicationEManifest();
+		createSubsystem(APPLICATION_E, BUNDLE_G);
+	}
+
+	private static void createApplicationEManifest() throws IOException {
+		Map<String, String> attributes = new HashMap<String, String>();
+		attributes.put(SubsystemConstants.SUBSYSTEM_SYMBOLICNAME, APPLICATION_E);
+		createManifest(APPLICATION_E + ".mf", attributes);
+	}
+
 	private void createBundleA() throws IOException {
 		createBundle(name(BUNDLE_A), new Header(Constants.REQUIRE_CAPABILITY, "a"));
 	}
@@ -156,6 +210,19 @@ public class ResolutionTest extends Subs
 		createBundle(name(BUNDLE_E), new Header(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT,
"J2SE-1.4, J2SE-1.5,		J2SE-1.6,JavaSE-1.7"));
 	}
 	
+	private void createBundleF() throws IOException {
+		createBundle(Collections.singletonList("native.file"), name(BUNDLE_F), new Header(Constants.BUNDLE_NATIVECODE,
+				"native.file; osname=Linux; processor=x86,"
+				+ "native.file; osname=Linux; processor=x86-64,"
+				+ "native.file; osname=Win32; processor=x86,"
+				+ "native.file; osname=Win32; processor=x86-64,"
+				+ "native.file; osname=\"MacOSX\"; processor=x86-64"));
+	}
+	private void createBundleG() throws IOException {
+		createBundle(Collections.singletonList("native.file"), name(BUNDLE_G), new Header(Constants.BUNDLE_NATIVECODE,
+				"native.file; osname=noMatch; processor=noMatch"));
+	}
+
 	/*
 	 * Test that the right regions are used when validating capabilities.
 	 * 
@@ -250,4 +317,42 @@ public class ResolutionTest extends Subs
 			uninstallSubsystemSilently(applicationC);
 		}
 	}
+
+	@Test
+	public void testNativeCodeRequirement() throws Exception {
+		Subsystem applicationD = null;
+		try {
+			applicationD = installSubsystemFromFile(APPLICATION_D);
+			applicationD.start();
+		}
+		catch (Exception e) {
+			e.printStackTrace();
+			fail("Installation should succeed for Bundle-NativeCode");
+		}
+		finally {
+			uninstallSubsystemSilently(applicationD);
+		}
+	}
+
+	@Test
+	public void testMissingNativeCodeRequirement() throws Exception {
+		Subsystem applicationE = null;
+		try {
+			applicationE = installSubsystemFromFile(APPLICATION_E);
+			// TODO this should fail to intsall
+		} catch (SubsystemException e) {
+			e.printStackTrace();
+			fail("Installation should succeed for Bundle-NativeCode");
+		}
+		try {
+			applicationE.start();
+			fail("Expected to fail to install");
+		}
+		catch (Exception e) {
+			// expected 
+		}
+		finally {
+			uninstallSubsystemSilently(applicationE);
+		}
+	}
 }

Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java?rev=1609285&r1=1609284&r2=1609285&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java
(original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java
Wed Jul  9 20:18:31 2014
@@ -37,6 +37,7 @@ import java.lang.reflect.Field;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.List;
@@ -630,16 +631,19 @@ public abstract class SubsystemTest exte
 	protected Header provideCapability(String capability) {
 		return new Header(Constants.PROVIDE_CAPABILITY, capability);
 	}
-	
 	protected static void createBundle(Header...  headers) throws IOException {
+		createBundle(Collections.<String> emptyList(), headers);
+	}
+
+	protected static void createBundle(List<String> emptyFiles, Header...  headers) throws
IOException {
 		HashMap<String, String> headerMap = new HashMap<String, String>();
 		for (Header header : headers) {
 			headerMap.put(header.key, header.value);
 		}
-		createBundle(headerMap);
+		createBundle(emptyFiles, headerMap);
 	}
 	
-	private static void createBundle(Map<String, String> headers) throws IOException 
+	private static void createBundle(List<String> emptyFiles, Map<String, String>
headers) throws IOException 
 	{
 		String symbolicName = headers.get(Constants.BUNDLE_SYMBOLICNAME);
 		JarFixture bundle = ArchiveFixture.newJar();
@@ -647,6 +651,9 @@ public abstract class SubsystemTest exte
 		for (Entry<String, String> header : headers.entrySet()) {
 			manifest.attribute(header.getKey(), header.getValue());
 		}
+		for (String path : emptyFiles) {
+			bundle.file(path).end();
+		}
 		write(symbolicName, bundle);
 	}
 	



Mime
View raw message