Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2011-02-16 20:45:18 +0000
committerThomas Watson2011-02-16 20:45:18 +0000
commitd54505947697088c05bad24a79cf084ec8d18891 (patch)
tree657a7a762b719326233cbce0a503c1ce6ca718d9 /bundles/org.eclipse.osgi/resolver
parent8ce99ab0bf9af45931ce0c1ea04680570d11c3c3 (diff)
downloadrt.equinox.framework-d54505947697088c05bad24a79cf084ec8d18891.tar.gz
rt.equinox.framework-d54505947697088c05bad24a79cf084ec8d18891.tar.xz
rt.equinox.framework-d54505947697088c05bad24a79cf084ec8d18891.zip
Merge wiring branch, fixes for the following bugs:
Bug 334582 - OSGi changes to the wiring API Bug 334574 - OSGi renamed synthetic wiring capabilities to start with osgi.wiring. Bug 334591 - OSGi added AdaptPermission Bug 335673 - No FrameworkEvent generated for exceptions in a WeavingHook
Diffstat (limited to 'bundles/org.eclipse.osgi/resolver')
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverBundle.java16
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverConstraint.java10
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverImpl.java111
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/VersionHashMap.java4
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/VersionSupplier.java8
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/BaseDescriptionImpl.java89
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/BundleDescriptionImpl.java274
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/BundleSpecificationImpl.java40
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/ExportPackageDescriptionImpl.java38
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/GenericDescriptionImpl.java36
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/GenericSpecificationImpl.java27
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/HostSpecificationImpl.java29
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/ImportPackageSpecificationImpl.java31
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/NativeCodeSpecificationImpl.java17
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/ReadOnlyState.java5
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateHelperImpl.java16
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateImpl.java33
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateReader.java77
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateWriter.java58
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/VersionConstraintImpl.java69
20 files changed, 729 insertions, 259 deletions
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverBundle.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverBundle.java
index 8aff6b6f4..7eb0e0827 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverBundle.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverBundle.java
@@ -12,6 +12,8 @@ package org.eclipse.osgi.internal.module;
import java.util.*;
import java.util.Map.Entry;
+import org.eclipse.osgi.internal.resolver.ExportPackageDescriptionImpl;
+import org.eclipse.osgi.internal.resolver.GenericDescriptionImpl;
import org.eclipse.osgi.service.resolver.*;
import org.osgi.framework.Constants;
@@ -351,7 +353,6 @@ public class ResolverBundle extends VersionSupplier implements Comparable<Resolv
ArrayList<ResolverExport> hostExports = new ArrayList<ResolverExport>(newExports.length);
if (newExports.length > 0 && dynamicAttach) {
- StateObjectFactory factory = resolver.getState().getFactory();
for (int i = 0; i < newExports.length; i++) {
ResolverExport currentExports[] = getExports(newExports[i].getName());
boolean foundEquivalent = false;
@@ -360,7 +361,7 @@ public class ResolverBundle extends VersionSupplier implements Comparable<Resolv
foundEquivalent = true;
}
if (!foundEquivalent) {
- ExportPackageDescription hostExport = factory.createExportPackageDescription(newExports[i].getName(), newExports[i].getVersion(), newExports[i].getDirectives(), newExports[i].getAttributes(), true, getBundleDescription());
+ ExportPackageDescription hostExport = new ExportPackageDescriptionImpl(getBundleDescription(), newExports[i]);
hostExports.add(new ResolverExport(this, hostExport));
}
}
@@ -369,17 +370,8 @@ public class ResolverBundle extends VersionSupplier implements Comparable<Resolv
List<GenericCapability> hostCapabilities = new ArrayList<GenericCapability>(newGenericCapabilities.length);
if (newGenericCapabilities.length > 0 && dynamicAttach) {
- StateObjectFactory factory = resolver.getState().getFactory();
for (GenericDescription capability : newGenericCapabilities) {
- Dictionary<String, Object> origAttrs = capability.getAttributes();
- Map<String, Object> attrs = new HashMap<String, Object>();
- if (origAttrs != null) {
- for (Enumeration<String> keys = origAttrs.keys(); keys.hasMoreElements();) {
- String key = keys.nextElement();
- attrs.put(key, origAttrs.get(key));
- }
- }
- GenericDescription hostCapabililty = factory.createGenericDescription(capability.getType(), attrs, null, getBundleDescription());
+ GenericDescription hostCapabililty = new GenericDescriptionImpl(getBundleDescription(), capability);
hostCapabilities.add(new GenericCapability(this, hostCapabililty));
}
fragmentGenericCapabilities.put(fragment.bundleID, hostCapabilities);
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverConstraint.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverConstraint.java
index 5d6f46c3a..759898a70 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverConstraint.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverConstraint.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2010 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2005, 2011 IBM Corporation and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
@@ -10,6 +10,7 @@ package org.eclipse.osgi.internal.module;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.VersionConstraint;
+import org.osgi.framework.wiring.BundleRequirement;
/*
* A companion to VersionConstraint from the state used while resolving
@@ -17,12 +18,14 @@ import org.eclipse.osgi.service.resolver.VersionConstraint;
public abstract class ResolverConstraint {
final protected ResolverBundle bundle;
protected VersionConstraint constraint;
+ private BundleRequirement requrement;
private VersionSupplier[] possibleSuppliers;
private int selectedSupplierIndex = 0;
ResolverConstraint(ResolverBundle bundle, VersionConstraint constraint) {
this.bundle = bundle;
this.constraint = constraint;
+ this.requrement = constraint.getRequirement();
}
// returns the Resolver bundle requiring the ResolverConstraint
@@ -139,5 +142,10 @@ public abstract class ResolverConstraint {
void setVersionConstraint(VersionConstraint constraint) {
this.constraint = constraint;
+ this.requrement = constraint.getRequirement();
+ }
+
+ BundleRequirement getRequirement() {
+ return requrement;
}
}
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverImpl.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverImpl.java
index 7652a122e..d8a800f73 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverImpl.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverImpl.java
@@ -27,8 +27,8 @@ import org.eclipse.osgi.util.ManifestElement;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.hooks.resolver.ResolverHook;
+import org.osgi.framework.wiring.BundleCapability;
import org.osgi.framework.wiring.BundleRevision;
-import org.osgi.framework.wiring.Capability;
public class ResolverImpl implements Resolver {
// Debug fields
@@ -349,21 +349,21 @@ public class ResolverImpl implements Resolver {
BundleConstraint hostConstraint = bundle.getHost();
List<ResolverBundle> hosts = resolverBundles.get(hostConstraint.getVersionConstraint().getName());
List<ResolverBundle> candidates = new ArrayList<ResolverBundle>(hosts);
- List<Capability> hostCapabilities = new ArrayList<Capability>(hosts.size());
+ List<BundleCapability> hostCapabilities = new ArrayList<BundleCapability>(hosts.size());
// Must remove candidates that do not match before calling hooks.
for (Iterator<ResolverBundle> iCandidates = candidates.iterator(); iCandidates.hasNext();) {
ResolverBundle host = iCandidates.next();
if (!host.isResolvable() || !host.getBundleDescription().attachFragments() || !hostConstraint.isSatisfiedBy(host)) {
iCandidates.remove();
} else {
- List<Capability> h = host.getBundleDescription().getDeclaredCapabilities(Capability.HOST_CAPABILITY);
+ List<BundleCapability> h = host.getBundleDescription().getDeclaredCapabilities(BundleRevision.HOST_NAMESPACE);
// the bundle must have 1 host capability.
hostCapabilities.add(h.get(0));
}
}
if (hook != null)
- hook.filterMatches(bundle.getBundleDescription(), asCapabilities(new ArrayMap<Capability, ResolverBundle>(hostCapabilities, candidates)));
+ hook.filterMatches(hostConstraint.getRequirement(), asCapabilities(new ArrayMap<BundleCapability, ResolverBundle>(hostCapabilities, candidates)));
// we are left with only candidates that satisfy the host constraint
for (ResolverBundle host : candidates) {
foundMatch = true;
@@ -435,6 +435,10 @@ public class ResolverImpl implements Resolver {
usesCalculationTimeout = false;
resolveBundles(bundles, platformProperties, hookDisabled);
+ // reorder exports and bundles after resolving the bundles
+ resolverExports.reorder();
+ resolverBundles.reorder();
+ reorderGenerics();
if (resolveOptional)
resolveOptionalConstraints(currentlyResolved);
if (DEBUG)
@@ -515,7 +519,7 @@ public class ResolverImpl implements Resolver {
resolvedOptional = true;
}
if (resolvedOptional) {
- state.resolveBundle(bundle.getBundleDescription(), false, null, null, null, null, null, null, null);
+ state.resolveBundle(bundle.getBundleDescription(), false, null, null, null, null, null, null, null, null);
stateResolveConstraints(bundle);
stateResolveBundle(bundle);
}
@@ -575,7 +579,7 @@ public class ResolverImpl implements Resolver {
continue;
}
List<ResolverBundle> collisionCandidates = new ArrayList<ResolverBundle>(sameBSN.size() - 1);
- List<Capability> capabilities = new ArrayList<Capability>(sameBSN.size() - 1);
+ List<BundleCapability> capabilities = new ArrayList<BundleCapability>(sameBSN.size() - 1);
for (ResolverBundle collision : sameBSN) {
if (collision == singleton || !collision.getBundleDescription().isSingleton() || !collision.isResolvable())
continue; // Ignore the bundle we are checking and non-singletons and non-resovlable
@@ -583,7 +587,7 @@ public class ResolverImpl implements Resolver {
capabilities.add(collision.getCapability());
}
if (hook != null)
- hook.filterSingletonCollisions(singleton.getCapability(), asCapabilities(new ArrayMap<Capability, ResolverBundle>(capabilities, collisionCandidates)));
+ hook.filterSingletonCollisions(singleton.getCapability(), asCapabilities(new ArrayMap<BundleCapability, ResolverBundle>(capabilities, collisionCandidates)));
if (collisionCandidates.isEmpty()) {
if (!selected.contains(singleton))
selected.add(singleton);
@@ -669,7 +673,7 @@ public class ResolverImpl implements Resolver {
continue;
if (!bundles[i].isResolved())
continue;
- if (!helper.giveExports(getExportsWiredTo(bundles[i]))) {
+ if (!helper.giveExports(getExportsWiredTo(bundles[i], null))) {
state.addResolverError(bundles[i].getBundleDescription(), ResolverError.DISABLED_BUNDLE, null, null);
bundles[i].setResolvable(false);
// We pass false for keepFragmentsAttached because we need to redo the attachments (bug 272561)
@@ -1123,8 +1127,8 @@ public class ResolverImpl implements Resolver {
}
@SuppressWarnings("unchecked")
- static Collection<Capability> asCapabilities(Collection<? extends Capability> capabilities) {
- return (Collection<Capability>) capabilities;
+ static Collection<BundleCapability> asCapabilities(Collection<? extends BundleCapability> capabilities) {
+ return (Collection<BundleCapability>) capabilities;
}
private void resolveFragment(ResolverBundle fragment) {
@@ -1292,7 +1296,7 @@ public class ResolverImpl implements Resolver {
else
capabilities = name == null || "*".equals(name) ? namespace.getAllValues() : namespace.get(name); //$NON-NLS-1$
List<GenericCapability> candidates = new ArrayList<GenericCapability>(capabilities);
- List<Capability> genCapabilities = new ArrayList<Capability>(candidates.size());
+ List<BundleCapability> genCapabilities = new ArrayList<BundleCapability>(candidates.size());
// Must remove candidates that do not match before calling hooks.
for (Iterator<GenericCapability> iCandidates = candidates.iterator(); iCandidates.hasNext();) {
GenericCapability capability = iCandidates.next();
@@ -1303,7 +1307,7 @@ public class ResolverImpl implements Resolver {
}
}
if (hook != null)
- hook.filterMatches(constraint.getBundle().getBundleDescription(), asCapabilities(new ArrayMap<Capability, GenericCapability>(genCapabilities, candidates)));
+ hook.filterMatches(constraint.getRequirement(), asCapabilities(new ArrayMap<BundleCapability, GenericCapability>(genCapabilities, candidates)));
boolean result = false;
// We are left with only capabilities that satisfy the constraint.
for (GenericCapability capability : candidates) {
@@ -1351,7 +1355,7 @@ public class ResolverImpl implements Resolver {
}
List<ResolverBundle> bundles = resolverBundles.get(req.getVersionConstraint().getName());
List<ResolverBundle> candidates = new ArrayList<ResolverBundle>(bundles);
- List<Capability> capabilities = new ArrayList<Capability>(candidates.size());
+ List<BundleCapability> capabilities = new ArrayList<BundleCapability>(candidates.size());
// Must remove candidates that do not match before calling hooks.
for (Iterator<ResolverBundle> iCandidates = candidates.iterator(); iCandidates.hasNext();) {
ResolverBundle bundle = iCandidates.next();
@@ -1362,7 +1366,7 @@ public class ResolverImpl implements Resolver {
}
}
if (hook != null)
- hook.filterMatches(req.getBundle().getBundleDescription(), asCapabilities(new ArrayMap<Capability, ResolverBundle>(capabilities, candidates)));
+ hook.filterMatches(req.getRequirement(), asCapabilities(new ArrayMap<BundleCapability, ResolverBundle>(capabilities, candidates)));
// We are left with only capabilities that satisfy the require bundle.
boolean result = false;
for (ResolverBundle bundle : candidates) {
@@ -1418,7 +1422,7 @@ public class ResolverImpl implements Resolver {
ResolverExport[] substitutableExps = imp.getBundle().getExports(imp.getName());
List<ResolverExport> exports = resolverExports.get(imp.getName());
List<ResolverExport> candidates = new ArrayList<ResolverExport>(exports);
- List<Capability> capabilities = new ArrayList<Capability>(candidates.size());
+ List<BundleCapability> capabilities = new ArrayList<BundleCapability>(candidates.size());
// Must remove candidates that do not match before calling hooks.
for (Iterator<ResolverExport> iCandidates = candidates.iterator(); iCandidates.hasNext();) {
ResolverExport export = iCandidates.next();
@@ -1429,7 +1433,7 @@ public class ResolverImpl implements Resolver {
}
}
if (hook != null)
- hook.filterMatches(imp.getBundle().getBundleDescription(), asCapabilities(new ArrayMap<Capability, ResolverExport>(capabilities, candidates)));
+ hook.filterMatches(imp.getRequirement(), asCapabilities(new ArrayMap<BundleCapability, ResolverExport>(capabilities, candidates)));
// We are left with only capabilities that satisfy the import.
for (ResolverExport export : candidates) {
if (DEBUG_IMPORTS)
@@ -1583,6 +1587,10 @@ public class ResolverImpl implements Resolver {
stateResolveFragConstraints(rb);
else
stateResolveConstraints(rb);
+
+ // Build up the state wires
+ Map<String, List<StateWire>> stateWires = new HashMap<String, List<StateWire>>();
+
// Gather selected exports
ResolverExport[] exports = rb.getSelectedExports();
List<ExportPackageDescription> selectedExports = new ArrayList<ExportPackageDescription>(exports.length);
@@ -1601,15 +1609,22 @@ public class ResolverImpl implements Resolver {
ExportPackageDescription[] substitutedExportsArray = substitutedExports.toArray(new ExportPackageDescription[substitutedExports.size()]);
// Gather exports that have been wired to
- ExportPackageDescription[] exportsWiredToArray = getExportsWiredTo(rb);
+ ExportPackageDescription[] exportsWiredToArray = getExportsWiredTo(rb, stateWires);
// Gather bundles that have been wired to
BundleConstraint[] requires = rb.getRequires();
List<BundleDescription> bundlesWiredTo = new ArrayList<BundleDescription>(requires.length);
+ List<StateWire> requireWires = new ArrayList<StateWire>(requires.length);
for (int i = 0; i < requires.length; i++)
- if (requires[i].getSelectedSupplier() != null)
- bundlesWiredTo.add((BundleDescription) requires[i].getSelectedSupplier().getBaseDescription());
+ if (requires[i].getSelectedSupplier() != null) {
+ BundleDescription supplier = (BundleDescription) requires[i].getSelectedSupplier().getBaseDescription();
+ bundlesWiredTo.add(supplier);
+ StateWire requireWire = newStateWire(rb.getBundleDescription(), requires[i].getVersionConstraint(), supplier, supplier);
+ requireWires.add(requireWire);
+ }
BundleDescription[] bundlesWiredToArray = bundlesWiredTo.toArray(new BundleDescription[bundlesWiredTo.size()]);
+ if (!requireWires.isEmpty())
+ stateWires.put(BundleRevision.BUNDLE_NAMESPACE, requireWires);
GenericCapability[] capabilities = rb.getGenericCapabilities();
List<GenericDescription> selectedCapabilities = new ArrayList<GenericDescription>(capabilities.length);
@@ -1623,8 +1638,17 @@ public class ResolverImpl implements Resolver {
for (GenericConstraint genericConstraint : genericRequires) {
VersionSupplier[] matching = genericConstraint.getMatchingCapabilities();
if (matching != null)
- for (VersionSupplier capability : matching)
- resolvedGenericRequires.add(((GenericCapability) capability).getGenericDescription());
+ for (VersionSupplier capability : matching) {
+ GenericDescription supplier = ((GenericCapability) capability).getGenericDescription();
+ resolvedGenericRequires.add(supplier);
+ StateWire genericWire = newStateWire(rb.getBundleDescription(), genericConstraint.getVersionConstraint(), supplier.getSupplier(), supplier);
+ List<StateWire> genericWires = stateWires.get(genericConstraint.getNameSpace());
+ if (genericWires == null) {
+ genericWires = new ArrayList<StateWire>();
+ stateWires.put(genericConstraint.getNameSpace(), genericWires);
+ }
+ genericWires.add(genericWire);
+ }
}
GenericDescription[] capabilitiesWiredToArray = resolvedGenericRequires.toArray(new GenericDescription[resolvedGenericRequires.size()]);
@@ -1633,8 +1657,12 @@ public class ResolverImpl implements Resolver {
VersionSupplier[] matchingBundles = rb.getHost().getPossibleSuppliers();
if (matchingBundles != null && matchingBundles.length > 0) {
hostBundles = new BundleDescription[matchingBundles.length];
+ List<StateWire> hostWires = new ArrayList<StateWire>(matchingBundles.length);
+ stateWires.put(BundleRevision.HOST_NAMESPACE, hostWires);
for (int i = 0; i < matchingBundles.length; i++) {
hostBundles[i] = matchingBundles[i].getBundleDescription();
+ StateWire hostWire = newStateWire(rb.getBundleDescription(), rb.getHost().getVersionConstraint(), hostBundles[i], hostBundles[i]);
+ hostWires.add(hostWire);
if (hostBundles[i].isResolved()) {
ExportPackageDescription[] newSelectedExports = null;
GenericDescription[] newSelectedCapabilities = null;
@@ -1657,7 +1685,7 @@ public class ResolverImpl implements Resolver {
newSelectedCapabilities = hostBundles[i].getSelectedGenericCapabilities();
if (newSelectedExports == null)
newSelectedExports = hostBundles[i].getSelectedExports();
- state.resolveBundle(hostBundles[i], true, null, newSelectedExports, hostBundles[i].getSubstitutedExports(), newSelectedCapabilities, hostBundles[i].getResolvedRequires(), hostBundles[i].getResolvedImports(), hostBundles[i].getResolvedGenericRequires());
+ state.resolveBundle(hostBundles[i], true, null, newSelectedExports, hostBundles[i].getSubstitutedExports(), newSelectedCapabilities, hostBundles[i].getResolvedRequires(), hostBundles[i].getResolvedImports(), hostBundles[i].getResolvedGenericRequires(), ((BundleDescriptionImpl) hostBundles[i]).getWires());
}
}
}
@@ -1665,19 +1693,32 @@ public class ResolverImpl implements Resolver {
}
// Resolve the bundle in the state
- state.resolveBundle(rb.getBundleDescription(), rb.isResolved(), hostBundles, selectedExportsArray, substitutedExportsArray, selectedCapabilitiesArray, bundlesWiredToArray, exportsWiredToArray, capabilitiesWiredToArray);
+ state.resolveBundle(rb.getBundleDescription(), rb.isResolved(), hostBundles, selectedExportsArray, substitutedExportsArray, selectedCapabilitiesArray, bundlesWiredToArray, exportsWiredToArray, capabilitiesWiredToArray, stateWires);
}
- private static ExportPackageDescription[] getExportsWiredTo(ResolverBundle rb) {
+ private static ExportPackageDescription[] getExportsWiredTo(ResolverBundle rb, Map<String, List<StateWire>> stateWires) {
// Gather exports that have been wired to
ResolverImport[] imports = rb.getImportPackages();
List<ExportPackageDescription> exportsWiredTo = new ArrayList<ExportPackageDescription>(imports.length);
+ List<StateWire> importWires = new ArrayList<StateWire>(imports.length);
for (int i = 0; i < imports.length; i++)
- if (imports[i].getSelectedSupplier() != null)
- exportsWiredTo.add((ExportPackageDescription) imports[i].getSelectedSupplier().getBaseDescription());
+ if (imports[i].getSelectedSupplier() != null) {
+ ExportPackageDescription supplier = (ExportPackageDescription) imports[i].getSelectedSupplier().getBaseDescription();
+ exportsWiredTo.add(supplier);
+ StateWire wire = newStateWire(rb.getBundleDescription(), imports[i].getVersionConstraint(), supplier.getExporter(), supplier);
+ importWires.add(wire);
+ }
+ if (stateWires != null && !importWires.isEmpty())
+ stateWires.put(BundleRevision.PACKAGE_NAMESPACE, importWires);
return exportsWiredTo.toArray(new ExportPackageDescription[exportsWiredTo.size()]);
}
+ private static StateWire newStateWire(BundleDescription requirementHost, VersionConstraint declaredRequirement, BundleDescription capabilityHost, BaseDescription declaredCapability) {
+ BaseDescription fragDeclared = ((BaseDescriptionImpl) declaredCapability).getFragmentDeclaration();
+ declaredCapability = fragDeclared != null ? fragDeclared : declaredCapability;
+ return new StateWire(requirementHost, declaredRequirement, capabilityHost, declaredCapability);
+ }
+
// Resolve dynamic import
public synchronized ExportPackageDescription resolveDynamicImport(BundleDescription importingBundle, String requestedPackage) {
if (state == null)
@@ -1720,6 +1761,16 @@ public class ResolverImpl implements Resolver {
}
}
+ private void addStateWire(BundleDescription importingBundle, VersionConstraint requirement, BundleDescription capabilityHost, ExportPackageDescription capability) {
+ Map<String, List<StateWire>> wires = ((BundleDescriptionImpl) importingBundle).getWires();
+ List<StateWire> imports = wires.get(BundleRevision.PACKAGE_NAMESPACE);
+ if (imports == null) {
+ imports = new ArrayList<StateWire>();
+ wires.put(BundleRevision.PACKAGE_NAMESPACE, imports);
+ }
+ imports.add(newStateWire(importingBundle, requirement, capabilityHost, capability));
+ }
+
private ExportPackageDescription resolveDynamicImport(ResolverImport dynamicImport, String requestedPackage) {
String importName = dynamicImport.getName();
// If the import uses a wildcard, then temporarily replace this with the requested package
@@ -1742,7 +1793,11 @@ public class ResolverImpl implements Resolver {
// If the import resolved then return it's matching export
if (DEBUG_IMPORTS)
ResolverImpl.log("Resolved dynamic import: " + dynamicImport.getBundle() + ":" + dynamicImport.getName() + " -> " + ((ResolverExport) dynamicImport.getSelectedSupplier()).getExporter() + ":" + requestedPackage); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- return ((ResolverExport) dynamicImport.getSelectedSupplier()).getExportPackageDescription();
+
+ ExportPackageDescription supplier = ((ResolverExport) dynamicImport.getSelectedSupplier()).getExportPackageDescription();
+ if (supplier != null)
+ addStateWire(dynamicImport.getBundleDescription(), dynamicImport.getVersionConstraint(), supplier.getExporter(), supplier);
+ return supplier;
}
}
dynamicImport.clearPossibleSuppliers();
@@ -1833,7 +1888,7 @@ public class ResolverImpl implements Resolver {
setBundleUnresolved(bundle, removed, false);
// Get bundles dependent on 'bundle'
BundleDescription[] dependents = bundle.getBundleDescription().getDependents();
- state.resolveBundle(bundle.getBundleDescription(), false, null, null, null, null, null, null, null);
+ state.resolveBundle(bundle.getBundleDescription(), false, null, null, null, null, null, null, null, null);
// Unresolve dependents of 'bundle'
for (int i = 0; i < dependents.length; i++)
unresolveBundle(bundleMapping.get(dependents[i]), false);
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/VersionHashMap.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/VersionHashMap.java
index 6b7be54b6..b27b03876 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/VersionHashMap.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/VersionHashMap.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2010 IBM Corporation and others.
+ * Copyright (c) 2004, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -78,7 +78,7 @@ public class VersionHashMap<V extends VersionSupplier> extends MappedList<String
void reorder() {
for (Iterator<List<V>> it = internal.values().iterator(); it.hasNext();) {
List<V> existing = it.next();
- if (existing.size() > 0)
+ if (existing.size() > 1)
Collections.sort(existing, this);
}
}
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/VersionSupplier.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/VersionSupplier.java
index 9ffdaeb91..03c94b021 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/VersionSupplier.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/VersionSupplier.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2008 IBM Corporation and others.
+ * Copyright (c) 2004, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -13,14 +13,14 @@ package org.eclipse.osgi.internal.module;
import org.eclipse.osgi.service.resolver.BaseDescription;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.osgi.framework.Version;
-import org.osgi.framework.wiring.Capability;
+import org.osgi.framework.wiring.BundleCapability;
/*
* A companion to BaseDescription from the state used while resolving.
*/
public abstract class VersionSupplier {
final protected BaseDescription base;
- final private Capability capability;
+ final private BundleCapability capability;
private VersionSupplier substitute;
VersionSupplier(BaseDescription base) {
@@ -65,7 +65,7 @@ public abstract class VersionSupplier {
return base.toString();
}
- Capability getCapability() {
+ BundleCapability getCapability() {
return capability;
}
}
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/BaseDescriptionImpl.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/BaseDescriptionImpl.java
index 5d890cf3f..c158d325f 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/BaseDescriptionImpl.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/BaseDescriptionImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2010 IBM Corporation and others.
+ * Copyright (c) 2004, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -13,11 +13,11 @@ package org.eclipse.osgi.internal.resolver;
import java.util.*;
import org.eclipse.osgi.service.resolver.BaseDescription;
-import org.eclipse.osgi.service.resolver.BundleDescription;
import org.osgi.framework.Version;
-import org.osgi.framework.wiring.*;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRevision;
-abstract class BaseDescriptionImpl implements BaseDescription {
+public abstract class BaseDescriptionImpl implements BaseDescription {
protected final Object monitor = new Object();
@@ -84,24 +84,18 @@ abstract class BaseDescriptionImpl implements BaseDescription {
return null;
}
- WiredCapability getWiredCapability(String namespace) {
- if (namespace == null)
- namespace = getInternalNameSpace();
- if (namespace == null)
- return null;
-
- BundleDescription supplier = getSupplier();
- BundleWiring wiring = supplier.getBundleWiring();
- if (wiring == null)
- return null;
- return new BaseWiredCapability(namespace, wiring);
+ public BaseDescription getFragmentDeclaration() {
+ return null;
}
- public Capability getCapability() {
+ public BundleCapability getCapability() {
return getCapability(null);
}
- Capability getCapability(String namespace) {
+ BundleCapability getCapability(String namespace) {
+ BaseDescriptionImpl fragmentDeclaration = (BaseDescriptionImpl) getFragmentDeclaration();
+ if (fragmentDeclaration != null)
+ return fragmentDeclaration.getCapability(namespace);
if (namespace == null)
namespace = getInternalNameSpace();
if (namespace == null)
@@ -109,7 +103,7 @@ abstract class BaseDescriptionImpl implements BaseDescription {
return new BaseCapability(namespace);
}
- class BaseCapability implements Capability {
+ class BaseCapability implements BundleCapability {
private final String namespace;
public BaseCapability(String namespace) {
@@ -117,7 +111,7 @@ abstract class BaseDescriptionImpl implements BaseDescription {
this.namespace = namespace;
}
- public BundleRevision getProviderRevision() {
+ public BundleRevision getRevision() {
return getSupplier();
}
@@ -162,61 +156,4 @@ abstract class BaseDescriptionImpl implements BaseDescription {
return getNamespace() + BaseDescriptionImpl.toString(getAttributes(), false);
}
}
-
- class BaseWiredCapability extends BaseCapability implements WiredCapability {
- private final BundleWiring originalWiring;
-
- public BaseWiredCapability(String namespace, BundleWiring originalWiring) {
- super(namespace);
- this.originalWiring = originalWiring;
- }
-
- public Collection<BundleWiring> getRequirerWirings() {
- BundleWiring wiring = getProviderWiring();
- if (wiring == null)
- return null;
- BundleDescription supplier = getSupplier();
- BundleDescription[] dependents = supplier.getDependents();
- Collection<BundleWiring> requirers = new ArrayList<BundleWiring>();
- if (Capability.HOST_CAPABILITY.equals(getNamespace())) {
- // special casing osgi.host capability.
- // this is needed because the host capability is manufactured only for
- // representation in the wiring API. We need to represent a host wiring
- // as requiring its own osgi.host capability if it has attached fragments
- List<BundleRevision> fragments = wiring.getFragmentRevisions();
- if (fragments != null && fragments.size() > 0)
- // found at least one fragment add the host wiring as a requirer and return
- requirers.add(wiring);
- }
-
- for (BundleDescription dependent : dependents) {
- BundleWiring dependentWiring = dependent.getBundleWiring();
- if (dependentWiring == null) // fragments have no wiring
- continue;
- List<WiredCapability> namespace = dependentWiring.getRequiredCapabilities(getNamespace());
- if (namespace == null)
- continue;
- if (namespace.contains(this))
- requirers.add(dependentWiring);
- }
- return requirers;
- }
-
- public BundleWiring getProviderWiring() {
- return originalWiring.isInUse() ? originalWiring : null;
- }
-
- public int hashCode() {
- return System.identityHashCode(BaseDescriptionImpl.this) ^ System.identityHashCode(originalWiring);
- }
-
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (!(obj instanceof BaseWiredCapability))
- return false;
- BaseWiredCapability other = (BaseWiredCapability) obj;
- return (other.originalWiring == this.originalWiring) && super.equals(obj);
- }
- }
}
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/BundleDescriptionImpl.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/BundleDescriptionImpl.java
index a3ab615f6..efcc81c76 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/BundleDescriptionImpl.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/BundleDescriptionImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2010 IBM Corporation and others.
+ * Copyright (c) 2003, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -47,7 +47,7 @@ public final class BundleDescriptionImpl extends BaseDescriptionImpl implements
private volatile int stateBits = FULLY_LOADED | ATTACH_FRAGMENTS | DYNAMIC_FRAGMENTS;
private volatile long bundleId = -1;
- private volatile HostSpecification host; //null if the bundle is not a fragment. volatile to allow unsynchronized checks for null
+ volatile HostSpecification host; //null if the bundle is not a fragment. volatile to allow unsynchronized checks for null
private volatile StateImpl containingState;
private volatile Object userObject;
@@ -257,6 +257,23 @@ public final class BundleDescriptionImpl extends BaseDescriptionImpl implements
}
}
+ public Map<String, List<StateWire>> getWires() {
+ LazyData currentData = loadLazyData();
+ synchronized (this.monitor) {
+ if (currentData.stateWires == null) {
+ currentData.stateWires = new HashMap<String, List<StateWire>>(0);
+ }
+ return currentData.stateWires;
+ }
+ }
+
+ Map<String, List<StateWire>> getWiresInternal() {
+ LazyData currentData = loadLazyData();
+ synchronized (this.monitor) {
+ return currentData.stateWires;
+ }
+ }
+
protected void setBundleId(long bundleId) {
this.bundleId = bundleId;
}
@@ -461,6 +478,13 @@ public final class BundleDescriptionImpl extends BaseDescriptionImpl implements
}
}
+ protected void setStateWires(Map<String, List<StateWire>> stateWires) {
+ synchronized (this.monitor) {
+ checkLazyData();
+ lazyData.stateWires = stateWires;
+ }
+ }
+
void clearAddedDynamicImportPackages() {
synchronized (this.monitor) {
checkLazyData();
@@ -792,6 +816,7 @@ public final class BundleDescriptionImpl extends BaseDescriptionImpl implements
String[] executionEnvironments;
Map<String, Long> dynamicStamps;
+ Map<String, List<StateWire>> stateWires;
// Note that this is not persisted in the state cache
List<ImportPackageSpecification> addedDynamicImports;
}
@@ -856,37 +881,61 @@ public final class BundleDescriptionImpl extends BaseDescriptionImpl implements
if (attributes != null)
result.putAll(attributes);
}
- result.put(Capability.BUNDLE_CAPABILITY, getName());
+ result.put(BundleRevision.BUNDLE_NAMESPACE, getName());
result.put(Constants.BUNDLE_VERSION_ATTRIBUTE, getVersion());
return Collections.unmodifiableMap(result);
}
- public List<Capability> getDeclaredCapabilities(String namespace) {
- List<Capability> result = new ArrayList<Capability>();
+ public List<BundleRequirement> getDeclaredRequirements(String namespace) {
+ List<BundleRequirement> result = new ArrayList<BundleRequirement>();
+ if (namespace == null || BundleRevision.BUNDLE_NAMESPACE.equals(namespace)) {
+ BundleSpecification[] requires = getRequiredBundles();
+ for (BundleSpecification require : requires) {
+ result.add(require.getRequirement());
+ }
+ }
+ if (host != null && (namespace == null || BundleRevision.HOST_NAMESPACE.equals(namespace))) {
+ result.add(host.getRequirement());
+ }
+ if (namespace == null || BundleRevision.PACKAGE_NAMESPACE.equals(namespace)) {
+ ImportPackageSpecification[] imports = getImportPackages();
+ for (ImportPackageSpecification importPkg : imports)
+ result.add(importPkg.getRequirement());
+ }
+ GenericSpecification[] genericSpecifications = getGenericRequires();
+ for (GenericSpecification requirement : genericSpecifications) {
+ if (namespace == null || namespace.equals(requirement.getType()))
+ result.add(requirement.getRequirement());
+ }
+ return Collections.unmodifiableList(result);
+ }
+
+ public List<BundleCapability> getDeclaredCapabilities(String namespace) {
+ List<BundleCapability> result = new ArrayList<BundleCapability>();
if (host == null) {
if (getSymbolicName() != null) {
- if (namespace == null || Capability.BUNDLE_CAPABILITY.equals(namespace)) {
+ if (namespace == null || BundleRevision.BUNDLE_NAMESPACE.equals(namespace)) {
result.add(BundleDescriptionImpl.this.getCapability());
}
- if (attachFragments() && (namespace == null || Capability.HOST_CAPABILITY.equals(namespace))) {
- result.add(BundleDescriptionImpl.this.getCapability(Capability.HOST_CAPABILITY));
+ if (attachFragments() && (namespace == null || BundleRevision.HOST_NAMESPACE.equals(namespace))) {
+ result.add(BundleDescriptionImpl.this.getCapability(BundleRevision.HOST_NAMESPACE));
}
}
} else {
- // may need to have a osgi.fragment capability
+ // may need to have a osgi.wiring.fragment capability
}
- if (namespace == null || Capability.PACKAGE_CAPABILITY.equals(namespace)) {
+ if (namespace == null || BundleRevision.PACKAGE_NAMESPACE.equals(namespace)) {
ExportPackageDescription[] exports = getExportPackages();
- for (ExportPackageDescription importPkg : exports)
- result.add(importPkg.getCapability());
+ for (ExportPackageDescription exportPkg : exports)
+ result.add(exportPkg.getCapability());
}
GenericDescription[] genericCapabilities = getGenericCapabilities();
for (GenericDescription capabilitiy : genericCapabilities) {
if (namespace == null || namespace.equals(capabilitiy.getType()))
result.add(capabilitiy.getCapability());
}
- return result;
+ return Collections.unmodifiableList(result);
}
public int getTypes() {
@@ -901,17 +950,72 @@ public final class BundleDescriptionImpl extends BaseDescriptionImpl implements
}
String getInternalNameSpace() {
- return Capability.BUNDLE_CAPABILITY;
+ return BundleRevision.BUNDLE_NAMESPACE;
}
- public BundleWiring getBundleWiring() {
+ public BundleWiring getWiring() {
synchronized (this.monitor) {
- if (bundleWiring != null || !isResolved() || (getTypes() & BundleRevision.TYPE_FRAGMENT) != 0)
+ if (bundleWiring != null || !isResolved())
return bundleWiring;
return bundleWiring = new DescriptionWiring();
}
}
+ static class BundleWireImpl implements BundleWire {
+ private final BundleCapability capability;
+ private final BundleWiring provider;
+ private final BundleRequirement requirement;
+ private final BundleWiring requirer;
+
+ public BundleWireImpl(StateWire wire) {
+ VersionConstraint declaredRequirement = wire.getDeclaredRequirement();
+ if (declaredRequirement instanceof HostSpecification)
+ this.capability = ((BaseDescriptionImpl) wire.getDeclaredCapability()).getCapability(BundleRevision.HOST_NAMESPACE);
+ else
+ this.capability = wire.getDeclaredCapability().getCapability();
+ this.provider = wire.getCapabilityHost().getWiring();
+ this.requirement = declaredRequirement.getRequirement();
+ this.requirer = wire.getRequirementHost().getWiring();
+ }
+
+ public BundleCapability getCapability() {
+ return capability;
+ }
+
+ public BundleRequirement getRequirement() {
+ return requirement;
+ }
+
+ public BundleWiring getProviderWiring() {
+ return provider;
+ }
+
+ public BundleWiring getRequirerWiring() {
+ return requirer;
+ }
+
+ @Override
+ public int hashCode() {
+ int hashcode = 31 + capability.hashCode();
+ hashcode = hashcode * 31 + requirement.hashCode();
+ hashcode = hashcode * 31 + provider.hashCode();
+ hashcode = hashcode * 31 + requirer.hashCode();
+ return hashcode;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof BundleWireImpl))
+ return false;
+ BundleWireImpl other = (BundleWireImpl) obj;
+ return capability.equals(other.getCapability()) && requirement.equals(other.getRequirement()) && provider.equals(other.getProviderWiring()) && requirer.equals(other.getRequirerWiring());
+ }
+
+ public String toString() {
+ return getRequirement() + " -> " + getCapability(); //$NON-NLS-1$
+ }
+ }
+
// Note that description wiring are identity equality based
class DescriptionWiring implements BundleWiring {
private volatile boolean valid = true;
@@ -932,69 +1036,115 @@ public final class BundleDescriptionImpl extends BaseDescriptionImpl implements
return valid && !BundleDescriptionImpl.this.isRemovalPending();
}
- public List<WiredCapability> getRequiredCapabilities(String capabilityNamespace) {
+ public List<BundleCapability> getCapabilities(String namespace) {
if (!isInUse())
return null;
- List<WiredCapability> result = new ArrayList<WiredCapability>();
- if (capabilityNamespace == null || Capability.BUNDLE_CAPABILITY.equals(capabilityNamespace)) {
- BundleDescription[] requires = getResolvedRequires();
- for (BundleDescription require : requires)
- result.add(((BaseDescriptionImpl) require).getWiredCapability(null));
- }
- if (attachFragments() && (capabilityNamespace == null || Capability.HOST_CAPABILITY.equals(capabilityNamespace))) {
- Collection<BundleRevision> fragments = getFragmentRevisions();
- if (fragments.size() > 0)
- result.add(BundleDescriptionImpl.this.getWiredCapability(Capability.HOST_CAPABILITY));
+ @SuppressWarnings("unchecked")
+ List<BundleCapability> result = Collections.EMPTY_LIST;
+ if (host != null)
+ return result;
+ result = new ArrayList<BundleCapability>();
+ if (getSymbolicName() != null) {
+ if (namespace == null || BundleRevision.BUNDLE_NAMESPACE.equals(namespace)) {
+ result.add(BundleDescriptionImpl.this.getCapability());
+ }
+ if (attachFragments() && (namespace == null || BundleRevision.HOST_NAMESPACE.equals(namespace))) {
+ result.add(BundleDescriptionImpl.this.getCapability(BundleRevision.HOST_NAMESPACE));
+ }
}
- if (capabilityNamespace == null || Capability.PACKAGE_CAPABILITY.equals(capabilityNamespace)) {
- ExportPackageDescription[] imports = getResolvedImports();
- for (ExportPackageDescription importPkg : imports)
- result.add(((BaseDescriptionImpl) importPkg).getWiredCapability(null));
+ if (namespace == null || BundleRevision.PACKAGE_NAMESPACE.equals(namespace)) {
+ ExportPackageDescription[] exports = getSelectedExports();
+ for (ExportPackageDescription exportPkg : exports)
+ result.add(exportPkg.getCapability());
}
- GenericDescription[] genericRequires = getResolvedGenericRequires();
- for (GenericDescription require : genericRequires) {
- if (capabilityNamespace == null || capabilityNamespace.equals(require.getType()))
- result.add(((BaseDescriptionImpl) require).getWiredCapability(null));
+ GenericDescription[] genericCapabilities = getSelectedGenericCapabilities();
+ for (GenericDescription capabilitiy : genericCapabilities) {
+ if (namespace == null || namespace.equals(capabilitiy.getType()))
+ result.add(capabilitiy.getCapability());
}
return result;
}
- public List<WiredCapability> getProvidedCapabilities(String capabilityNamespace) {
- if (!isInUse())
+ public List<BundleRequirement> getRequirements(String namespace) {
+ List<BundleWire> requiredWires = getRequiredWires(namespace);
+ if (requiredWires == null)
+ // happens if not in use
return null;
- List<WiredCapability> result = new ArrayList<WiredCapability>();
- if (getSymbolicName() != null) {
- if ((capabilityNamespace == null || Capability.BUNDLE_CAPABILITY.equals(capabilityNamespace)))
- result.add(BundleDescriptionImpl.this.getWiredCapability(null));
- if (attachFragments() && (capabilityNamespace == null || Capability.HOST_CAPABILITY.endsWith(capabilityNamespace)))
- result.add(BundleDescriptionImpl.this.getWiredCapability(Capability.HOST_CAPABILITY));
+ List<BundleRequirement> requirements = new ArrayList<BundleRequirement>(requiredWires.size());
+ for (BundleWire wire : requiredWires) {
+ if (!requirements.contains(wire.getRequirement()))
+ requirements.add(wire.getRequirement());
+ }
+ // get dynamic imports
+ if (namespace == null || BundleRevision.PACKAGE_NAMESPACE.equals(namespace)) {
+ if (hasDynamicImports()) {
+ ImportPackageSpecification[] imports = getImportPackages();
+ for (ImportPackageSpecification impPackage : imports) {
+ if (ImportPackageSpecification.RESOLUTION_DYNAMIC.equals(impPackage.getDirective(Constants.RESOLUTION_DIRECTIVE))) {
+ BundleRequirement req = impPackage.getRequirement();
+ if (!requirements.contains(req))
+ requirements.add(req);
+ }
+ }
+ }
}
+ return requirements;
+ }
- if (capabilityNamespace == null || Capability.PACKAGE_CAPABILITY.equals(capabilityNamespace)) {
- ExportPackageDescription[] exports = getSelectedExports();
- for (ExportPackageDescription importPkg : exports)
- result.add(((BaseDescriptionImpl) importPkg).getWiredCapability(null));
+ public List<BundleWire> getProvidedWires(String namespace) {
+ if (!isInUse())
+ return null;
+ BundleDescription[] dependentBundles = getDependents();
+ List<BundleWire> unorderedResult = new ArrayList<BundleWire>();
+ for (BundleDescription dependent : dependentBundles) {
+ List<BundleWire> dependentWires = dependent.getWiring().getRequiredWires(namespace);
+ if (dependentWires != null)
+ for (BundleWire bundleWire : dependentWires) {
+ if (bundleWire.getProviderWiring() == this)
+ unorderedResult.add(bundleWire);
+ }
}
- GenericDescription[] genericCapabilities = getSelectedGenericCapabilities();
- for (GenericDescription capabilitiy : genericCapabilities) {
- if (capabilityNamespace == null || capabilityNamespace.equals(capabilitiy.getType()))
- result.add(((BaseDescriptionImpl) capabilitiy).getWiredCapability(null));
+ List<BundleWire> orderedResult = new ArrayList<BundleWire>(unorderedResult.size());
+ List<BundleCapability> capabilities = getCapabilities(namespace);
+ for (BundleCapability capability : capabilities) {
+ for (Iterator<BundleWire> wires = unorderedResult.iterator(); wires.hasNext();) {
+ BundleWire wire = wires.next();
+ if (wire.getCapability().equals(capability)) {
+ wires.remove();
+ orderedResult.add(wire);
+ }
+ }
}
- return result;
+ return orderedResult;
}
- public List<BundleRevision> getFragmentRevisions() {
+ public List<BundleWire> getRequiredWires(String namespace) {
if (!isInUse())
return null;
- List<BundleRevision> results = new ArrayList<BundleRevision>();
- BundleDescription[] deps = getDependents();
- for (BundleDescription dependent : deps) {
- if (dependent.getHost() != null) {
- // found a fragment
- results.add(dependent);
+ @SuppressWarnings("unchecked")
+ List<BundleWire> result = Collections.EMPTY_LIST;
+ Map<String, List<StateWire>> wireMap = getWires();
+ if (namespace == null) {
+ result = new ArrayList<BundleWire>();
+ for (List<StateWire> wires : wireMap.values()) {
+ for (StateWire wire : wires) {
+ result.add(new BundleWireImpl(wire));
+ }
}
+ return result;
+ }
+ List<StateWire> wires = wireMap.get(namespace);
+ if (wires == null)
+ return result;
+ result = new ArrayList<BundleWire>(wires.size());
+ for (StateWire wire : wires) {
+ result.add(new BundleWireImpl(wire));
}
- return results;
+ return result;
+ }
+
+ public BundleRevision getRevision() {
+ return BundleDescriptionImpl.this;
}
public ClassLoader getClassLoader() {
@@ -1019,10 +1169,6 @@ public final class BundleDescriptionImpl extends BaseDescriptionImpl implements
return null;
}
- public BundleRevision getBundleRevision() {
- return BundleDescriptionImpl.this;
- }
-
private boolean hasResourcePermission() {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/BundleSpecificationImpl.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/BundleSpecificationImpl.java
index 01e350b36..630313186 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/BundleSpecificationImpl.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/BundleSpecificationImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2008 IBM Corporation and others.
+ * Copyright (c) 2003, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,10 +11,10 @@
*******************************************************************************/
package org.eclipse.osgi.internal.resolver;
-import java.util.Map;
-import org.eclipse.osgi.service.resolver.BaseDescription;
-import org.eclipse.osgi.service.resolver.BundleSpecification;
+import java.util.*;
+import org.eclipse.osgi.service.resolver.*;
import org.osgi.framework.Constants;
+import org.osgi.framework.wiring.BundleRevision;
public class BundleSpecificationImpl extends VersionConstraintImpl implements BundleSpecification {
private boolean exported;
@@ -93,4 +93,36 @@ public class BundleSpecificationImpl extends VersionConstraintImpl implements Bu
public String toString() {
return "Require-Bundle: " + getName() + "; bundle-version=\"" + getVersionRange() + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
+
+ @Override
+ protected Map<String, String> getInternalDirectives() {
+ Map<String, String> result = new HashMap<String, String>(2);
+ synchronized (this.monitor) {
+ if (exported)
+ result.put(Constants.VISIBILITY_DIRECTIVE, Constants.VISIBILITY_REEXPORT);
+ if (optional)
+ result.put(Constants.RESOLUTION_DIRECTIVE, Constants.RESOLUTION_OPTIONAL);
+ return Collections.unmodifiableMap(result);
+ }
+ }
+
+ @Override
+ protected Map<String, Object> getInteralAttributes() {
+ Map<String, Object> result = new HashMap<String, Object>(2);
+ synchronized (this.monitor) {
+ if (attributes != null)
+ result.putAll(attributes);
+ result.put(BundleRevision.BUNDLE_NAMESPACE, getName());
+ VersionRange range = getVersionRange();
+ if (range != null)
+ result.put(Constants.BUNDLE_VERSION_ATTRIBUTE, range.toString());
+ return Collections.unmodifiableMap(result);
+ }
+ }
+
+ @Override
+ protected String getInternalNameSpace() {
+ // TODO Auto-generated method stub
+ return BundleRevision.BUNDLE_NAMESPACE;
+ }
}
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/ExportPackageDescriptionImpl.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/ExportPackageDescriptionImpl.java
index 6863b681a..a76444518 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/ExportPackageDescriptionImpl.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/ExportPackageDescriptionImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2010 IBM Corporation and others.
+ * Copyright (c) 2004, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -14,10 +14,9 @@ package org.eclipse.osgi.internal.resolver;
import java.util.*;
import org.eclipse.osgi.framework.internal.core.Constants;
-import org.eclipse.osgi.service.resolver.BundleDescription;
-import org.eclipse.osgi.service.resolver.ExportPackageDescription;
+import org.eclipse.osgi.service.resolver.*;
import org.osgi.framework.Version;
-import org.osgi.framework.wiring.Capability;
+import org.osgi.framework.wiring.BundleRevision;
public class ExportPackageDescriptionImpl extends BaseDescriptionImpl implements ExportPackageDescription {
public static final String EQUINOX_EE = "x-equinox-ee"; //$NON-NLS-1$
@@ -31,7 +30,20 @@ public class ExportPackageDescriptionImpl extends BaseDescriptionImpl implements
private String[] mandatory;
private Boolean internal = Boolean.FALSE;
private int equinox_ee = -1;
- private volatile int tableIndex;
+ private ExportPackageDescription fragmentDeclaration = null;
+
+ public ExportPackageDescriptionImpl() {
+ super();
+ }
+
+ public ExportPackageDescriptionImpl(BundleDescription host, ExportPackageDescription fragmentDeclaration) {
+ setName(fragmentDeclaration.getName());
+ setVersion(fragmentDeclaration.getVersion());
+ setDirectives(fragmentDeclaration.getDirectives());
+ setAttributes(fragmentDeclaration.getAttributes());
+ setExporter(host);
+ this.fragmentDeclaration = fragmentDeclaration;
+ }
public Map<String, Object> getDirectives() {
synchronized (this.monitor) {
@@ -76,7 +88,7 @@ public class ExportPackageDescriptionImpl extends BaseDescriptionImpl implements
synchronized (this.monitor) {
if (attributes != null)
result.putAll(attributes);
- result.put(Capability.PACKAGE_CAPABILITY, getName());
+ result.put(BundleRevision.PACKAGE_NAMESPACE, getName());
result.put(Constants.VERSION_ATTRIBUTE, getVersion());
Version bundleVersion = getSupplier().getVersion();
if (bundleVersion != null)
@@ -185,19 +197,19 @@ public class ExportPackageDescriptionImpl extends BaseDescriptionImpl implements
this.exporter = exporter;
}
- public String toString() {
- return "Export-Package: " + getName() + "; version=\"" + getVersion() + "\""; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ public BaseDescription getFragmentDeclaration() {
+ return fragmentDeclaration;
}
- int getTableIndex() {
- return tableIndex;
+ void setFragmentDeclaration(ExportPackageDescription fragmentDeclaration) {
+ this.fragmentDeclaration = fragmentDeclaration;
}
- void setTableIndex(int tableIndex) {
- this.tableIndex = tableIndex;
+ public String toString() {
+ return "Export-Package: " + getName() + "; version=\"" + getVersion() + "\""; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
}
String getInternalNameSpace() {
- return Capability.PACKAGE_CAPABILITY;
+ return BundleRevision.PACKAGE_NAMESPACE;
}
}
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/GenericDescriptionImpl.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/GenericDescriptionImpl.java
index b53c563d9..9e438f033 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/GenericDescriptionImpl.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/GenericDescriptionImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 IBM Corporation and others.
+ * Copyright (c) 2006, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -12,8 +12,7 @@
package org.eclipse.osgi.internal.resolver;
import java.util.*;
-import org.eclipse.osgi.service.resolver.BundleDescription;
-import org.eclipse.osgi.service.resolver.GenericDescription;
+import org.eclipse.osgi.service.resolver.*;
import org.osgi.framework.Constants;
import org.osgi.framework.Version;
@@ -22,6 +21,29 @@ public class GenericDescriptionImpl extends BaseDescriptionImpl implements Gener
private volatile BundleDescription supplier;
private volatile String type = GenericDescription.DEFAULT_TYPE;
private Map<String, String> directives;
+ private GenericDescription fragmentDeclaration;
+
+ public GenericDescriptionImpl() {
+ super();
+ }
+
+ public GenericDescriptionImpl(BundleDescription host, GenericDescription fragmentDeclaration) {
+ setType(fragmentDeclaration.getType());
+ Dictionary<String, Object> origAttrs = fragmentDeclaration.getAttributes();
+ if (origAttrs != null) {
+ Hashtable<String, Object> copyAttrs = new Hashtable<String, Object>();
+ for (Enumeration<String> keys = origAttrs.keys(); keys.hasMoreElements();) {
+ String key = keys.nextElement();
+ copyAttrs.put(key, origAttrs.get(key));
+ }
+ setAttributes(copyAttrs);
+ }
+ Map<String, String> origDirectives = fragmentDeclaration.getDeclaredDirectives();
+ Map<String, String> copyDirectives = new HashMap<String, String>(origDirectives);
+ setDirectives(copyDirectives);
+ setSupplier(host);
+ this.fragmentDeclaration = fragmentDeclaration;
+ }
public Dictionary<String, Object> getAttributes() {
synchronized (this.monitor) {
@@ -113,4 +135,12 @@ public class GenericDescriptionImpl extends BaseDescriptionImpl implements Gener
String getInternalNameSpace() {
return getType();
}
+
+ public BaseDescription getFragmentDeclaration() {
+ return fragmentDeclaration;
+ }
+
+ void setFragmentDeclaration(GenericDescription fragmentDeclaration) {
+ this.fragmentDeclaration = fragmentDeclaration;
+ }
}
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/GenericSpecificationImpl.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/GenericSpecificationImpl.java
index c919258fa..2afacb7e5 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/GenericSpecificationImpl.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/GenericSpecificationImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 IBM Corporation and others.
+ * Copyright (c) 2006, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,6 +11,7 @@
*******************************************************************************/
package org.eclipse.osgi.internal.resolver;
+import java.util.*;
import org.eclipse.osgi.framework.internal.core.FilterImpl;
import org.eclipse.osgi.service.resolver.*;
import org.osgi.framework.*;
@@ -127,4 +128,28 @@ public class GenericSpecificationImpl extends VersionConstraintImpl implements G
this.suppliers = suppliers;
}
}
+
+ @Override
+ protected Map<String, String> getInternalDirectives() {
+ Map<String, String> result = new HashMap<String, String>(2);
+ synchronized (this.monitor) {
+ if ((resolution & GenericSpecification.RESOLUTION_OPTIONAL) != 0)
+ result.put(Constants.RESOLUTION_DIRECTIVE, Constants.RESOLUTION_OPTIONAL);
+ if (matchingFilter != null) {
+ result.put(Constants.FILTER_DIRECTIVE, matchingFilter.toString());
+ }
+ }
+ return Collections.unmodifiableMap(result);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected Map<String, Object> getInteralAttributes() {
+ return Collections.EMPTY_MAP;
+ }
+
+ @Override
+ protected String getInternalNameSpace() {
+ return getType();
+ }
}
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/HostSpecificationImpl.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/HostSpecificationImpl.java
index 527e77620..e433fa74c 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/HostSpecificationImpl.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/HostSpecificationImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2008 IBM Corporation and others.
+ * Copyright (c) 2003, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -12,9 +12,10 @@
package org.eclipse.osgi.internal.resolver;
-import java.util.Map;
+import java.util.*;
import org.eclipse.osgi.service.resolver.*;
import org.osgi.framework.Constants;
+import org.osgi.framework.wiring.BundleRevision;
public class HostSpecificationImpl extends VersionConstraintImpl implements HostSpecification {
@@ -111,4 +112,28 @@ public class HostSpecificationImpl extends VersionConstraintImpl implements Host
this.multihost = multihost;
}
}
+
+ @SuppressWarnings("unchecked")
+ protected Map<String, String> getInternalDirectives() {
+ // TODO this does not handle extension directive; but we do not support bootclasspath anyway
+ return Collections.EMPTY_MAP;
+ }
+
+ protected Map<String, Object> getInteralAttributes() {
+ Map<String, Object> result = new HashMap<String, Object>(2);
+ synchronized (this.monitor) {
+ if (attributes != null)
+ result.putAll(attributes);
+ result.put(BundleRevision.HOST_NAMESPACE, getName());
+ VersionRange range = getVersionRange();
+ if (range != null)
+ result.put(Constants.BUNDLE_VERSION_ATTRIBUTE, range.toString());
+ return Collections.unmodifiableMap(result);
+ }
+ }
+
+ @Override
+ protected String getInternalNameSpace() {
+ return BundleRevision.HOST_NAMESPACE;
+ }
}
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/ImportPackageSpecificationImpl.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/ImportPackageSpecificationImpl.java
index edf3107e2..6d34edd7f 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/ImportPackageSpecificationImpl.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/ImportPackageSpecificationImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2008 IBM Corporation and others.
+ * Copyright (c) 2003, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -15,6 +15,7 @@ package org.eclipse.osgi.internal.resolver;
import java.util.*;
import org.eclipse.osgi.framework.internal.core.Constants;
import org.eclipse.osgi.service.resolver.*;
+import org.osgi.framework.wiring.BundleRevision;
public class ImportPackageSpecificationImpl extends VersionConstraintImpl implements ImportPackageSpecification {
private String resolution = ImportPackageSpecification.RESOLUTION_STATIC; // the default is static
@@ -182,4 +183,32 @@ public class ImportPackageSpecificationImpl extends VersionConstraintImpl implem
public String toString() {
return "Import-Package: " + getName() + "; version=\"" + getVersionRange() + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
+
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ protected Map<String, String> getInternalDirectives() {
+ Map raw = getDirectives();
+ return Collections.unmodifiableMap(raw);
+ }
+
+ protected Map<String, Object> getInteralAttributes() {
+ Map<String, Object> result = new HashMap<String, Object>(2);
+ synchronized (this.monitor) {
+ if (attributes != null)
+ result.putAll(attributes);
+ result.put(BundleRevision.PACKAGE_NAMESPACE, getName());
+ VersionRange range = getVersionRange();
+ if (range != null)
+ result.put(Constants.VERSION_ATTRIBUTE, range.toString());
+ if (symbolicName != null)
+ result.put(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE, symbolicName);
+ if (bundleVersionRange != null)
+ result.put(Constants.BUNDLE_VERSION_ATTRIBUTE, bundleVersionRange.toString());
+ return Collections.unmodifiableMap(result);
+ }
+ }
+
+ @Override
+ protected String getInternalNameSpace() {
+ return BundleRevision.PACKAGE_NAMESPACE;
+ }
}
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/NativeCodeSpecificationImpl.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/NativeCodeSpecificationImpl.java
index 9a808e8d5..ee15b9edd 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/NativeCodeSpecificationImpl.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/NativeCodeSpecificationImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 IBM Corporation and others.
+ * Copyright (c) 2007, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -156,4 +156,19 @@ public class NativeCodeSpecificationImpl extends VersionConstraintImpl implement
return sb.toString();
}
+
+ @SuppressWarnings("unchecked")
+ protected Map<String, String> getInternalDirectives() {
+ return Collections.EMPTY_MAP;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected Map<String, Object> getInteralAttributes() {
+ return Collections.EMPTY_MAP;
+ }
+
+ @Override
+ protected String getInternalNameSpace() {
+ return null;
+ }
}
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/ReadOnlyState.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/ReadOnlyState.java
index a1d91c352..d0bc359ae 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/ReadOnlyState.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/ReadOnlyState.java
@@ -12,8 +12,7 @@
*******************************************************************************/
package org.eclipse.osgi.internal.resolver;
-import java.util.Collection;
-import java.util.Dictionary;
+import java.util.*;
import org.eclipse.osgi.service.resolver.*;
import org.osgi.framework.BundleException;
import org.osgi.framework.Version;
@@ -133,7 +132,7 @@ public final class ReadOnlyState implements State {
throw new UnsupportedOperationException();
}
- public void resolveBundle(BundleDescription bundle, boolean status, BundleDescription[] hosts, ExportPackageDescription[] selectedExports, ExportPackageDescription[] substitutedExports, GenericDescription[] selectedCapabilities, BundleDescription[] resolvedRequires, ExportPackageDescription[] resolvedImports, GenericDescription[] resolveCapabilities) {
+ public void resolveBundle(BundleDescription bundle, boolean status, BundleDescription[] hosts, ExportPackageDescription[] selectedExports, ExportPackageDescription[] substitutedExports, GenericDescription[] selectedCapabilities, BundleDescription[] resolvedRequires, ExportPackageDescription[] resolvedImports, GenericDescription[] resolvedCapabilities, Map<String, List<StateWire>> resolvedRequirements) {
throw new UnsupportedOperationException();
}
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateHelperImpl.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateHelperImpl.java
index de1db0560..131d7dd67 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateHelperImpl.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateHelperImpl.java
@@ -17,8 +17,8 @@ import org.eclipse.osgi.internal.baseadaptor.ArrayMap;
import org.eclipse.osgi.service.resolver.*;
import org.osgi.framework.hooks.resolver.ResolverHook;
import org.osgi.framework.hooks.resolver.ResolverHookFactory;
+import org.osgi.framework.wiring.BundleCapability;
import org.osgi.framework.wiring.BundleRevision;
-import org.osgi.framework.wiring.Capability;
/**
* An implementation for the StateHelper API. Access to this implementation is
@@ -125,7 +125,7 @@ public final class StateHelperImpl implements StateHelper {
Collection<BaseDescription> satisfied = null;
if (constraint instanceof BundleSpecification || constraint instanceof HostSpecification) {
BundleDescription[] suppliers = state.getBundles(constraint.getName());
- satisfied = getPossibleCandidates(constraint, suppliers, constraint instanceof HostSpecification ? Capability.HOST_CAPABILITY : null, hook, false);
+ satisfied = getPossibleCandidates(constraint, suppliers, constraint instanceof HostSpecification ? BundleRevision.HOST_NAMESPACE : null, hook, false);
} else if (constraint instanceof ImportPackageSpecification) {
List<ExportPackageDescription> exports = packages.get(constraint.getName());
if (exports != null)
@@ -194,7 +194,7 @@ public final class StateHelperImpl implements StateHelper {
List<VersionConstraint> unsatisfied = new ArrayList<VersionConstraint>();
HostSpecification host = bundle.getHost();
if (host != null)
- if (!host.isResolved() && !isBundleConstraintResolvable(host, Capability.HOST_CAPABILITY, hook))
+ if (!host.isResolved() && !isBundleConstraintResolvable(host, BundleRevision.HOST_NAMESPACE, hook))
unsatisfied.add(host);
BundleSpecification[] requiredBundles = bundle.getRequiredBundles();
for (int i = 0; i < requiredBundles.length; i++)
@@ -214,11 +214,11 @@ public final class StateHelperImpl implements StateHelper {
return unsatisfied.toArray(new VersionConstraint[unsatisfied.size()]);
}
- private ArrayMap<Capability, BaseDescription> asArrayMap(List<BaseDescription> descriptions, String namespace) {
- List<Capability> capabilities = new ArrayList<Capability>(descriptions.size());
+ private ArrayMap<BundleCapability, BaseDescription> asArrayMap(List<BaseDescription> descriptions, String namespace) {
+ List<BundleCapability> capabilities = new ArrayList<BundleCapability>(descriptions.size());
for (BaseDescription description : descriptions)
capabilities.add(((BaseDescriptionImpl) description).getCapability(namespace));
- return new ArrayMap<Capability, BaseDescription>(capabilities, descriptions);
+ return new ArrayMap<BundleCapability, BaseDescription>(capabilities, descriptions);
}
private List<BaseDescription> getPossibleCandidates(VersionConstraint constraint, BaseDescription[] descriptions, String namespace, ResolverHook hook, boolean resolved) {
@@ -227,7 +227,7 @@ public final class StateHelperImpl implements StateHelper {
if ((!resolved || descriptions[i].getSupplier().isResolved()) && constraint.isSatisfiedBy(descriptions[i]))
candidates.add(descriptions[i]);
if (hook != null)
- hook.filterMatches(constraint.getBundle(), asArrayMap(candidates, namespace));
+ hook.filterMatches(constraint.getRequirement(), asArrayMap(candidates, namespace));
return candidates;
}
@@ -268,7 +268,7 @@ public final class StateHelperImpl implements StateHelper {
* @see StateHelper
*/
public boolean isResolvable(HostSpecification specification) {
- return isBundleConstraintResolvable(specification, Capability.HOST_CAPABILITY);
+ return isBundleConstraintResolvable(specification, BundleRevision.HOST_NAMESPACE);
}
/*
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateImpl.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateImpl.java
index beac95554..79d37c5bf 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateImpl.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateImpl.java
@@ -139,7 +139,7 @@ public abstract class StateImpl implements State {
try {
resolving = true;
resolverErrors.remove(existing);
- resolveBundle(existing, false, null, null, null, null, null, null, null);
+ resolveBundle(existing, false, null, null, null, null, null, null, null, null);
} finally {
resolving = false;
}
@@ -311,10 +311,10 @@ public abstract class StateImpl implements State {
* @deprecated
*/
public void resolveBundle(BundleDescription bundle, boolean status, BundleDescription[] hosts, ExportPackageDescription[] selectedExports, ExportPackageDescription[] substitutedExports, BundleDescription[] resolvedRequires, ExportPackageDescription[] resolvedImports) {
- resolveBundle(bundle, status, hosts, selectedExports, substitutedExports, null, resolvedRequires, resolvedImports, null);
+ resolveBundle(bundle, status, hosts, selectedExports, substitutedExports, null, resolvedRequires, resolvedImports, null, null);
}
- public void resolveBundle(BundleDescription bundle, boolean status, BundleDescription[] hosts, ExportPackageDescription[] selectedExports, ExportPackageDescription[] substitutedExports, GenericDescription[] selectedCapabilities, BundleDescription[] resolvedRequires, ExportPackageDescription[] resolvedImports, GenericDescription[] resolveCapabilities) {
+ public void resolveBundle(BundleDescription bundle, boolean status, BundleDescription[] hosts, ExportPackageDescription[] selectedExports, ExportPackageDescription[] substitutedExports, GenericDescription[] selectedCapabilities, BundleDescription[] resolvedRequires, ExportPackageDescription[] resolvedImports, GenericDescription[] resolvedCapabilities, Map<String, List<StateWire>> resolvedWires) {
synchronized (this.monitor) {
if (!resolving)
throw new IllegalStateException(); // TODO need error message here!
@@ -333,12 +333,12 @@ public abstract class StateImpl implements State {
resolvedBundles.remove(modifiable);
modifiable.removeDependencies();
}
- // to support develoment mode we will resolveConstraints even if the resolve status == false
+ // to support development mode we will resolveConstraints even if the resolve status == false
// we only do this if the resolved constraints are not null
if (selectedExports == null || resolvedRequires == null || resolvedImports == null)
unresolveConstraints(modifiable);
else
- resolveConstraints(modifiable, hosts, selectedExports, substitutedExports, selectedCapabilities, resolvedRequires, resolvedImports, resolveCapabilities);
+ resolveConstraints(modifiable, hosts, selectedExports, substitutedExports, selectedCapabilities, resolvedRequires, resolvedImports, resolvedCapabilities, resolvedWires);
}
}
@@ -351,7 +351,7 @@ public abstract class StateImpl implements State {
}
}
- private void resolveConstraints(BundleDescriptionImpl bundle, BundleDescription[] hosts, ExportPackageDescription[] selectedExports, ExportPackageDescription[] substitutedExports, GenericDescription[] selectedCapabilities, BundleDescription[] resolvedRequires, ExportPackageDescription[] resolvedImports, GenericDescription[] resolvedCapabilities) {
+ private void resolveConstraints(BundleDescriptionImpl bundle, BundleDescription[] hosts, ExportPackageDescription[] selectedExports, ExportPackageDescription[] substitutedExports, GenericDescription[] selectedCapabilities, BundleDescription[] resolvedRequires, ExportPackageDescription[] resolvedImports, GenericDescription[] resolvedCapabilities, Map<String, List<StateWire>> resolvedWires) {
HostSpecificationImpl hostSpec = (HostSpecificationImpl) bundle.getHost();
if (hostSpec != null) {
if (hosts != null) {
@@ -369,6 +369,7 @@ public abstract class StateImpl implements State {
bundle.setSubstitutedExports(substitutedExports);
bundle.setSelectedCapabilities(selectedCapabilities);
bundle.setResolvedCapabilities(resolvedCapabilities);
+ bundle.setStateWires(resolvedWires);
bundle.addDependencies(hosts, true);
bundle.addDependencies(resolvedRequires, true);
@@ -381,25 +382,6 @@ public abstract class StateImpl implements State {
// there are issues here because the order in which fragments are resolved is not always the same ...
}
- // private void checkForSubstitutedExports(BundleDescriptionImpl bundle, ExportPackageDescription[] selectedExports) {
- // ExportPackageDescription[] existingSubstitutes = bundle.getSubstitutedExports();
- // ExportPackageDescription[] declaredExports = bundle.getExportPackages();
- // ArrayList substitutes = new ArrayList();
- // for (int i = 0; i < declaredExports.length; i++) {
- // boolean selected = false;
- // for (int j = 0; !selected && j < selectedExports.length; j++)
- // selected = declaredExports[i] == selectedExports[j];
- // if (!selected)
- // substitutes.add(declaredExports[i]);
- // }
- // if (substitutes.size() > 0) {
- // substitutes.ensureCapacity(substitutes.size() + existingSubstitutes.length);
- // for (int i = 0; i < existingSubstitutes.length; i++)
- // substitutes.add(0, existingSubstitutes[i]);
- // bundle.setSubstitutedExports((ExportPackageDescription[]) substitutes.toArray(new ExportPackageDescription[substitutes.size()]));
- // }
- // }
-
private void unresolveConstraints(BundleDescriptionImpl bundle) {
HostSpecificationImpl host = (HostSpecificationImpl) bundle.getHost();
if (host != null)
@@ -411,6 +393,7 @@ public abstract class StateImpl implements State {
bundle.setSubstitutedExports(null);
bundle.setSelectedCapabilities(null);
bundle.setResolvedCapabilities(null);
+ bundle.setStateWires(null);
bundle.clearAddedDynamicImportPackages();
// remove the constraint suppliers
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateReader.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateReader.java
index ea1954ce3..f31405073 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateReader.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateReader.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2010 IBM Corporation and others.
+ * Copyright (c) 2003, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -46,7 +46,7 @@ final class StateReader {
private volatile int numBundles;
private volatile boolean accessedFlag = false;
- public static final byte STATE_CACHE_VERSION = 35;
+ public static final byte STATE_CACHE_VERSION = 36;
public static final byte NULL = 0;
public static final byte OBJECT = 1;
public static final byte INDEX = 2;
@@ -75,7 +75,10 @@ final class StateReader {
}
private Object getFromObjectTable(int index) {
- return objectTable.get(new Integer(index));
+ Object result = objectTable.get(new Integer(index));
+ if (result == null)
+ throw new IllegalStateException("Expected to find an object at table index: " + index); //$NON-NLS-1$
+ return result;
}
private boolean readState(StateImpl state, long expectedTimestamp) throws IOException {
@@ -370,6 +373,10 @@ final class StateReader {
result.setNativeCodeSpecification(readNativeCode(in));
+ @SuppressWarnings("rawtypes")
+ Map raw = readMap(in);
+ result.setStateWires(raw);
+
result.setFullyLoaded(true); // set fully loaded before setting the dependencies
// No need to add bundle dependencies for hosts, imports or requires;
// This is done by readBundleDescription
@@ -377,7 +384,14 @@ final class StateReader {
}
private BundleSpecificationImpl readBundleSpec(DataInputStream in) throws IOException {
+ byte tag = readTag(in);
+ if (tag == NULL)
+ return null;
+ if (tag == INDEX)
+ return (BundleSpecificationImpl) getFromObjectTable(in.readInt());
BundleSpecificationImpl result = new BundleSpecificationImpl();
+ int tableIndex = in.readInt();
+ addToObjectTable(result, tableIndex);
readVersionConstraint(result, in);
result.setSupplier(readBundleDescription(in));
result.setExported(in.readBoolean());
@@ -395,11 +409,11 @@ final class StateReader {
ExportPackageDescriptionImpl exportPackageDesc = new ExportPackageDescriptionImpl();
int tableIndex = in.readInt();
addToObjectTable(exportPackageDesc, tableIndex);
- exportPackageDesc.setTableIndex(tableIndex);
readBaseDescription(exportPackageDesc, in);
exportPackageDesc.setExporter(readBundleDescription(in));
exportPackageDesc.setAttributes(readMap(in));
exportPackageDesc.setDirectives(readMap(in));
+ exportPackageDesc.setFragmentDeclaration(readExportPackageDesc(in));
return exportPackageDesc;
}
@@ -464,6 +478,9 @@ final class StateReader {
case 6 :
list.add(readVersion(in));
break;
+ case 7 :
+ list.add(readStateWire(in));
+ break;
default :
throw new IOException("Invalid type: " + listType); //$NON-NLS-1$
}
@@ -475,6 +492,39 @@ final class StateReader {
return result;
}
+ private Object readStateWire(DataInputStream in) throws IOException {
+ VersionConstraint requirement;
+ BundleDescription requirementHost;
+ BaseDescription capability;
+ BundleDescription capabilityHost;
+
+ byte wireType = in.readByte();
+ switch (wireType) {
+ case 0 :
+ requirement = readImportPackageSpec(in);
+ capability = readExportPackageDesc(in);
+ break;
+ case 1 :
+ requirement = readBundleSpec(in);
+ capability = readBundleDescription(in);
+ break;
+ case 2 :
+ requirement = readHostSpec(in);
+ capability = readBundleDescription(in);
+ break;
+ case 3 :
+ requirement = readGenericSpecification(in);
+ capability = readGenericDescription(in);
+ break;
+ default :
+ throw new IOException("Invalid wire type: " + wireType); //$NON-NLS-1$
+ }
+
+ requirementHost = readBundleDescription(in);
+ capabilityHost = readBundleDescription(in);
+ return new StateWire(requirementHost, requirement, capabilityHost, capability);
+ }
+
private String[] readList(DataInputStream in) throws IOException {
int count = in.readInt();
if (count == 0)
@@ -491,7 +541,14 @@ final class StateReader {
}
private ImportPackageSpecificationImpl readImportPackageSpec(DataInputStream in) throws IOException {
+ byte tag = readTag(in);
+ if (tag == NULL)
+ return null;
+ if (tag == INDEX)
+ return (ImportPackageSpecificationImpl) getFromObjectTable(in.readInt());
ImportPackageSpecificationImpl result = new ImportPackageSpecificationImpl();
+ int tableIndex = in.readInt();
+ addToObjectTable(result, tableIndex);
readVersionConstraint(result, in);
result.setSupplier(readExportPackageDesc(in));
result.setBundleSymbolicName(readString(in, false));
@@ -505,7 +562,11 @@ final class StateReader {
byte tag = readTag(in);
if (tag == NULL)
return null;
+ if (tag == INDEX)
+ return (HostSpecificationImpl) getFromObjectTable(in.readInt());
HostSpecificationImpl result = new HostSpecificationImpl();
+ int tableIndex = in.readInt();
+ addToObjectTable(result, tableIndex);
readVersionConstraint(result, in);
int hostCount = in.readInt();
if (hostCount > 0) {
@@ -542,11 +603,19 @@ final class StateReader {
Map directives = readMap(in);
if (directives != null)
result.setDirectives(directives);
+ result.setFragmentDeclaration(readGenericDescription(in));
return result;
}
private GenericSpecification readGenericSpecification(DataInputStream in) throws IOException {
+ byte tag = readTag(in);
+ if (tag == NULL)
+ return null;
+ if (tag == INDEX)
+ return (GenericSpecification) getFromObjectTable(in.readInt());
GenericSpecificationImpl result = new GenericSpecificationImpl();
+ int tableIndex = in.readInt();
+ addToObjectTable(result, tableIndex);
readVersionConstraint(result, in);
result.setType(readString(in, false));
int num = in.readInt();
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateWriter.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateWriter.java
index 72bc7c2a4..33e39e4de 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateWriter.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateWriter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2010 IBM Corporation and others.
+ * Copyright (c) 2003, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -28,7 +28,7 @@ class StateWriter {
// cached state.
private final Map<Object, Integer> objectTable = new HashMap<Object, Integer>();
- private final List<BundleDescription> forcedWrite = new ArrayList<BundleDescription>();
+ private final List<Object> forcedWrite = new ArrayList<Object>();
private int addToObjectTable(Object object) {
Integer cur = objectTable.get(object);
@@ -336,6 +336,7 @@ class StateWriter {
writeNativeCode(bundle.getNativeCodeSpecification(), out);
+ writeMap(out, ((BundleDescriptionImpl) bundle).getWiresInternal());
// save the size of the lazy data
((BundleDescriptionImpl) bundle).setLazyDataSize(out.size() - dataStart);
}
@@ -347,6 +348,8 @@ class StateWriter {
}
private void writeBundleSpec(BundleSpecificationImpl bundle, DataOutputStream out) throws IOException {
+ if (writePrefix(bundle, out))
+ return;
writeVersionConstraint(bundle, out);
writeBundleDescription((BundleDescription) bundle.getSupplier(), out, false);
out.writeBoolean(bundle.isExported());
@@ -361,6 +364,7 @@ class StateWriter {
writeBundleDescription(exportPackageDesc.getExporter(), out, false);
writeMap(out, exportPackageDesc.getAttributes());
writeMap(out, exportPackageDesc.getDirectives());
+ writeExportPackageDesc((ExportPackageDescriptionImpl) exportPackageDesc.getFragmentDeclaration(), out);
}
private void writeGenericDescription(GenericDescription description, DataOutputStream out) throws IOException {
@@ -378,9 +382,12 @@ class StateWriter {
writeMap(out, mapAttrs);
Map<String, String> directives = description.getDeclaredDirectives();
writeMap(out, directives);
+ writeGenericDescription((GenericDescription) ((BaseDescriptionImpl) description).getFragmentDeclaration(), out);
}
private void writeGenericSpecification(GenericSpecification specification, DataOutputStream out) throws IOException {
+ if (writePrefix(specification, out))
+ return;
writeVersionConstraint(specification, out);
writeStringOrNull(specification.getType() == GenericDescription.DEFAULT_TYPE ? null : specification.getType(), out);
GenericDescription[] suppliers = specification.getSuppliers();
@@ -505,12 +512,45 @@ class StateWriter {
case 6 :
writeVersion((Version) value, out);
break;
+ case 7 :
+ writeStateWire((StateWire) value, out);
default :
break;
}
}
}
+ private void writeStateWire(StateWire wire, DataOutputStream out) throws IOException {
+ VersionConstraint requirement = wire.getDeclaredRequirement();
+ if (requirement instanceof ImportPackageSpecificationImpl) {
+ out.writeByte(0);
+ writeImportPackageSpec((ImportPackageSpecificationImpl) requirement, out);
+ } else if (requirement instanceof BundleSpecificationImpl) {
+ out.writeByte(1);
+ writeBundleSpec((BundleSpecificationImpl) requirement, out);
+ } else if (requirement instanceof HostSpecificationImpl) {
+ out.writeByte(2);
+ writeHostSpec((HostSpecificationImpl) requirement, out, false);
+ } else if (requirement instanceof GenericSpecificationImpl) {
+ out.writeByte(3);
+ writeGenericSpecification((GenericSpecificationImpl) requirement, out);
+ } else
+ throw new IllegalArgumentException("Unknown requiement type: " + requirement.getClass());
+
+ BaseDescription capability = wire.getDeclaredCapability();
+ if (capability instanceof BundleDescription)
+ writeBundleDescription((BundleDescription) capability, out, false);
+ else if (capability instanceof ExportPackageDescriptionImpl)
+ writeExportPackageDesc((ExportPackageDescriptionImpl) capability, out);
+ else if (capability instanceof GenericDescription)
+ writeGenericDescription((GenericDescription) capability, out);
+ else
+ throw new IllegalArgumentException("Unknown capability type: " + requirement.getClass());
+
+ writeBundleDescription(wire.getRequirementHost(), out, false);
+ writeBundleDescription(wire.getCapabilityHost(), out, false);
+ }
+
private byte getListType(List<?> list) {
if (list.size() == 0)
return -1;
@@ -525,6 +565,8 @@ class StateWriter {
return 5;
if (type instanceof Version)
return 6;
+ if (type instanceof StateWire)
+ return 7;
return -2;
}
@@ -544,6 +586,8 @@ class StateWriter {
}
private void writeImportPackageSpec(ImportPackageSpecification importPackageSpec, DataOutputStream out) throws IOException {
+ if (writePrefix(importPackageSpec, out))
+ return;
writeVersionConstraint(importPackageSpec, out);
// TODO this is a hack until the state dynamic loading is cleaned up
// we should only write the supplier if we are resolved
@@ -559,11 +603,13 @@ class StateWriter {
}
private void writeHostSpec(HostSpecificationImpl host, DataOutputStream out, boolean force) throws IOException {
- if (host == null) {
- out.writeByte(StateReader.NULL);
+ if (host != null && force && !forcedWrite.contains(host)) {
+ int index = addToObjectTable(host);
+ out.writeByte(StateReader.OBJECT);
+ out.writeInt(index);
+ forcedWrite.add(host);
+ } else if (writePrefix(host, out))
return;
- }
- out.writeByte(StateReader.OBJECT);
writeVersionConstraint(host, out);
BundleDescription[] hosts = host.getHosts();
if (hosts == null) {
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/VersionConstraintImpl.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/VersionConstraintImpl.java
index 5d668cb15..d3c8df191 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/VersionConstraintImpl.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/VersionConstraintImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2010 IBM Corporation and others.
+ * Copyright (c) 2003, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -12,8 +12,12 @@
*******************************************************************************/
package org.eclipse.osgi.internal.resolver;
+import java.util.Collections;
+import java.util.Map;
import org.eclipse.osgi.framework.internal.core.Constants;
+import org.eclipse.osgi.internal.resolver.BaseDescriptionImpl.BaseCapability;
import org.eclipse.osgi.service.resolver.*;
+import org.osgi.framework.wiring.*;
abstract class VersionConstraintImpl implements VersionConstraint {
@@ -89,4 +93,67 @@ abstract class VersionConstraintImpl implements VersionConstraint {
this.supplier = supplier;
}
}
+
+ protected abstract String getInternalNameSpace();
+
+ protected abstract Map<String, String> getInternalDirectives();
+
+ protected abstract Map<String, Object> getInteralAttributes();
+
+ public BundleRequirement getRequirement() {
+ String namespace = getInternalNameSpace();
+ if (namespace == null)
+ return null;
+ return new BundleRequirementImpl(namespace);
+ }
+
+ class BundleRequirementImpl implements BundleRequirement {
+ private final String namespace;
+
+ public BundleRequirementImpl(String namespace) {
+ this.namespace = namespace;
+ }
+
+ public String getNamespace() {
+ return namespace;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Map<String, String> getDirectives() {
+ return Collections.unmodifiableMap(getInternalDirectives());
+ }
+
+ @SuppressWarnings("unchecked")
+ public Map<String, Object> getAttributes() {
+ return getInteralAttributes();
+ }
+
+ public BundleRevision getRevision() {
+ return getBundle();
+ }
+
+ public boolean matches(BundleCapability capability) {
+ return isSatisfiedBy(((BaseCapability) capability).getBaseDescription());
+ }
+
+ public int hashCode() {
+ return System.identityHashCode(VersionConstraintImpl.this);
+ }
+
+ private VersionConstraintImpl getVersionConstraint() {
+ return VersionConstraintImpl.this;
+ }
+
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!(obj instanceof BundleRequirementImpl))
+ return false;
+ return ((BundleRequirementImpl) obj).getVersionConstraint() == VersionConstraintImpl.this;
+ }
+
+ public String toString() {
+ return getNamespace() + BaseDescriptionImpl.toString(getAttributes(), false);
+ }
+ }
}

Back to the top