aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwr...@apache.org
Subject svn commit: r1330543 - in /aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal: SubsystemResolveContext.java SystemRepository.java
Date Wed, 25 Apr 2012 20:34:31 GMT
Author: jwross
Date: Wed Apr 25 20:34:30 2012
New Revision: 1330543

URL: http://svn.apache.org/viewvc?rev=1330543&view=rev
Log:
ARIES-825: Factored out functionality from resolve context into new system repository.

Added:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SystemRepository.java
Modified:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResolveContext.java

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResolveContext.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResolveContext.java?rev=1330543&r1=1330542&r2=1330543&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResolveContext.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResolveContext.java
Wed Apr 25 20:34:30 2012
@@ -28,7 +28,6 @@ import java.util.Map;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
-import org.apache.aries.subsystem.core.ResourceHelper;
 import org.apache.aries.subsystem.core.archive.PreferredProviderHeader;
 import org.eclipse.equinox.region.Region;
 import org.osgi.framework.Bundle;
@@ -142,9 +141,8 @@ public class SubsystemResolveContext ext
 			// Unscoped subsystems share content resources as well as transitive
 			// dependencies. Scoped subsystems share transitive dependencies as
 			// long as they're in the same region.
-			if (subsystem.isFeature() || identity.isTransitiveDependency()) {
-				findConstituentProviders(requirement, capabilities);
-			}
+			if (subsystem.isFeature() || identity.isTransitiveDependency())
+				capabilities.addAll(new SystemRepository(subsystem).findProviders(requirement));
 			findArchiveProviders(capabilities, identity);
 			findRepositoryServiceProviders(capabilities, identity);
 		}
@@ -154,7 +152,7 @@ public class SubsystemResolveContext ext
 			findArchiveProviders(capabilities, requirement);
 			findRepositoryServiceProviders(capabilities, requirement);
 			// 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);
+			capabilities.addAll(new SystemRepository(subsystem).findProviders(requirement));
 		}
 		logger.debug(LOG_EXIT, "findProviders", capabilities);
 		return new ArrayList<Capability>(capabilities);
@@ -222,67 +220,6 @@ public class SubsystemResolveContext ext
 		return true;
 	}
 	
