aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwr...@apache.org
Subject svn commit: r1171761 - in /aries/trunk/subsystem: subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/ subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/...
Date Fri, 16 Sep 2011 20:20:16 GMT
Author: jwross
Date: Fri Sep 16 20:20:16 2011
New Revision: 1171761

URL: http://svn.apache.org/viewvc?rev=1171761&view=rev
Log:
ARIES-748: Update subsystems to use Equinox impl of org.osgi.service.resolver.Resolver

The initial API and implementation of the Equinox org.osgi.service.resolver (RFC 112) is available
in the master branches of the rt.equinox.bundles and rt.equinox.framework git repositories.
I updated subsystems to make use of it. Previously, a quick and dirty Resolver adaptor wrapped
around the existing Felix OBR implementation was used. Note the subsystems impl uses a registered
Resolver service, so making use of the Equinox resolver simply meant adding the bundle to
the itests project. When Felix releases their implementation of org.osgi.service.resolver,
the two will (hopefully) be interchangeable. 

Using the Equinox resolver highlighted some shortcomings in the subsystems implementation,
which were fixed and are listed below. 

(1) Updated subsystem-itests to bring in the Equinox resolver. 
(2) Updated SubsystemEnvironment to return all capabilities that match a requirement, even
those from the root subsystem (i.e. from the system bundle and any other already installed
bundles). Previously, Felix OBR had been automatically providing these via the Resolver adaptor
since Felix OBR has a built-in system repository. However, for the RFC 112 resolver, the expectation
is the Environment will provide everything. 
(3) Fixed an issue where the resource -> subsystem relationship was not being established
for resources in the root subsystem causing an NPE. 
(4) The FelixRequirementAdaptor must strip out the "mandatory:<*" clause from the filter
or InvalidSyntaxException occurs. 
(5) OsgiIdentityRequirement now includes the filter directive. 
(6) Added namespace translations to FelixResourceAdaptor.

Modified:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AriesSubsystem.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/OsgiIdentityRequirement.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/SubsystemEnvironment.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/FelixCapabilityAdapter.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/FelixRequirementAdapter.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/FelixResourceAdapter.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/OsgiCapabilityAdapter.java
    aries/trunk/subsystem/subsystem-itests/pom.xml
    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/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java?rev=1171761&r1=1171760&r2=1171761&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java
Fri Sep 16 20:20:16 2011
@@ -116,7 +116,19 @@ public class Activator implements Bundle
 	 * A naive implementation serving as a placeholder until a real Resolver comes along.
 	 */
 	public static Resolver getResolver() {
-		return new SubsystemResolver();
+//		return new SubsystemResolver();
+		ServiceTracker st = new ServiceTracker(context, Resolver.class.getName(), null);
+		try {
+			st.open();
+			return (Resolver)st.waitForService(5000);
+		}
+		catch (InterruptedException e) {
+			Thread.currentThread().interrupt();
+			return null;
+		}
+		finally {
+			st.close();
+		}
 	}
 	
 	private final BundleListener bundleListener = new SubsystemSynchronousBundleListener();

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AriesSubsystem.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AriesSubsystem.java?rev=1171761&r1=1171760&r2=1171761&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AriesSubsystem.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AriesSubsystem.java
Fri Sep 16 20:20:16 2011
@@ -700,6 +700,7 @@ public class AriesSubsystem implements S
 				}
 			}
 			catch (Exception e) {
+				// TODO Log this exception? If not, who's responsible for logging it?
 				coordination.fail(e);
 			}
 			finally {
@@ -713,7 +714,15 @@ public class AriesSubsystem implements S
 		Bundle bundle;
 		synchronized (resourceToSubsystems) {
 			if (resource instanceof BundleRevision) {
-				resourceToSubsystems.get(resource).add(this);
+				// This means the resource is a bundle that's already been installed, but we still need
to establish the resource->subsystem relationship.
+				// TODO The null check is necessary for when the bundle is in the root subsystem. Currently,
the root subsystem is not initialized with
+				// these relationships. Need to decide if that would be better.
+				Set<Subsystem> subsystems = resourceToSubsystems.get(resource);
+				if (subsystems == null) {
+					subsystems = new HashSet<Subsystem>();
+					resourceToSubsystems.put(resource, subsystems);
+				}
+				subsystems.add(this);
 				return;
 			}
 			provisionTo = getProvisionTo(resource, transitive);

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/OsgiIdentityRequirement.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/OsgiIdentityRequirement.java?rev=1171761&r1=1171760&r2=1171761&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/OsgiIdentityRequirement.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/OsgiIdentityRequirement.java
Fri Sep 16 20:20:16 2011
@@ -102,6 +102,7 @@ public class OsgiIdentityRequirement imp
 		this.filter = filter;
 		this.resource = resource;
 		this.transitive = transitive;
+		directives.put(Constants.FILTER_DIRECTIVE, filter.toString());
 		directives.put(ResourceConstants.IDENTITY_SINGLETON_DIRECTIVE, Boolean.FALSE.toString());
 		directives.put(Constants.EFFECTIVE_DIRECTIVE, Constants.EFFECTIVE_RESOLVE);
 	}

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/SubsystemEnvironment.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/SubsystemEnvironment.java?rev=1171761&r1=1171760&r2=1171761&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/SubsystemEnvironment.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/SubsystemEnvironment.java
Fri Sep 16 20:20:16 2011
@@ -69,6 +69,8 @@ public class SubsystemEnvironment implem
 		// This means we're looking for capabilities satisfying a requirement within a content
resource or transitive dependency.
 		findArchiveProviders(capabilities, requirement, false);
 		findRepositoryServiceProviders(capabilities, requirement, false);
+		// TODO The following is a quick fix to ensure this environment always returns capabilities
provided by the system bundle. Needs some more thought.
+		findConstituentProviders(requirement, capabilities);
 		return capabilities;
 	}
 	
