Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolver.java10
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleWiring.java4
-rwxr-xr-xbundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/FelixResolveContext.java39
-rwxr-xr-xbundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/ResolverImpl.java55
-rw-r--r--bundles/org.eclipse.osgi/osgi/src/org/osgi/service/resolver/ResolveContext.java89
-rw-r--r--bundles/org.eclipse.osgi/osgi/src/org/osgi/service/resolver/Resolver.java2
-rw-r--r--bundles/org.eclipse.osgi/osgi/src/org/osgi/service/resolver/package-info.java2
7 files changed, 97 insertions, 104 deletions
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolver.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolver.java
index 9d0b7872f..6861703da 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolver.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolver.java
@@ -472,7 +472,7 @@ final class ModuleResolver {
return version instanceof Version ? (Version) version : Version.emptyVersion;
}
- class ResolveProcess extends ResolveContext implements Comparator<Capability>, FelixResolveContext, Executor {
+ class ResolveProcess extends ResolveContext implements Comparator<Capability>, Executor {
class ResolveLogger extends Logger {
private Map<Resource, ResolutionException> errors = null;
@@ -1033,8 +1033,8 @@ final class ModuleResolver {
}
} catch (ResolutionException resolutionException) {
if (resolutionException.getCause() instanceof CancellationException) {
- // revert back to single bundle resolves
- resolveRevisionsIndividually(isMandatory, logger, result, toResolve, revisions);
+ // revert back to single bundle resolves
+ resolveRevisionsIndividually(isMandatory, logger, result, toResolve, revisions);
} else {
throw resolutionException;
}
@@ -1091,7 +1091,7 @@ final class ModuleResolver {
}
} catch (ResolutionException resolutionException) {
if (resolutionException.getCause() instanceof CancellationException) {
- applyTransitiveFailures = false;
+ applyTransitiveFailures = false;
}
throw resolutionException;
} catch (OutOfMemoryError memoryError) {
@@ -1607,7 +1607,7 @@ final class ModuleResolver {
}
@Override
- public Collection<Wire> getSubstitutionWires(Wiring wiring) {
+ public List<Wire> getSubstitutionWires(Wiring wiring) {
return ((ModuleWiring) wiring).getSubstitutionWires();
}
}
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleWiring.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleWiring.java
index ce85e5074..2aa1442e9 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleWiring.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleWiring.java
@@ -459,12 +459,12 @@ public final class ModuleWiring implements BundleWiring {
return revision.toString();
}
- Collection<Wire> getSubstitutionWires() {
+ List<Wire> getSubstitutionWires() {
if (substitutedPkgNames.isEmpty()) {
return Collections.emptyList();
}
// Could cache this, but seems unnecessary since it will only be used by the resolver
- Collection<Wire> substitutionWires = new ArrayList<>(substitutedPkgNames.size());
+ List<Wire> substitutionWires = new ArrayList<>(substitutedPkgNames.size());
List<ModuleWire> current = requiredWires;
for (ModuleWire wire : current) {
Capability cap = wire.getCapability();
diff --git a/bundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/FelixResolveContext.java b/bundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/FelixResolveContext.java
deleted file mode 100755
index ddfb49bcf..000000000
--- a/bundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/FelixResolveContext.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.felix.resolver;
-
-import java.util.Collection;
-import org.osgi.framework.namespace.PackageNamespace;
-import org.osgi.resource.*;
-
-public interface FelixResolveContext {
- /**
- * Returns the subset of {@link Wiring#getRequiredResourceWires(String) require wires}
- * that provide wires to {@link Capability capabilities} which substitute capabilities
- * of the given 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 hosted by a different wiring then the package capability is
- * considered to be substituted.
- *
- * @param wiring the wiring to get the substitution wires from
- * @return A collection containing a snapshot of the substitution {@link Wire}s
- * for the {@link Requirement requirements} of this wiring, or an empty list
- * if this wiring has no substitution wires.
- */
- public Collection<Wire> getSubstitutionWires(Wiring wiring);
-}
diff --git a/bundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/ResolverImpl.java b/bundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/ResolverImpl.java
index 09f9ec56a..146a9c563 100755
--- a/bundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/ResolverImpl.java
+++ b/bundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/ResolverImpl.java
@@ -1646,17 +1646,7 @@ public class ResolverImpl implements Resolver
// map to determine which exports are substitutable.
if (wiring != null)
{
- Collection<Wire> substitutionWires;
- if (session.getContext() instanceof FelixResolveContext)
- {
- substitutionWires = ((FelixResolveContext) session.getContext()).getSubstitutionWires(
- wiring);
- }
- else
- {
- substitutionWires = getSubstitutionWires(wiring);
- }
- for (Wire wire : substitutionWires)
+ for (Wire wire : session.getContext().getSubstitutionWires(wiring))
{
Capability cap = wire.getCapability();
if (!cap.getResource().equals(wire.getProvider()))
@@ -1697,49 +1687,6 @@ public class ResolverImpl implements Resolver
return exports;
}
- private static Collection<Wire> getSubstitutionWires(Wiring wiring)
- {
- Set<String> exportNames = new HashSet<String>();
- for (Capability cap : wiring.getResource().getCapabilities(null))
- {
- if (PackageNamespace.PACKAGE_NAMESPACE.equals(cap.getNamespace()))
- {
- exportNames.add(
- (String) cap.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
- }
- }
- // Add fragment exports
- for (Wire wire : wiring.getProvidedResourceWires(null))
- {
- if (HostNamespace.HOST_NAMESPACE.equals(wire.getCapability().getNamespace()))
- {
- for (Capability cap : wire.getRequirement().getResource().getCapabilities(
- null))
- {
- if (PackageNamespace.PACKAGE_NAMESPACE.equals(cap.getNamespace()))
- {
- exportNames.add((String) cap.getAttributes().get(
- PackageNamespace.PACKAGE_NAMESPACE));
- }
- }
- }
- }
- Collection<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;
- }
-
private static boolean isCompatible(
Blame currentBlame, Capability candCap,
Map<Resource, Packages> resourcePkgMap)
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.

Back to the top