-	private void findConstituentProviders(Requirement requirement, Collection<Capability>
capabilities) {
-		if (logger.isDebugEnabled())
-			logger.debug(LOG_ENTRY, "findConstituentProviders", new Object[]{requirement, capabilities});
-		AriesSubsystem subsystem = this.subsystem;
-		if (requirement instanceof OsgiIdentityRequirement) {
-			// We only want to return providers from the same region as the subsystem.
-			// Find the one and only one scoped subsystem in the region, which
-			// will be either the current subsystem or one of its parents.
-			do {
-				subsystem = (AriesSubsystem)subsystem.getParents().iterator().next();
-			} while (!(subsystem.isApplication() || subsystem.isComposite()));
-			// Now search the one and only one scoped parent within the same region
-			// and all children that are also in the same region for a provider.
-			findConstituentProviders(subsystem, requirement, capabilities);
-			return;
-		}
-		logger.debug("Navigating up the parent hierarchy...");
-		while (!subsystem.getParents().isEmpty()) {
-			subsystem = (AriesSubsystem)subsystem.getParents().iterator().next();
-			logger.debug("Next parent is: {}", subsystem);
-		}
-		findConstituentProviders(subsystem, requirement, capabilities);
-		logger.debug(LOG_EXIT, "findConstituentProviders");
-	}
-	
-	private void findConstituentProviders(AriesSubsystem subsystem, Requirement requirement,
Collection<Capability> capabilities) {
-		if (logger.isDebugEnabled())
-			logger.debug(LOG_ENTRY, "findConstituentProviders", new Object[]{subsystem, requirement,
capabilities});
-		// Because constituent providers are already provisioned resources, the
-		// sharing policy check must be between the requiring subsystem and the
-		// offering subsystem, not the subsystem the resource would be
-		// provisioned to as in the other methods.
-		SharingPolicyValidator validator = new SharingPolicyValidator(subsystem.getRegion(), this.subsystem.getRegion());
-		for (Resource resource : subsystem.getConstituents()) {
-			logger.debug("Evaluating resource: {}", resource);
-			for (Capability capability : resource.getCapabilities(requirement.getNamespace())) {
-				logger.debug("Evaluating capability: {}", capability);
-				// Filter out capabilities offered by dependencies that will be
-				// or already are provisioned to an out of scope region. This
-				// filtering does not apply to osgi.identity requirements within
-				// the same region.
-				if (!(requirement instanceof OsgiIdentityRequirement) && !validator.isValid(capability))
-					continue;
-				if (ResourceHelper.matches(requirement, capability)) {
-					logger.debug("Adding capability: {}", capability);
-					capabilities.add(capability);
-				}
-			}
-		}
-		for (Subsystem child : subsystem.getChildren()) {
-			logger.debug("Evaluating child subsystem: {}", child);
-			// If the requirement is osgi.identity and the child is not in the
-			// same region as the parent, we do not want to search it.
-			if (requirement instanceof OsgiIdentityRequirement
-					&& !subsystem.getRegion().equals(((AriesSubsystem)child).getRegion()))
-				continue;
-			findConstituentProviders((AriesSubsystem)child, requirement, capabilities);
-		}
-		logger.debug(LOG_EXIT, "findConstituentProviders");
-	}
-	
 	private void findArchiveProviders(Collection<Capability> capabilities, Requirement
requirement) {
 		if (logger.isDebugEnabled())
 			logger.debug(LOG_ENTRY, "findArchiveProviders", new Object[]{capabilities, requirement});

Added: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SystemRepository.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SystemRepository.java?rev=1330543&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SystemRepository.java
(added)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SystemRepository.java
Wed Apr 25 20:34:30 2012
@@ -0,0 +1,83 @@
+package org.apache.aries.subsystem.core.internal;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+
+import org.apache.aries.subsystem.core.ResourceHelper;
+import org.osgi.resource.Capability;
+import org.osgi.resource.Requirement;
+import org.osgi.resource.Resource;
+import org.osgi.service.repository.Repository;
+import org.osgi.service.subsystem.Subsystem;
+
+public class SystemRepository implements Repository {
+	private final AriesSubsystem subsystem;
+	
+	public SystemRepository(AriesSubsystem subsystem) {
+		this.subsystem = subsystem;
+	}
+
+	@Override
+	public Map<Requirement, Collection<Capability>> findProviders(
+			Collection<? extends Requirement> requirements) {
+		Map<Requirement, Collection<Capability>> result = new HashMap<Requirement,
Collection<Capability>>();
+		for (Requirement requirement : requirements)
+			result.put(requirement, findProviders(requirement));
+		return result;
+	}
+	
+	public Collection<Capability> findProviders(Requirement requirement) {
+		Collection<Capability> result = new HashSet<Capability>();
+		findProviders(requirement, result);
+		return result;
+	}
+	
+	private void findProviders(Requirement requirement, Collection<Capability> capabilities)
{
+		AriesSubsystem subsystem = this.subsystem;
+		if (requirement instanceof OsgiIdentityRequirement) {
+			// We only want to return providers from the same region as the subsystem.
+			// Find the one and only one scoped subsystem in the region, which
+			// will be either the current subsystem or one of its parents.
+			do {
+				subsystem = (AriesSubsystem)subsystem.getParents().iterator().next();
+			} while (!(subsystem.isApplication() || subsystem.isComposite()));
+			// Now search the one and only one scoped parent within the same region
+			// and all children that are also in the same region for a provider.
+			findProviders(subsystem, requirement, capabilities);
+			return;
+		}
+		while (!subsystem.getParents().isEmpty())
+			subsystem = (AriesSubsystem)subsystem.getParents().iterator().next();
+		findProviders(subsystem, requirement, capabilities);
+	}
+	
+	private void findProviders(AriesSubsystem subsystem, Requirement requirement, Collection<Capability>
capabilities) {
+		// Because constituent providers are already provisioned resources, the
+		// sharing policy check must be between the requiring subsystem and the
+		// offering subsystem, not the subsystem the resource would be
+		// provisioned to as in the other methods.
+		SharingPolicyValidator validator = new SharingPolicyValidator(subsystem.getRegion(), this.subsystem.getRegion());
+		for (Resource resource : subsystem.getConstituents()) {
+			for (Capability capability : resource.getCapabilities(requirement.getNamespace())) {
+				// Filter out capabilities offered by dependencies that will be
+				// or already are provisioned to an out of scope region. This
+				// filtering does not apply to osgi.identity requirements within
+				// the same region.
+				if (!(requirement instanceof OsgiIdentityRequirement) && !validator.isValid(capability))
+					continue;
+				if (ResourceHelper.matches(requirement, capability))
+					capabilities.add(capability);
+			}
+		}
+		for (Subsystem child : subsystem.getChildren()) {
+			// If the requirement is osgi.identity and the child is not in the
+			// same region as the parent, we do not want to search it.
+			if (requirement instanceof OsgiIdentityRequirement
+					&& !subsystem.getRegion().equals(((AriesSubsystem)child).getRegion()))
+				continue;
+			findProviders((AriesSubsystem)child, requirement, capabilities);
+		}
+	}
+}



Mime
View raw message