Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2011-09-12 21:32:43 +0000
committerThomas Watson2011-09-26 14:14:04 +0000
commitdbad33a7f9ccc7eeb91ad6fed66810e5cb450bc0 (patch)
tree33f17d75b679b8dd90274c37f513b73c9aeff5e3
parent27b217c6c3d7622ff2455f6ef4829778f1ee2730 (diff)
downloadrt.equinox.framework-dbad33a7f9ccc7eeb91ad6fed66810e5cb450bc0.tar.gz
rt.equinox.framework-dbad33a7f9ccc7eeb91ad6fed66810e5cb450bc0.tar.xz
rt.equinox.framework-dbad33a7f9ccc7eeb91ad6fed66810e5cb450bc0.zip
Bug 350960 - [R4.4] Support cardinality for Require-Capability
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/OSGiCapabilityTest.java42
-rw-r--r--bundles/org.eclipse.osgi.tests/test_files/genericCapability/c5.osgi.MF10
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/GenericSpecificationImpl.java3
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateBuilder.java13
4 files changed, 64 insertions, 4 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/OSGiCapabilityTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/OSGiCapabilityTest.java
index 9eb9b8472..483477993 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/OSGiCapabilityTest.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/OSGiCapabilityTest.java
@@ -21,6 +21,8 @@ import org.eclipse.osgi.service.resolver.*;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.osgi.framework.resource.*;
+import org.osgi.framework.wiring.BundleWire;
+import org.osgi.framework.wiring.BundleWiring;
public class OSGiCapabilityTest extends AbstractStateTest {
private static final String MANIFEST_ROOT = "test_files/genericCapability/";
@@ -439,6 +441,46 @@ public class OSGiCapabilityTest extends AbstractStateTest {
}
}
+ public void testOSGiCardinality() throws BundleException {
+ State state = buildEmptyState();
+ long bundleID = 0;
+ Dictionary manifest;
+
+ manifest = loadManifest("p1.osgi.MF");
+ BundleDescription p1 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME), bundleID++);
+ manifest = loadManifest("p2.osgi.MF");
+ BundleDescription p2 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME), bundleID++);
+ manifest = loadManifest("p3.osgi.MF");
+ BundleDescription p3 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME), bundleID++);
+ manifest = loadManifest("c5.osgi.MF");
+ BundleDescription c5 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME), bundleID++);
+
+ state.addBundle(p1);
+ state.addBundle(p2);
+ state.addBundle(p3);
+ state.addBundle(c5);
+
+ state.resolve();
+
+ assertTrue("p1", p1.isResolved());
+ assertTrue("p2", p2.isResolved());
+ assertTrue("p3", p3.isResolved());
+ assertTrue("c5", c5.isResolved());
+
+ BundleWiring c5Wiring = c5.getWiring();
+ List requiredWires = c5Wiring.getRequiredWires(null);
+ assertEquals("Wrong number of required wires.", 3, requiredWires.size());
+ List expectedCapabilities = new ArrayList();
+ expectedCapabilities.addAll(p1.getCapabilities("namespace.1"));
+ expectedCapabilities.addAll(p2.getCapabilities("namespace.1"));
+ expectedCapabilities.addAll(p3.getCapabilities("namespace.1"));
+ for (Iterator iWires = requiredWires.iterator(); iWires.hasNext();) {
+ BundleWire wire = (BundleWire) iWires.next();
+ expectedCapabilities.remove(wire.getCapability());
+ }
+ assertTrue("Unexpected capability wire: " + requiredWires, expectedCapabilities.isEmpty());
+ }
+
private void checkUsedImports(BundleDescription importer, ExportPackageDescription[] expectedPackages) {
ExportPackageDescription[] imported = importer.getResolvedImports();
assertEquals("Wrong number of imports for bundle: " + importer, expectedPackages.length, imported.length);
diff --git a/bundles/org.eclipse.osgi.tests/test_files/genericCapability/c5.osgi.MF b/bundles/org.eclipse.osgi.tests/test_files/genericCapability/c5.osgi.MF
new file mode 100644
index 000000000..fb3305de8
--- /dev/null
+++ b/bundles/org.eclipse.osgi.tests/test_files/genericCapability/c5.osgi.MF
@@ -0,0 +1,10 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: c3.osgi
+Bundle-Version: 1.0
+Require-Capability:
+ namespace.1;
+ filter:="(&(rank>=100)(!(rank>=400))
+ (percent>=0.1)(!(percent>=0.4))
+ (test.version>=1.0)(!(test.version>=4.0)))";
+ cardinality:="multiple"
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 617b4781d..2e15392a9 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
@@ -15,6 +15,7 @@ import java.util.*;
import org.eclipse.osgi.framework.internal.core.FilterImpl;
import org.eclipse.osgi.service.resolver.*;
import org.osgi.framework.*;
+import org.osgi.framework.resource.ResourceConstants;
public class GenericSpecificationImpl extends VersionConstraintImpl implements GenericSpecification {
private Filter matchingFilter;
@@ -170,6 +171,8 @@ public class GenericSpecificationImpl extends VersionConstraintImpl implements G
result.putAll(arbitraryDirectives);
if ((resolution & GenericSpecification.RESOLUTION_OPTIONAL) != 0)
result.put(Constants.RESOLUTION_DIRECTIVE, Constants.RESOLUTION_OPTIONAL);
+ if ((resolution & GenericSpecification.RESOLUTION_MULTIPLE) != 0)
+ result.put(ResourceConstants.REQUIREMENT_CARDINALITY_DIRECTIVE, ResourceConstants.REQUIREMENT_CARDINALITY_MULTIPLE);
if (matchingFilter != null) {
result.put(Constants.FILTER_DIRECTIVE, matchingFilter.toString());
}
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateBuilder.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateBuilder.java
index a3ecf0253..3a1dce124 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateBuilder.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateBuilder.java
@@ -32,7 +32,7 @@ public class StateBuilder {
private static final String[] DEFINED_FRAGMENT_HOST_DIRECTIVES = {Constants.EXTENSION_DIRECTIVE};
static final String[] DEFINED_BSN_DIRECTIVES = {Constants.SINGLETON_DIRECTIVE, Constants.FRAGMENT_ATTACHMENT_DIRECTIVE, Constants.MANDATORY_DIRECTIVE};
static final String[] DEFINED_BSN_MATCHING_ATTRS = {Constants.BUNDLE_VERSION_ATTRIBUTE, Constants.OPTIONAL_ATTRIBUTE, Constants.REPROVIDE_ATTRIBUTE};
- private static final String[] DEFINED_REQUIRE_CAPABILITY_DIRECTIVES = {Constants.RESOLUTION_DIRECTIVE, Constants.FILTER_DIRECTIVE};
+ private static final String[] DEFINED_REQUIRE_CAPABILITY_DIRECTIVES = {Constants.RESOLUTION_DIRECTIVE, Constants.FILTER_DIRECTIVE, ResourceConstants.REQUIREMENT_CARDINALITY_DIRECTIVE};
private static final String[] DEFINED_REQUIRE_CAPABILITY_ATTRS = {};
private static final String[] DEFINED_OSGI_VALIDATE_HEADERS = {Constants.IMPORT_PACKAGE, Constants.DYNAMICIMPORT_PACKAGE, Constants.EXPORT_PACKAGE, Constants.FRAGMENT_HOST, Constants.BUNDLE_SYMBOLICNAME, Constants.REQUIRE_BUNDLE};
static final String GENERIC_REQUIRE = "Eclipse-GenericRequire"; //$NON-NLS-1$
@@ -506,9 +506,14 @@ public class StateBuilder {
throw new BundleException(message + " : filter", BundleException.MANIFEST_ERROR, e); //$NON-NLS-1$
}
}
- String resolution = element.getDirective(Constants.RESOLUTION_DIRECTIVE);
- if (Constants.RESOLUTION_OPTIONAL.equals(resolution))
- spec.setResolution(GenericSpecification.RESOLUTION_OPTIONAL);
+ String resolutionDirective = element.getDirective(Constants.RESOLUTION_DIRECTIVE);
+ int resolution = 0;
+ if (Constants.RESOLUTION_OPTIONAL.equals(resolutionDirective))
+ resolution |= GenericSpecification.RESOLUTION_OPTIONAL;
+ String cardinality = element.getDirective(ResourceConstants.REQUIREMENT_CARDINALITY_DIRECTIVE);
+ if (ResourceConstants.REQUIREMENT_CARDINALITY_MULTIPLE.equals(cardinality))
+ resolution |= GenericSpecification.RESOLUTION_MULTIPLE;
+ spec.setResolution(resolution);
spec.setAttributes(getAttributes(element, DEFINED_REQUIRE_CAPABILITY_ATTRS));
spec.setArbitraryDirectives(getDirectives(element, DEFINED_REQUIRE_CAPABILITY_DIRECTIVES));
result.add(spec);

Back to the top