@@ -89,11 +91,8 @@ public class SubsystemEnvironment implem
 
 	@Override
 	public Map<Resource, List<Wire>> getWiring() {
-		Map<Resource, List<Wire>> wiring = new HashMap<Resource, List<Wire>>();
-		for (Resource resource : resourceToRepository.keySet()) {
-			wiring.put(resource, Collections.EMPTY_LIST);
-		}
-		return wiring;
+		// TODO When will this ever return an existing wiring?
+		return Collections.EMPTY_MAP;
 	}
 	
 	public boolean isContentResource(Resource resource) {

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/FelixCapabilityAdapter.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/FelixCapabilityAdapter.java?rev=1171761&r1=1171760&r2=1171761&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/FelixCapabilityAdapter.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/FelixCapabilityAdapter.java
Fri Sep 16 20:20:16 2011
@@ -34,7 +34,9 @@ public class FelixCapabilityAdapter impl
 	}
 
 	public Map<String, Object> getAttributes() {
-		return capability.getPropertiesAsMap();
+		Map<String, Object> result = capability.getPropertiesAsMap();
+		result.put(getNamespace(), result.get(capability.getName()));
+		return result;
 	}
 
 	public Map<String, String> getDirectives() {

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/FelixRequirementAdapter.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/FelixRequirementAdapter.java?rev=1171761&r1=1171760&r2=1171761&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/FelixRequirementAdapter.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/FelixRequirementAdapter.java
Fri Sep 16 20:20:16 2011
@@ -42,7 +42,12 @@ public class FelixRequirementAdapter imp
 
 	public Map<String, String> getDirectives() {
 		Map<String, String> result = new HashMap<String, String>(1);
-		result.put(Constants.FILTER_DIRECTIVE, requirement.getFilter());
+		/* (1) The Felix OBR specific "mandatory:<*" syntax must be stripped out of the filter.
+		 * (2) The namespace must be translated.
+		 */
+		result.put(Constants.FILTER_DIRECTIVE, requirement.getFilter()
+				.replaceAll("\\(mandatory\\:\\<\\*[^\\)]*\\)", "")
+				.replaceAll(requirement.getName() + '=', getNamespace() + '='));
 		return result;
 	}
 

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/FelixResourceAdapter.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/FelixResourceAdapter.java?rev=1171761&r1=1171760&r2=1171761&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/FelixResourceAdapter.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/FelixResourceAdapter.java
Fri Sep 16 20:20:16 2011
@@ -23,8 +23,19 @@ import org.osgi.framework.resource.Capab
 import org.osgi.framework.resource.Requirement;
 import org.osgi.framework.resource.Resource;
 import org.osgi.framework.resource.ResourceConstants;
+import org.osgi.framework.wiring.BundleRevision;
 
 public class FelixResourceAdapter implements Resource {
+	private static String toFelixNamespace(String namespace) {
+		if (BundleRevision.BUNDLE_NAMESPACE.equals(namespace))
+			return org.apache.felix.bundlerepository.Capability.BUNDLE;
+		if (BundleRevision.HOST_NAMESPACE.equals(namespace))
+			return org.apache.felix.bundlerepository.Capability.FRAGMENT;
+		if (BundleRevision.PACKAGE_NAMESPACE.equals(namespace))
+			return org.apache.felix.bundlerepository.Capability.PACKAGE;
+		return namespace;
+	}
+	
 	private final org.apache.felix.bundlerepository.Resource resource;
 	
 	public FelixResourceAdapter(final org.apache.felix.bundlerepository.Resource resource) {
@@ -55,6 +66,7 @@ public class FelixResourceAdapter implem
 	}
 	
 	public List<Capability> getCapabilities(String namespace) {
+		namespace = toFelixNamespace(namespace);
 		org.apache.felix.bundlerepository.Capability[] capabilities = resource.getCapabilities();
 		ArrayList<Capability> result = new ArrayList<Capability>(capabilities.length);
 		if (namespace == null || namespace.equals(ResourceConstants.IDENTITY_NAMESPACE)) {
@@ -81,6 +93,7 @@ public class FelixResourceAdapter implem
 	}
 
 	public List<Requirement> getRequirements(String namespace) {
+		namespace = toFelixNamespace(namespace);
 		org.apache.felix.bundlerepository.Requirement[] requirements = resource.getRequirements();
 		ArrayList<Requirement> result = new ArrayList<Requirement>(requirements.length);
 		for (final org.apache.felix.bundlerepository.Requirement requirement : requirements) {

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/OsgiCapabilityAdapter.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/OsgiCapabilityAdapter.java?rev=1171761&r1=1171760&r2=1171761&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/OsgiCapabilityAdapter.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/OsgiCapabilityAdapter.java
Fri Sep 16 20:20:16 2011
@@ -15,6 +15,7 @@ package org.apache.aries.subsystem.core.
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.felix.bundlerepository.Capability;
@@ -44,13 +45,20 @@ public class OsgiCapabilityAdapter imple
 	public Property[] getProperties() {
 		Map<String, Object> attributes = capability.getAttributes();
 		Collection<Property> result = new ArrayList<Property>(attributes.size());
-		for (final Map.Entry<String, Object> entry : capability.getAttributes().entrySet())
+		for (final Map.Entry<String, Object> entry : capability.getAttributes().entrySet())
{
+			if (entry.getKey().equals(capability.getNamespace())) {
+				result.add(new FelixProperty(getName(), entry.getValue()));
+				continue;
+			}
 			result.add(new FelixProperty(entry));
+		}
 		return result.toArray(new Property[result.size()]);
 	}
 
 	@SuppressWarnings("rawtypes")
 	public Map getPropertiesAsMap() {
-		return capability.getAttributes();
+		Map<String, Object> result = new HashMap<String, Object>(capability.getAttributes());
+		result.put(getName(), result.get(capability.getNamespace()));
+		return result;
 	}
 }

Modified: aries/trunk/subsystem/subsystem-itests/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/pom.xml?rev=1171761&r1=1171760&r2=1171761&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/pom.xml (original)
+++ aries/trunk/subsystem/subsystem-itests/pom.xml Fri Sep 16 20:20:16 2011
@@ -41,6 +41,11 @@
         </dependency>
         <dependency>
             <groupId>org.eclipse.equinox</groupId>
+            <artifactId>org.eclipse.equinox.resolver</artifactId>
+            <version>1.0.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.equinox</groupId>
             <artifactId>org.eclipse.equinox.event</artifactId>
             <version>1.2.100</version>
         </dependency>

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=1171761&r1=1171760&r2=1171761&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
Fri Sep 16 20:20:16 2011
@@ -125,6 +125,7 @@ public abstract class SubsystemTest exte
 				// Bundles
 				mavenBundle("org.eclipse.osgi", "services").version("3.3.0-v20110523"),
 				mavenBundle("org.eclipse.equinox", "region").version("1.0.0.v20110518"),
+				mavenBundle("org.eclipse.equinox", "org.eclipse.equinox.resolver").version("1.0.0-SNAPSHOT"),
 				mavenBundle("org.apache.aries.testsupport", "org.apache.aries.testsupport.unit"),
 				mavenBundle("org.apache.aries.application", "org.apache.aries.application.api"),
 				mavenBundle("org.apache.aries", "org.apache.aries.util"),



Mime
View raw message