aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwr...@apache.org
Subject svn commit: r1701286 - /aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/PreferredProviderRepository.java
Date Fri, 04 Sep 2015 16:07:15 GMT
Author: jwross
Date: Fri Sep  4 16:07:14 2015
New Revision: 1701286

URL: http://svn.apache.org/r1701286
Log:
ARIES-1397 Use capability set with preferred provider repository.

Modified:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/PreferredProviderRepository.java

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/PreferredProviderRepository.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/PreferredProviderRepository.java?rev=1701286&r1=1701285&r2=1701286&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/PreferredProviderRepository.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/PreferredProviderRepository.java
Fri Sep  4 16:07:14 2015
@@ -13,98 +13,61 @@
  */
 package org.apache.aries.subsystem.core.internal;
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Map;
 
 import org.apache.aries.subsystem.core.archive.PreferredProviderHeader;
 import org.apache.aries.subsystem.core.archive.PreferredProviderRequirement;
+import org.apache.aries.subsystem.core.capabilityset.CapabilitySetRepository;
+import org.apache.aries.subsystem.core.repository.Repository;
 import org.osgi.resource.Capability;
 import org.osgi.resource.Requirement;
-import org.osgi.resource.Resource;
 
 public class PreferredProviderRepository implements org.apache.aries.subsystem.core.repository.Repository
{
-	// @GuardedBy("this")
-	private boolean initialized;
-	
-	private final org.apache.aries.subsystem.core.repository.Repository repositoryServiceRepository
= new RepositoryServiceRepository();
+    private final CapabilitySetRepository repository;
 	private final SubsystemResource resource;
-	private final Collection<Resource> resources = new HashSet<Resource>();
-	private final org.apache.aries.subsystem.core.repository.Repository systemRepository = Activator.getInstance().getSystemRepository();
 	
 	public PreferredProviderRepository(SubsystemResource resource) {
 		this.resource = resource;
+		repository = new CapabilitySetRepository();
+		PreferredProviderHeader header = resource.getSubsystemManifest().getPreferredProviderHeader();
+		if (header != null) {
+		    Collection<PreferredProviderRequirement> requirements = header.toRequirements(resource);
+	        for (PreferredProviderRequirement requirement : requirements) {
+	            if (!addProviders(requirement, Activator.getInstance().getSystemRepository(),
true)) {
+	                if (!addProviders(requirement, resource.getLocalRepository(), false)) {
+	                    addProviders(requirement, new RepositoryServiceRepository(), false);
+	                }
+	            }
+	        }
+		}
 	}
 
 	@Override
-	public Map<Requirement, Collection<Capability>> findProviders(
-			Collection<? extends Requirement> requirements) {
-		synchronized (this) {
-			if (!initialized) {
-				initialize();
-				initialized = true;
-			}
-		}
-		Map<Requirement, Collection<Capability>> result = new HashMap<Requirement,
Collection<Capability>>();
-		for (Requirement requirement : requirements)
-			result.put(requirement, findProviders(requirement));
-		return result;
+	public Map<Requirement, Collection<Capability>> findProviders(Collection<?
extends Requirement> requirements) {
+		return repository.findProviders(requirements);
 	}
 	
-	private boolean addLocalRepositoryProviders(Requirement requirement) {
-		return addProviders(requirement, resource.getLocalRepository(), false);
-	}
-	
-	private boolean addProviders(Requirement requirement, org.apache.aries.subsystem.core.repository.Repository
repository, boolean checkValid) {
+	private boolean addProviders(Requirement requirement, Repository repository, boolean checkValid)
{
+	    boolean result = false;
 		Map<Requirement, Collection<Capability>> map = repository.findProviders(Collections.singleton(requirement));
 		Collection<Capability> capabilities = map.get(requirement);
-		if (capabilities == null || capabilities.isEmpty())
-			return false;
-		for (Capability capability : map.get(requirement)) {
-			if (checkValid && !isValid(capability))
-				continue;
-			resources.add(capability.getResource());
+		for (Capability capability : capabilities) {
+		    if (checkValid ? isValid(capability) : true) {
+		        this.repository.addResource(capability.getResource());
+		        result = true;
+		    }
 		}
-		return true;
-	}
-	
-	private boolean addRepositoryServiceProviders(Requirement requirement) {
-		return addProviders(requirement, repositoryServiceRepository, false);
-	}
-	
-	private boolean addSystemRepositoryProviders(Requirement requirement) {
-		return addProviders(requirement, systemRepository, true);
-	}
-	
-	private Collection<Capability> findProviders(Requirement requirement) {
-		ArrayList<Capability> result = new ArrayList<Capability>(resources.size());
-		for (Resource resource : resources)
-			for (Capability capability : resource.getCapabilities(requirement.getNamespace()))
-				if (ResourceHelper.matches(requirement, capability))
-					result.add(capability);
-		result.trimToSize();
 		return result;
 	}
 	
-	private void initialize() {
-		PreferredProviderHeader header = resource.getSubsystemManifest().getPreferredProviderHeader();
-		if (header == null)
-			return;
-		Collection<PreferredProviderRequirement> requirements = header.toRequirements(resource);
-		for (PreferredProviderRequirement requirement : requirements)
-			if (!addSystemRepositoryProviders(requirement))
-				if (!addLocalRepositoryProviders(requirement))
-					addRepositoryServiceProviders(requirement);
-	}
-	
 	private boolean isValid(Capability capability) {
-		for (BasicSubsystem parent : resource.getParents())
-			for (Resource constituent : parent.getConstituents())
-				if (ResourceHelper.areEqual(constituent, capability.getResource()))
-					return true;
+		for (BasicSubsystem parent : resource.getParents()) {
+		    if (parent.getConstituents().contains(resource)) {
+		        return true;
+		    }
+		}
 		return false;
 	}
 }



Mime
View raw message