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 2012/02/16 22:06:22 UTC

svn commit: r1245176 - in /aries/trunk/subsystem: subsystem-api/src/main/java/org/osgi/service/repository/ subsystem-api/src/main/java/org/osgi/service/resolver/ subsystem-core/src/main/java/org/apache/aries/subsystem/core/ subsystem-core/src/main/java...

Author: jwross
Date: Thu Feb 16 21:06:21 2012
New Revision: 1245176

URL: http://svn.apache.org/viewvc?rev=1245176&view=rev
Log:
ARIES-825: Update subsystems to latest Subsystem, Resolver, and Repository APIs.

(1) Updated subsystem-api with latest resolver and repository API.
(2) Fixed compile errors in subsystem-core from latest repository API.

Added:
    aries/trunk/subsystem/subsystem-api/src/main/java/org/osgi/service/resolver/HostedCapability.java
Removed:
    aries/trunk/subsystem/subsystem-api/src/main/java/org/osgi/service/resolver/Synthesized.java
Modified:
    aries/trunk/subsystem/subsystem-api/src/main/java/org/osgi/service/repository/Repository.java
    aries/trunk/subsystem/subsystem-api/src/main/java/org/osgi/service/resolver/Environment.java
    aries/trunk/subsystem/subsystem-api/src/main/java/org/osgi/service/resolver/Resolver.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/ResourceHelper.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemArchive.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/FelixRepositoryAdapter.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/RepositoryAdminRepository.java

Modified: aries/trunk/subsystem/subsystem-api/src/main/java/org/osgi/service/repository/Repository.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-api/src/main/java/org/osgi/service/repository/Repository.java?rev=1245176&r1=1245175&r2=1245176&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-api/src/main/java/org/osgi/service/repository/Repository.java (original)
+++ aries/trunk/subsystem/subsystem-api/src/main/java/org/osgi/service/repository/Repository.java Thu Feb 16 21:06:21 2012
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) OSGi Alliance (2006, 2011). All Rights Reserved.
+ * Copyright (c) OSGi Alliance (2006, 2012). All Rights Reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -40,7 +40,7 @@ import org.osgi.service.resolver.Environ
  * properties.
  * 
  * @ThreadSafe
