You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by jw...@apache.org on 2015/09/25 19:24:04 UTC

svn commit: r1705334 - 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/defect/

Author: jwross
Date: Fri Sep 25 17:24:04 2015
New Revision: 1705334

URL: http://svn.apache.org/viewvc?rev=1705334&view=rev
Log:
ARIES-1328 Application subsystem does not import service capabilities

Add test.

Stop filtering out osgi.service when generating the Require-Capability header and relying solely on Subsystem-ImportService. When
creating the import sharing policy using the resolution, create region filters for both the osgi.service (for service capability
resolution) and org.eclipse.equinox.allow.service (for service registration visibility) namespaces.

Added:
    aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1328Test.java
Modified:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RawSubsystemResource.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResource.java

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RawSubsystemResource.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RawSubsystemResource.java?rev=1705334&r1=1705333&r2=1705334&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RawSubsystemResource.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RawSubsystemResource.java Fri Sep 25 17:24:04 2015
@@ -367,9 +367,11 @@ public class RawSubsystemResource implem
 		ArrayList<RequireCapabilityHeader.Clause> clauses = new ArrayList<RequireCapabilityHeader.Clause>();
 		for (Requirement requirement : requirements) {
 			String namespace = requirement.getNamespace();
-			if (namespace.startsWith("osgi.") &&
-					// Don't filter out the osgi.ee namespace.
-					!namespace.equals(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE))
+			if (namespace.startsWith("osgi.") && !(
+					// Don't filter out the osgi.ee namespace...
+					namespace.equals(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE) ||
+					// ...or the osgi.service namespace.
+					namespace.equals(ServiceNamespace.SERVICE_NAMESPACE)))
 				continue;
 			clauses.add(RequireCapabilityHeader.Clause.valueOf(requirement));
 		}

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=1705334&r1=1705333&r2=1705334&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 Fri Sep 25 17:24:04 2015
@@ -613,18 +613,20 @@ public class SubsystemResource implement
 				// The provider is not content, so the requirement must
 				// be added to the sharing policy.
 				Requirement requirement = wire.getRequirement();
-				String namespace = requirement.getNamespace();
-				if (ServiceNamespace.SERVICE_NAMESPACE.equals(namespace)) {
-					// The osgi.service namespace must be translated to one
-					// that region digraph understands.
-					namespace = RegionFilter.VISIBLE_SERVICE_NAMESPACE;
+				List<String> namespaces = new ArrayList<String>(2);
+				namespaces.add(requirement.getNamespace());
+				if (ServiceNamespace.SERVICE_NAMESPACE.equals(namespaces.get(0))) {
+					// Both service capabilities and services must be visible.
+					namespaces.add(RegionFilter.VISIBLE_SERVICE_NAMESPACE);
 				}
 				String filter = requirement.getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
 				if (filter == null) {
-					builder.allowAll(namespace);
+					for (String namespace : namespaces)
+						builder.allowAll(namespace);
 				}
 				else {
-					builder.allow(namespace, filter);
+					for (String namespace : namespaces)
+						builder.allow(namespace, filter);
 				}
 			}
 		}

Added: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1328Test.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1328Test.java?rev=1705334&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1328Test.java (added)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1328Test.java Fri Sep 25 17:24:04 2015
@@ -0,0 +1,127 @@
+/*
+ * 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.subsystem.itests.defect;
+
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.aries.subsystem.itests.SubsystemTest;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.service.subsystem.Subsystem;
+import org.osgi.service.subsystem.SubsystemConstants;
+import org.osgi.service.subsystem.SubsystemException;
+
+/*
+ * https://issues.apache.org/jira/browse/ARIES-1419
+ * 
+ * Provide-Capability header parser does not support typed attributes.
+ */
+public class Aries1328Test extends SubsystemTest {
+    /*
+     * Subsystem-SymbolicName: application.a.esa
+     * 
+     * Included In Archive:
+     * 		bundle.a.jar
+     */
+    private static final String APPLICATION_A = "application.a.esa";
+	/*
+	 * Bundle-SymbolicName: bundle.a.jar
+	 * Require-Capability: osgi.service;filter:="(objectClass=service.a)",
+	 *  osgi.service;filter:="(objectClass=service.b)";effective:=resolve
+	 */
+	private static final String BUNDLE_A = "bundle.a.jar";
+	/*
+	 * Bundle-SymbolicName: bundle.b.jar
+	 * Provide-Capability: osgi.service;objectClass=service.a",
+	 *  osgi.service;objectClass=service.b
+	 */
+	private static final String BUNDLE_B = "bundle.b.jar";
+	
+	private static boolean createdTestFiles;
+	
+	@Before
+	public void createTestFiles() throws Exception {
+		if (createdTestFiles)
+			return;
+		createBundleA();
+		createBundleB();
+		createApplicationA();
+		createdTestFiles = true;
+	}
+	
+	private void createBundleA() throws IOException {
+		createBundle(
+				name(BUNDLE_A), 
+				requireCapability("osgi.service;filter:=\"(objectClass=service.a)\"" +
+						", osgi.service;filter:=\"(objectClass=service.b)\";effective:=resolve"));
+	}
+	
+	private void createBundleB() throws IOException {
+		createBundle(
+				name(BUNDLE_B), 
+				provideCapability("osgi.service;objectClass=service.a, osgi.service;objectClass=service.b"));
+	}
+    
+    private static void createApplicationA() throws IOException {
+        createApplicationAManifest();
+        createSubsystem(APPLICATION_A, BUNDLE_A);
+    }
+    
+    private static void createApplicationAManifest() throws IOException {
+        Map<String, String> attributes = new HashMap<String, String>();
+        attributes.put(SubsystemConstants.SUBSYSTEM_SYMBOLICNAME, APPLICATION_A);
+        createManifest(APPLICATION_A + ".mf", attributes);
+    }
+    
+    @Test 
+    public void testServiceAndRequireCapabilityInServiceNamespaceVisibilityInImportSharingPolicy() throws Exception {
+    	Bundle bundleB = installBundleFromFile(BUNDLE_B);
+    	try {
+    		// Install application A containing content bundle A requiring two
+    		// service capabilities each with effective:=resolve. Both the
+    		// services and service capabilities should be visible to the
+    		// bundle.
+    		Subsystem applicationA = installSubsystemFromFile(APPLICATION_A);
+    		try {
+    			// Start the application to ensure the runtime resolution
+    			// succeeds.
+    			applicationA.start();
+    		}
+    		catch (SubsystemException e) {
+    			e.printStackTrace();
+    			fail("Subsystem should have started");
+    		}
+    		finally {
+    			stopAndUninstallSubsystemSilently(applicationA);
+    		}
+    	}
+    	catch (SubsystemException e) {
+    		e.printStackTrace();
+    		fail("Subsystem should have installed");
+    	}
+    	finally {
+    		uninstallSilently(bundleB);
+    	}
+    }
+}