diff options
author | Thomas Watson | 2017-02-16 19:43:36 +0000 |
---|---|---|
committer | Thomas Watson | 2017-06-16 12:38:08 +0000 |
commit | 9616ef3b024f613d07ca7936751061f6cd473a9e (patch) | |
tree | 7703691c953b81817609b427ffd418ca2c671f81 /bundles/org.eclipse.osgi/osgi | |
parent | 6b01d11c037e98842a9c3b18a6a8866813d63dab (diff) | |
download | rt.equinox.framework-9616ef3b024f613d07ca7936751061f6cd473a9e.tar.gz rt.equinox.framework-9616ef3b024f613d07ca7936751061f6cd473a9e.tar.xz rt.equinox.framework-9616ef3b024f613d07ca7936751061f6cd473a9e.zip |
resolver: add ResolveContext getSubstitutionWires method
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
Change-Id: I44f6400ec2b37603299bed60750383177f968ada
Diffstat (limited to 'bundles/org.eclipse.osgi/osgi')
3 files changed, 89 insertions, 4 deletions
diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/resolver/ResolveContext.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/resolver/ResolveContext.java index 4cf3f3568..887cb785c 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/resolver/ResolveContext.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/resolver/ResolveContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) OSGi Alliance (2011, 2013). All Rights Reserved. + * Copyright (c) OSGi Alliance (2011, 2016). 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. @@ -16,16 +16,23 @@ package org.osgi.service.resolver; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.CancellationException; import org.osgi.annotation.versioning.ConsumerType; +import org.osgi.framework.namespace.BundleNamespace; +import org.osgi.framework.namespace.HostNamespace; +import org.osgi.framework.namespace.PackageNamespace; import org.osgi.resource.Capability; import org.osgi.resource.Requirement; import org.osgi.resource.Resource; +import org.osgi.resource.Wire; import org.osgi.resource.Wiring; /** @@ -237,11 +244,89 @@ public abstract class ResolveContext { * of resources which may allow the resolve operation to complete normally. * * @param callback the callback to execute in order to cancel the resolve - * operation + * operation. Must not be {@code null}. * @throws IllegalStateException if the resolver attempts to register more * than one callback for a resolve operation + * @since 1.1 */ public void onCancel(Runnable callback) { // do nothing by default } + + /** + * Returns the subset of {@link Wiring#getRequiredResourceWires(String) + * required} wires that provide wires to {@link Capability capabilities} + * which substitute capabilities of the wiring. For example, when a + * {@link PackageNamespace package} name is both provided and required by + * the same resource. If the package requirement is resolved to a capability + * provided by a different wiring then the package capability is considered + * to be substituted. + * <p> + * The resolver asks the resolve context to return substitution wires for + * each wiring that {@link Wiring#getResourceCapabilities(String) provides} + * a {@link BundleNamespace bundle} namespace capability that is used to + * resolve one or more bundle requirements. + * <p> + * Note that this method searches all the {@link PackageNamespace package} + * capabilities declared as {@link Resource#getCapabilities(String) + * provided} by the resource associated with the wiring and fragment + * resources wired to the wiring with the {@link HostNamespace host} + * namespace. The provided package names are compared against the + * {@link Wiring#getRequiredResourceWires(String) required} package wires to + * determine which wires are substitution wires. Subclasses of + * <code>ResolveContext</code> should provide a more efficient + * implementation of this method. + * + * @param wiring the wiring to get the substitution wires for. Must not be + * {@code null}. + * @return A list containing a snapshot of the substitution {@link Wire}s + * for the {@link Requirement requirements} of the wiring, or an + * empty list if the wiring has no substitution wires. The list + * contains the wires in the order they are found in the + * {@link Wiring#getRequiredResourceWires(String) required} wires of + * the wiring. + * @since 1.1 + */ + public List<Wire> getSubstitutionWires(Wiring wiring) { + // Keep track of the declared capability package names + Set<String> exportNames = new HashSet<String>(); + + // Add packages declared as provided by the wiring host + for (Capability cap : wiring.getResource().getCapabilities(null)) { + if (PackageNamespace.PACKAGE_NAMESPACE.equals(cap.getNamespace())) { + exportNames.add((String) cap.getAttributes() + .get(PackageNamespace.PACKAGE_NAMESPACE)); + } + } + + // Add packages declared as provided by the attached fragments + for (Wire wire : wiring.getProvidedResourceWires(null)) { + if (HostNamespace.HOST_NAMESPACE + .equals(wire.getCapability().getNamespace())) { + Resource fragment = wire.getRequirement().getResource(); + for (Capability cap : fragment.getCapabilities(null)) { + if (PackageNamespace.PACKAGE_NAMESPACE + .equals(cap.getNamespace())) { + exportNames.add((String) cap.getAttributes() + .get(PackageNamespace.PACKAGE_NAMESPACE)); + } + } + } + } + + // collect the package wires that substitute one of the declared + // export package names + List<Wire> substitutionWires = new ArrayList<Wire>(); + for (Wire wire : wiring.getRequiredResourceWires(null)) { + if (PackageNamespace.PACKAGE_NAMESPACE + .equals(wire.getCapability().getNamespace())) { + if (exportNames + .contains(wire.getCapability().getAttributes().get( + PackageNamespace.PACKAGE_NAMESPACE))) { + substitutionWires.add(wire); + } + } + } + return substitutionWires; + } } diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/resolver/Resolver.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/resolver/Resolver.java index 7fb3ca12a..555f3cd15 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/resolver/Resolver.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/resolver/Resolver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) OSGi Alliance (2006, 2013). All Rights Reserved. + * Copyright (c) OSGi Alliance (2006, 2016). 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. diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/resolver/package-info.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/resolver/package-info.java index 544d95611..6ac829e72 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/resolver/package-info.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/resolver/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) OSGi Alliance (2010, 2013). All Rights Reserved. + * Copyright (c) OSGi Alliance (2010, 2016). 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. |