- * @version $Id: 95cb10e57c1262d6aae8e3bb5e9d3fa4f8d1cd64 $
+ * @version $Id: eb3d63491b6a021133bbec533295ad07ca88a348 $
  */
 public interface Repository {
   /**
@@ -59,20 +59,6 @@ public interface Repository {
   final String DISPLAY_NAME = "repository.displayName";
 
   /**
-   * Find any capabilities that match the supplied requirement.
-   * 
-   * <p>
-   * See {@link Environment#findProviders} for a discussion on matching.
-   * 
-   * @param requirement The requirement that should be matched
-   * 
-   * @return A collection of capabilities that match the supplied requirement
-   *  
-   * @throws NullPointerException if the requirement is null
-   */
-  Collection<Capability> findProviders(Requirement requirement);
-
-  /**
    * Find any capabilities that match the supplied requirements.
    * 
    * <p>

Modified: aries/trunk/subsystem/subsystem-api/src/main/java/org/osgi/service/resolver/Environment.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-api/src/main/java/org/osgi/service/resolver/Environment.java?rev=1245176&r1=1245175&r2=1245176&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-api/src/main/java/org/osgi/service/resolver/Environment.java (original)
+++ aries/trunk/subsystem/subsystem-api/src/main/java/org/osgi/service/resolver/Environment.java Thu Feb 16 21:06:21 2012
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) OSGi Alliance (2011). All Rights Reserved.
+ * Copyright (c) OSGi Alliance (2011, 2012). All Rights Reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -17,36 +17,34 @@
 package org.osgi.service.resolver;
 
 import java.util.Collection;
+import java.util.List;
 import java.util.Map;
-import java.util.SortedSet;
 
-import org.osgi.framework.Constants;
 import org.osgi.framework.resource.Capability;
 import org.osgi.framework.resource.Requirement;
 import org.osgi.framework.resource.Resource;
-import org.osgi.framework.resource.ResourceConstants;
 import org.osgi.framework.resource.Wire;
 import org.osgi.framework.resource.Wiring;
 
 /**
  * An environment provides options and constraints to the potential solution of
  * a {@link Resolver#resolve(Environment, Collection, Collection)} operation.
- *
+ * 
  * <p>
  * Environments:
  * <ul>
  * <li>Provide {@link Capability capabilities} that the Resolver can use to
  * satisfy {@link Requirement requirements} via the
  * {@link #findProviders(Requirement)} method</li>
- *
+ * 
  * <li>Constrain solutions via the {@link #getWirings()} method. A wiring
  * consists of a map of existing {@link Resource resources} to {@link Wire
  * wires}.
- *
+ * 
  * <li>Filter transitive requirements that are brought in as part of a resolve
  * operation via the {@link #isEffective(Requirement)}.
  * </ul>
- *
+ * 
  * <p>
  * An environment may be used to provide capabilities via local {@link Resource
  * resources} and/or remote {@link org.osgi.service.repository.Repository
@@ -63,80 +61,75 @@ import org.osgi.framework.resource.Wirin
  */
 public interface Environment {
 	/**
-	 * Find any capabilities that match the supplied requirement.
-	 *
+	 * Find Capabilities that match the given Requirement.
 	 * <p>
-	 * A resolver should use the iteration order or the returned capability
-	 * collection to infer preference in the case where multiple capabilities
-	 * match a requirement. Capabilities at the start of the iteration are
-	 * implied to be preferred over capabilities at the end.
-	 * 
-	 * <p>
-	 * The set returned by this call should be mutable to support ordering
-	 * of {@link Synthesized} resources created by the resolution process.
-	 *
-	 * <h3>Matching</h3>
-	 * <p>
-	 * A capability matches a requirement when all of the following are true:
-	 * <ul>
-	 * <li>The specified capability has the same {@link Capability#getNamespace() name
-	 * space} as the requirement.
-	 * <li>The filter specified by the {@link Constants#FILTER_DIRECTIVE filter}
-	 * directive of the requirement matches the
-	 * {@link Capability#getAttributes() attributes of the specified capability}.
-	 * <li>The standard capability {@link Capability#getDirectives() directives}
-	 * that influence matching and that apply to the name space are satisfied.
-	 * See the capability
-	 * {@link ResourceConstants#CAPABILITY_MANDATORY_DIRECTIVE mandatory}
-	 * directive.
-	 * </ul>
-	 *
+	 * The returned list contains {@link HostedCapability} objects where the
+	 * Resource must be the declared Resource of the Capability. The Resolver
+	 * can then add additional {@link HostedCapability} objects with the
+	 * {@link #add(Resource, Capability, List)} method when it, for example,
+	 * attaches fragments. Those {@link HostedCapability} objects will then use
+	 * the host's Resource which likely differs from the declared Resource of
+	 * the corresponding Capability.
+	 * <p>
+	 * The returned list is in priority order, the Capabilities with a lower
+	 * index have a preference over later {@link HostedCapability} objects.
+	 * <p>
+	 * The collection returned is unmodifiable but additional elements can be
+	 * added through the {@link #add(Resource, Capability, List)} method. In
+	 * general, this is necessary when the Resolver uses Capabilities declared
+	 * in a Resource but that must originate from an attached host.
+	 * <p>
+	 * Each returned Capability must match the given Requirement. This implies
+	 * that the filter in the Requirement must match as well as any namespace
+	 * specific directives. For example mandatory attributes for the
+	 * {@code osgi.wiring.package} namespace.
+	 * 
 	 * @param requirement the requirement that a resolver is attempting to
 	 *        satisfy
-	 *
-	 * @return an collection of capabilities that match the supplied requirement
-	 *
+	 * 
+	 * @return a List of {@link HostedCapability} objects that match the
+	 *         requirement
+	 * 
 	 * @throws NullPointerException if the requirement is null
 	 */
-	SortedSet<Capability> findProviders(Requirement requirement);
+	List<HostedCapability> findProviders(Requirement requirement);
 
 	/**
-	 * Find any capabilities that match the supplied requirement.
-	 * 
+	 * Add a Resource/Capability tuple to the list of capabilities returned from
+	 * {@link #findProviders(Requirement)}.
 	 * <p>
-	 * The set returned by this call should be mutable to support ordering of
-	 * {@link Synthesized} resources created by the resolution process.
+	 * Used by the Resolver to add additional Capabilities, with a potentially
+	 * different Resource as its source, to the set of Capabilities. This
+	 * function is necessary to allow fragments to attach to hosts, thereby
+	 * changing the origin of a Capability.
+	 * <p>
+	 * The given Capability must
+	 * 
+	 * @param resource The Resource that hosts this capability
+	 * @param capability The Capability to be hosted
+	 * @param capabilities The list returned from
+	 *        {@link #findProviders(Requirement)}
+	 * @return The newly created HostedCapability
 	 * 
-	 * <p>
-	 * See {@link #findProviders} for a discussion on matching.
-	 * 
-	 * @param requirements the requirements that should be matched
-	 * 
-	 * @return A map of requirements to capabilities that match the supplied
-	 *         requirements
-	 * 
-	 * @throws NullPointerException if requirements is null
-	 * 
-	 * 
-	 * @see #findProviders
 	 */
-	Map<Requirement, SortedSet<Capability>> findProviders(Collection<? extends Requirement> requirements);
+	HostedCapability insertHostedCapability(Resource resource, Capability capability,
+			List<HostedCapability> capabilities);
 
 	/**
 	 * Test if a given requirement should be wired in a given resolve operation.
 	 * If this method returns false then the resolver should ignore this
 	 * requirement during this resolve operation.
-	 *
+	 * 
 	 * <p>
 	 * The primary use case for this is to test the <code>effective</code>
 	 * directive on the requirement, though implementations are free to use this
 	 * for any other purposes.
-	 *
+	 * 
 	 * @param requirement the Requirement to test
-	 *
+	 * 
 	 * @return true if the requirement should be considered as part of this
 	 *         resolve operation
-	 *
+	 * 
 	 * @throws NullPointerException if requirement is null
 	 */
 	boolean isEffective(Requirement requirement);
@@ -144,7 +137,7 @@ public interface Environment {
 	/**
 	 * An immutable map of wirings for resources. Multiple calls to this method
 	 * for the same environment object must result in the same set of wirings.
-	 *
+	 * 
 	 * @return the wirings already defined in this environment
 	 */
 	Map<Resource, Wiring> getWirings();

Added: aries/trunk/subsystem/subsystem-api/src/main/java/org/osgi/service/resolver/HostedCapability.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-api/src/main/java/org/osgi/service/resolver/HostedCapability.java?rev=1245176&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-api/src/main/java/org/osgi/service/resolver/HostedCapability.java (added)
+++ aries/trunk/subsystem/subsystem-api/src/main/java/org/osgi/service/resolver/HostedCapability.java Thu Feb 16 21:06:21 2012
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) OSGi Alliance (2012). All Rights Reserved.
+ * 
+ * Licensed 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.osgi.service.resolver;
+
+import org.osgi.framework.resource.*;
+
+/**
+ * A HostedCapability is a tuple of a Resource with a Capability to model the
+ * cases where the declared Resource of a Capability does not match the runtime
+ * state. This is the case for fragments, when a fragment attaches a host, most
+ * of its Capabilities and Requirements become hosted by the attached host.
+ * Since a fragment can attach multiple hosts, a single Capability can actually
+ * be hosted multiple times.
+ * 
+ * @Threadsafe
+ * @version $Id: 8b77d074366fb7dcd8cd209d767be652b1db0cfd $
+ */
+public interface HostedCapability {
+
+	/**
+	 * Return the Resource of this HostedCapability.
+	 * 
+	 * @return the Resource
+	 */
+	Resource getResource();
+
+	/**
+	 * Return the Capability of this HostedCapability.
+	 * 
+	 * @return the Capability
+	 */
+	Capability getCapability();
+}

Modified: aries/trunk/subsystem/subsystem-api/src/main/java/org/osgi/service/resolver/Resolver.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-api/src/main/java/org/osgi/service/resolver/Resolver.java?rev=1245176&r1=1245175&r2=1245176&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-api/src/main/java/org/osgi/service/resolver/Resolver.java (original)
+++ aries/trunk/subsystem/subsystem-api/src/main/java/org/osgi/service/resolver/Resolver.java Thu Feb 16 21:06:21 2012
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) OSGi Alliance (2006, 2011). All Rights Reserved.
+ * Copyright (c) OSGi Alliance (2006, 2012). All Rights Reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@ import org.osgi.framework.resource.Wire;
  * specified {@link Resource resources} based on a supplied {@link Environment}.
  *
  * @ThreadSafe
- * @version $Id: 5491eb77894ab6827ad9e922a25fc475e79265ec $
+ * @version $Id: 2207d63318bcc17df98cab5e649e4e74245b01e4 $
  */
 public interface Resolver {
 	/**
@@ -95,6 +95,8 @@ public interface Resolver {
 	 *        impossible or null if no resources are optional.
 	 *
 	 * @return the new resources and wires required to satisfy the requirements
+	 * 
+	 * TODO I assume the list is mutable?
 	 *
 	 * @throws ResolutionException if the resolution cannot be satisfied for any
 	 *         reason

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/ResourceHelper.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/ResourceHelper.java?rev=1245176&r1=1245175&r2=1245176&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/ResourceHelper.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/ResourceHelper.java Thu Feb 16 21:06:21 2012
@@ -16,8 +16,10 @@ package org.apache.aries.subsystem.core;
 import static org.apache.aries.application.utils.AppConstants.LOG_ENTRY;
 import static org.apache.aries.application.utils.AppConstants.LOG_EXIT;
 
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.aries.subsystem.core.archive.TypeAttribute;
 import org.osgi.framework.Constants;
@@ -65,7 +67,8 @@ public class ResourceHelper {
 	}
 	
 	public static Resource getResource(Requirement requirement, Repository repository) {
-		Collection<Capability> capabilities = repository.findProviders(requirement);
+		Map<Requirement, Collection<Capability>> map = repository.findProviders(Arrays.asList(requirement));
+		Collection<Capability> capabilities = map.get(requirement);
 		return capabilities == null ? null : capabilities.size() == 0 ? null : capabilities.iterator().next().getResource();
 	}
 	

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemArchive.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemArchive.java?rev=1245176&r1=1245175&r2=1245176&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemArchive.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemArchive.java Thu Feb 16 21:06:21 2012
@@ -55,7 +55,6 @@ public class SubsystemArchive implements
 		logger.debug(LOG_EXIT, "init");
 	}
 	
-	@Override
 	public synchronized Collection<Capability> findProviders(Requirement requirement) {
 		logger.debug(LOG_ENTRY, "findProviders", requirement);
 		Collection<Capability> capabilities = new ArrayList<Capability>(1);

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=1245176&r1=1245175&r2=1245176&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 Thu Feb 16 21:06:21 2012
@@ -18,6 +18,7 @@ import static org.apache.aries.applicati
 
 import java.io.IOException;
 import java.net.URISyntaxException;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Comparator;
 import java.util.HashMap;
@@ -241,13 +242,17 @@ public class SubsystemEnvironment implem
 		Collection<Repository> repositories = Activator.getInstance().getServiceProvider().getServices(Repository.class);
 		for (Repository repository : repositories) {
 			logger.debug("Evaluating repository: {}", repository);
-			for (Capability capability : repository.findProviders(requirement)) {
-				logger.debug("Adding capability: {}", capability);
-				capabilities.add(capability);
-				if (content) {
-					Resource resource = capability.getResource();
-					logger.debug("Adding content resource: {}", resource);
-					resources.add(resource);
+			Map<Requirement, Collection<Capability>> map = repository.findProviders(Arrays.asList(requirement));
+			Collection<Capability> caps = map.get(requirement);
+			if (caps != null) {
+				for (Capability capability : caps) {
+					logger.debug("Adding capability: {}", capability);
+					capabilities.add(capability);
+					if (content) {
+						Resource resource = capability.getResource();
+						logger.debug("Adding content resource: {}", resource);
+						resources.add(resource);
+					}
 				}
 			}
 		}

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/FelixRepositoryAdapter.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/FelixRepositoryAdapter.java?rev=1245176&r1=1245175&r2=1245176&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/FelixRepositoryAdapter.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/FelixRepositoryAdapter.java Thu Feb 16 21:06:21 2012
@@ -69,7 +69,6 @@ public class FelixRepositoryAdapter impl
 		this.repository = repository;
 	}
 	
-	@Override
 	public Collection<Capability> findProviders(Requirement requirement) {
 		logger.debug(LOG_ENTRY, "findProviders", requirement);
 		update();

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/RepositoryAdminRepository.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/RepositoryAdminRepository.java?rev=1245176&r1=1245175&r2=1245176&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/RepositoryAdminRepository.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/obr/felix/RepositoryAdminRepository.java Thu Feb 16 21:06:21 2012
@@ -17,6 +17,7 @@ import static org.apache.aries.applicati
 import static org.apache.aries.application.utils.AppConstants.LOG_EXIT;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -46,14 +47,16 @@ public class RepositoryAdminRepository i
 		this.repositoryAdmin = repositoryAdmin;
 	}
 	
-	@Override
 	public Collection<Capability> findProviders(Requirement requirement) {
 		logger.debug(LOG_ENTRY, "findProviders", requirement);
 		Collection<Capability> result = Collections.emptyList();
 		if (ResourceConstants.IDENTITY_NAMESPACE.equals(requirement.getNamespace())) {
 			result = new ArrayList<Capability>();
 			for (Repository repository : repositories) {
-				result.addAll(repository.findProviders(requirement));
+				Map<Requirement, Collection<Capability>> map = repository.findProviders(Arrays.asList(requirement));
+				Collection<Capability> capabilities = map.get(requirement);
+				if (capabilities != null)
+					result.addAll(capabilities);
 			}
 			return result;
 		}