Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2011-07-05 19:23:55 +0000
committerThomas Watson2011-07-05 19:23:55 +0000
commite573cfeb5095b874c3dcd573dc404caca3b1d36d (patch)
treea6f88be4b971464c70af966aae7e3939e31f0c3d /bundles/org.eclipse.osgi/resolver
parentb73e2bb175dcd50b1435ded4e195bca64c10dfc7 (diff)
downloadrt.equinox.framework-e573cfeb5095b874c3dcd573dc404caca3b1d36d.tar.gz
rt.equinox.framework-e573cfeb5095b874c3dcd573dc404caca3b1d36d.tar.xz
rt.equinox.framework-e573cfeb5095b874c3dcd573dc404caca3b1d36d.zip
Bug 349618 - Framework support for Resource, etc. in OSGi 4.4
Diffstat (limited to 'bundles/org.eclipse.osgi/resolver')
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverBundle.java26
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverImpl.java29
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/BaseDescriptionImpl.java4
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/BundleDescriptionImpl.java35
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/BundleSpecificationImpl.java14
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/GenericSpecificationImpl.java5
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/HostSpecificationImpl.java24
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/ImportPackageSpecificationImpl.java20
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/NativeCodeSpecificationImpl.java5
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateBuilder.java51
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateImpl.java6
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/VersionConstraintImpl.java25
12 files changed, 196 insertions, 48 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 7eb0e0827..dfb102ccd 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
@@ -16,6 +16,7 @@ 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;
+import org.osgi.framework.wiring.ResourceConstants;
/*
* A companion to BundleDescription from the state used while resolving.
@@ -62,7 +63,16 @@ public class ResolverBundle extends VersionSupplier implements Comparable<Resolv
imports = new ResolverImport[0];
requires = new BundleConstraint[0];
genericReqiures = new GenericConstraint[0];
- genericCapabilities = new GenericCapability[0];
+ GenericDescription[] capabilities = getBundleDescription().getGenericCapabilities();
+ GenericCapability identity = null;
+ for (GenericDescription capability : capabilities) {
+ if (ResourceConstants.IDENTITY_NAMESPACE.equals(capability.getType())) {
+ identity = new GenericCapability(this, capability);
+ break;
+ }
+ }
+
+ genericCapabilities = identity == null ? new GenericCapability[0] : new GenericCapability[] {identity};
return;
}
@@ -311,8 +321,6 @@ public class ResolverBundle extends VersionSupplier implements Comparable<Resolv
return; // do not allow fragments with conflicting constraints
if (isResolved() && newExports.length > 0)
fragment.setNewFragmentExports(true);
- if (isResolved() && newGenericCapabilities.length > 0)
- fragment.setNewFragmentCapabilities(true);
initFragments();
// need to make sure there is not already another version of this fragment
@@ -371,10 +379,16 @@ public class ResolverBundle extends VersionSupplier implements Comparable<Resolv
List<GenericCapability> hostCapabilities = new ArrayList<GenericCapability>(newGenericCapabilities.length);
if (newGenericCapabilities.length > 0 && dynamicAttach) {
for (GenericDescription capability : newGenericCapabilities) {
- GenericDescription hostCapabililty = new GenericDescriptionImpl(getBundleDescription(), capability);
- hostCapabilities.add(new GenericCapability(this, hostCapabililty));
+ if (!ResourceConstants.IDENTITY_NAMESPACE.equals(capability.getType())) {
+ GenericDescription hostCapabililty = new GenericDescriptionImpl(getBundleDescription(), capability);
+ hostCapabilities.add(new GenericCapability(this, hostCapabililty));
+ }
+ }
+ if (hostCapabilities.size() > 0) {
+ fragmentGenericCapabilities.put(fragment.bundleID, hostCapabilities);
+ if (isResolved())
+ fragment.setNewFragmentCapabilities(true);
}
- fragmentGenericCapabilities.put(fragment.bundleID, hostCapabilities);
}
if (dynamicAttach) {
resolver.getResolverExports().put(hostExports.toArray(new ResolverExport[hostExports.size()]));
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 defb5a28a..78123ebd0 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
@@ -1333,7 +1333,7 @@ public class ResolverImpl implements Resolver {
if (namespace == null)
capabilities = Collections.EMPTY_LIST;
else
- capabilities = name == null || "*".equals(name) ? namespace.getAllValues() : namespace.get(name); //$NON-NLS-1$
+ capabilities = name == null || name.indexOf('*') >= 0 ? namespace.getAllValues() : namespace.get(name);
List<GenericCapability> candidates = new ArrayList<GenericCapability>(capabilities);
List<BundleCapability> genCapabilities = new ArrayList<BundleCapability>(candidates.size());
// Must remove candidates that do not match before calling hooks.
@@ -1359,14 +1359,25 @@ public class ResolverImpl implements Resolver {
result = true; // Wired to ourselves
continue;
}
- ResolverBundle supplier = capability.getResolverBundle();
- // if in dev mode then allow a constraint to resolve to an unresolved bundle
- if (supplier.getState() == ResolverBundle.RESOLVED || (resolveBundle(supplier, cycle) || developmentMode)) {
- // Check cyclic dependencies
- if (supplier.getState() == ResolverBundle.RESOLVING)
- if (!cycle.contains(supplier))
- cycle.add(supplier);
- } else {
+ VersionSupplier[] capabilityHosts = capability.getResolverBundle().isFragment() ? capability.getResolverBundle().getHost().getPossibleSuppliers() : new ResolverBundle[] {capability.getResolverBundle()};
+ boolean foundResolvedMatch = false;
+ for (int i = 0; capabilityHosts != null && i < capabilityHosts.length; i++) {
+ ResolverBundle capabilitySupplier = capabilityHosts[i].getResolverBundle();
+ if (capabilitySupplier == constraint.getBundle()) {
+ // the capability is from a fragment attached to this host do not recursively resolve the host again
+ foundResolvedMatch = true;
+ continue;
+ }
+ // if in dev mode then allow a constraint to resolve to an unresolved bundle
+ if (capabilitySupplier.getState() == ResolverBundle.RESOLVED || (resolveBundle(capabilitySupplier, cycle) || developmentMode)) {
+ foundResolvedMatch |= !capability.getResolverBundle().isFragment() ? true : capability.getResolverBundle().getHost().getPossibleSuppliers() != null;
+ // Check cyclic dependencies
+ if (capabilitySupplier.getState() == ResolverBundle.RESOLVING)
+ if (!cycle.contains(capabilitySupplier))
+ cycle.add(capabilitySupplier);
+ }
+ }
+ if (!foundResolvedMatch) {
constraint.removePossibleSupplier(capability);
continue; // constraint hasn't resolved
}
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 fa47b2c99..471631850 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
@@ -156,5 +156,9 @@ public abstract class BaseDescriptionImpl implements BaseDescription {
public String toString() {
return getNamespace() + BaseDescriptionImpl.toString(getAttributes(), false) + BaseDescriptionImpl.toString(getDirectives(), true);
}
+
+ public BundleRevision getResource() {
+ return getRevision();
+ }
}
}
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 f2e4205ae..a83425a06 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
@@ -1031,6 +1031,14 @@ public final class BundleDescriptionImpl extends BaseDescriptionImpl implements
public String toString() {
return getRequirement() + " -> " + getCapability(); //$NON-NLS-1$
}
+
+ public BundleRevision getProvider() {
+ return provider.getRevision();
+ }
+
+ public BundleRevision getRequirer() {
+ return requirer.getRevision();
+ }
}
// Note that description wiring are identity equality based
@@ -1056,11 +1064,14 @@ public final class BundleDescriptionImpl extends BaseDescriptionImpl implements
public List<BundleCapability> getCapabilities(String namespace) {
if (!isInUse())
return null;
- @SuppressWarnings("unchecked")
- List<BundleCapability> result = Collections.EMPTY_LIST;
+ List<BundleCapability> result = new ArrayList<BundleCapability>();
+ GenericDescription[] genericCapabilities = getSelectedGenericCapabilities();
+ for (GenericDescription capabilitiy : genericCapabilities) {
+ if (namespace == null || namespace.equals(capabilitiy.getType()))
+ result.add(capabilitiy.getCapability());
+ }
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());
@@ -1074,11 +1085,6 @@ public final class BundleDescriptionImpl extends BaseDescriptionImpl implements
for (ExportPackageDescription exportPkg : exports)
result.add(exportPkg.getCapability());
}
- GenericDescription[] genericCapabilities = getSelectedGenericCapabilities();
- for (GenericDescription capabilitiy : genericCapabilities) {
- if (namespace == null || namespace.equals(capabilitiy.getType()))
- result.add(capabilitiy.getCapability());
- }
return result;
}
@@ -1093,7 +1099,8 @@ public final class BundleDescriptionImpl extends BaseDescriptionImpl implements
requirements.add(wire.getRequirement());
}
// get dynamic imports
- if (namespace == null || BundleRevision.PACKAGE_NAMESPACE.equals(namespace)) {
+ if (getHost() == null && (namespace == null || BundleRevision.PACKAGE_NAMESPACE.equals(namespace))) {
+ // TODO need to handle fragments that add dynamic imports
if (hasDynamicImports()) {
ImportPackageSpecification[] imports = getImportPackages();
for (ImportPackageSpecification impPackage : imports) {
@@ -1230,4 +1237,14 @@ public final class BundleDescriptionImpl extends BaseDescriptionImpl implements
return BundleDescriptionImpl.this.toString();
}
}
+
+ @SuppressWarnings({"cast", "unchecked", "rawtypes"})
+ public List<Capability> getCapabilities(String namespace) {
+ return (List<Capability>) (List) getDeclaredCapabilities(namespace);
+ }
+
+ @SuppressWarnings({"cast", "unchecked", "rawtypes"})
+ public List<Requirement> getRequirements(String namespace) {
+ return (List<Requirement>) (List) getDeclaredRequirements(namespace);
+ }
}
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 0e1577645..6946f4d7e 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
@@ -91,7 +91,17 @@ public class BundleSpecificationImpl extends VersionConstraintImpl implements Bu
}
}
String[] mandatory = (String[]) candidate.getDirective(Constants.MANDATORY_DIRECTIVE);
+ if (!hasMandatoryAttributes(mandatory))
+ return false;
+ if (getName() != null && getName().equals(candidate.getSymbolicName()) && (getVersionRange() == null || getVersionRange().isIncluded(candidate.getVersion())))
+ return true;
+ return false;
+ }
+
+ @Override
+ protected boolean hasMandatoryAttributes(String[] mandatory) {
if (mandatory != null) {
+ Map<String, ?> requiredAttrs = getAttributes();
for (String key : mandatory) {
if (Constants.BUNDLE_VERSION_ATTRIBUTE.equals(key))
continue; // has a default value of 0.0.0
@@ -99,9 +109,7 @@ public class BundleSpecificationImpl extends VersionConstraintImpl implements Bu
return false;
}
}
- if (getName() != null && getName().equals(candidate.getSymbolicName()) && (getVersionRange() == null || getVersionRange().isIncluded(candidate.getVersion())))
- return true;
- return false;
+ return true;
}
public String toString() {
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 296f70f79..617b4781d 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
@@ -57,6 +57,11 @@ public class GenericSpecificationImpl extends VersionConstraintImpl implements G
return matchingFilter == null || matchingFilter.match(candidate.getAttributes());
}
+ @Override
+ protected boolean hasMandatoryAttributes(String[] mandatory) {
+ return true;
+ }
+
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append(Constants.REQUIRE_CAPABILITY).append(": ").append(getType()); //$NON-NLS-1$
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 82b453716..2f6d77841 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
@@ -69,14 +69,8 @@ public class HostSpecificationImpl extends VersionConstraintImpl implements Host
}
}
String[] mandatory = (String[]) candidate.getDirective(Constants.MANDATORY_DIRECTIVE);
- if (mandatory != null) {
- for (String key : mandatory) {
- if (Constants.BUNDLE_VERSION_ATTRIBUTE.equals(key))
- continue; // has a default value of 0.0.0
- if (requiredAttrs == null || requiredAttrs.get(key) == null)
- return false;
- }
- }
+ if (!hasMandatoryAttributes(mandatory))
+ return false;
if (getName() != null && getName().equals(candidate.getSymbolicName()) && (getVersionRange() == null || getVersionRange().isIncluded(candidate.getVersion())))
return true;
return false;
@@ -88,6 +82,20 @@ public class HostSpecificationImpl extends VersionConstraintImpl implements Host
}
}
+ @Override
+ protected boolean hasMandatoryAttributes(String[] mandatory) {
+ if (mandatory != null) {
+ Map<String, ?> requiredAttrs = getAttributes();
+ for (String key : mandatory) {
+ if (Constants.BUNDLE_VERSION_ATTRIBUTE.equals(key))
+ continue; // has a default value of 0.0.0
+ if (requiredAttrs == null || requiredAttrs.get(key) == null)
+ return false;
+ }
+ }
+ return true;
+ }
+
public boolean isResolved() {
synchronized (this.monitor) {
return hosts != null && hosts.length > 0;
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 a1966c2a1..83a14b124 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
@@ -149,10 +149,22 @@ public class ImportPackageSpecificationImpl extends VersionConstraintImpl implem
}
}
String[] mandatory = (String[]) pkgDes.getDirective(Constants.MANDATORY_DIRECTIVE);
+ if (!hasMandatoryAttributes(mandatory))
+ return false;
+ // finally check the ee index
+ if (((BundleDescriptionImpl) getBundle()).getEquinoxEE() < 0)
+ return true;
+ int eeIndex = ((Integer) pkgDes.getDirective(ExportPackageDescriptionImpl.EQUINOX_EE)).intValue();
+ return eeIndex < 0 || eeIndex == ((BundleDescriptionImpl) getBundle()).getEquinoxEE();
+ }
+
+ @Override
+ protected boolean hasMandatoryAttributes(String[] mandatory) {
if (mandatory != null) {
+ Map<String, ?> importAttrs = getAttributes();
for (int i = 0; i < mandatory.length; i++) {
if (Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE.equals(mandatory[i])) {
- if (exporterSymbolicName == null)
+ if (getBundleSymbolicName() == null)
return false;
} else if (Constants.BUNDLE_VERSION_ATTRIBUTE.equals(mandatory[i])) {
if (bundleVersionRange == null)
@@ -168,11 +180,7 @@ public class ImportPackageSpecificationImpl extends VersionConstraintImpl implem
}
}
}
- // finally check the ee index
- if (((BundleDescriptionImpl) getBundle()).getEquinoxEE() < 0)
- return true;
- int eeIndex = ((Integer) pkgDes.getDirective(ExportPackageDescriptionImpl.EQUINOX_EE)).intValue();
- return eeIndex < 0 || eeIndex == ((BundleDescriptionImpl) getBundle()).getEquinoxEE();
+ return true;
}
protected void setBundleSymbolicName(String symbolicName) {
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 ee15b9edd..59d55d1d3 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
@@ -145,6 +145,11 @@ public class NativeCodeSpecificationImpl extends VersionConstraintImpl implement
return match;
}
+ @Override
+ protected boolean hasMandatoryAttributes(String[] mandatory) {
+ return true;
+ }
+
public String toString() {
StringBuffer sb = new StringBuffer();
NativeCodeDescription[] suppliers = getPossibleSuppliers();
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 db90b9dda..577c97e85 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
@@ -19,6 +19,7 @@ import org.eclipse.osgi.service.resolver.*;
import org.eclipse.osgi.util.ManifestElement;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.*;
+import org.osgi.framework.wiring.ResourceConstants;
/**
* This class builds bundle description objects from manifests
@@ -118,7 +119,7 @@ public class StateBuilder {
result.setGenericRequires(createGenericRequires(genericRequires, osgiRequires));
ManifestElement[] genericCapabilities = getGenericCapabilities(manifest, genericAliases);
ManifestElement[] osgiCapabilities = ManifestElement.parseHeader(Constants.PROVIDE_CAPABILITY, manifest.get(Constants.PROVIDE_CAPABILITY));
- result.setGenericCapabilities(createGenericCapabilities(genericCapabilities, osgiCapabilities));
+ result.setGenericCapabilities(createGenericCapabilities(genericCapabilities, osgiCapabilities, result));
ManifestElement[] nativeCode = ManifestElement.parseHeader(Constants.BUNDLE_NATIVECODE, manifest.get(Constants.BUNDLE_NATIVECODE));
result.setNativeCodeSpecification(createNativeCode(nativeCode));
return result;
@@ -554,13 +555,24 @@ public class StateBuilder {
return results;
}
- private static GenericDescription[] createGenericCapabilities(ManifestElement[] equinoxCapabilities, ManifestElement[] osgiCapabilities) {
+ private static GenericDescription[] createGenericCapabilities(ManifestElement[] equinoxCapabilities, ManifestElement[] osgiCapabilities, BundleDescription description) throws BundleException {
List<GenericDescription> result = createEquinoxCapabilities(equinoxCapabilities);
- result = createOSGiCapabilities(osgiCapabilities, result);
+ result = createOSGiCapabilities(osgiCapabilities, result, description);
return result == null ? null : result.toArray(new GenericDescription[result.size()]);
}
- static List<GenericDescription> createOSGiCapabilities(ManifestElement[] osgiCapabilities, List<GenericDescription> result) {
+ private static List<GenericDescription> createOSGiCapabilities(ManifestElement[] osgiCapabilities, List<GenericDescription> result, BundleDescription description) throws BundleException {
+ if (result == null)
+ result = new ArrayList<GenericDescription>(osgiCapabilities == null ? 1 : osgiCapabilities.length + 1);
+ // Always have an osgi.identity capability if there is a symbolic name.
+ GenericDescription osgiIdentity = createOsgiIdentityCapability(description);
+ if (osgiIdentity != null)
+ // always add the capability to the front
+ result.add(0, osgiIdentity);
+ return createOSGiCapabilities(osgiCapabilities, result);
+ }
+
+ static List<GenericDescription> createOSGiCapabilities(ManifestElement[] osgiCapabilities, List<GenericDescription> result) throws BundleException {
if (osgiCapabilities == null)
return result;
if (result == null)
@@ -570,8 +582,12 @@ public class StateBuilder {
String[] namespaces = element.getValueComponents();
types: for (String namespace : namespaces) {
String effective = element.getDirective(Constants.EFFECTIVE_DIRECTIVE);
+ // Any declared osgi.identity capability with an effective directive value of "resolve" will be overridden.
if (effective != null && !Constants.EFFECTIVE_RESOLVE.equals(effective))
break types; // ignore any namespace that is not effective at resolve time.
+ if (ResourceConstants.IDENTITY_NAMESPACE.equals(namespace))
+ throw new BundleException("A bundle is not allowed to define a capability in the " + ResourceConstants.IDENTITY_NAMESPACE + " name space."); //$NON-NLS-1$ //$NON-NLS-2$
+
GenericDescriptionImpl desc = new GenericDescriptionImpl();
desc.setType(namespace);
Map<String, Object> mapAttrs = getAttributes(element, new String[0]);
@@ -591,7 +607,7 @@ public class StateBuilder {
return result;
}
- private static List<GenericDescription> createEquinoxCapabilities(ManifestElement[] equinoxCapabilities) {
+ private static List<GenericDescription> createEquinoxCapabilities(ManifestElement[] equinoxCapabilities) throws BundleException {
if (equinoxCapabilities == null)
return null;
ArrayList<GenericDescription> results = new ArrayList<GenericDescription>(equinoxCapabilities.length);
@@ -604,6 +620,8 @@ public class StateBuilder {
if (colonIdx > 0) {
name = genericNames[j].substring(0, colonIdx);
desc.setType(genericNames[j].substring(colonIdx + 1));
+ if (ResourceConstants.IDENTITY_NAMESPACE.equals(desc.getType()))
+ throw new BundleException("A bundle is not allowed to define a capability in the " + ResourceConstants.IDENTITY_NAMESPACE + " name space."); //$NON-NLS-1$ //$NON-NLS-2$
}
Map<String, Object> mapAttrs = getAttributes(equinoxCapabilities[i], new String[] {Constants.VERSION_ATTRIBUTE});
Dictionary<String, Object> attrs = mapAttrs == null ? new Hashtable<String, Object>() : new Hashtable<String, Object>(mapAttrs);
@@ -748,4 +766,27 @@ public class StateBuilder {
throw new BundleException(message + " : " + NLS.bind(StateMsg.HEADER_EXTENSION_ERROR, hostName), BundleException.MANIFEST_ERROR); //$NON-NLS-1$
}
}
+
+ private static GenericDescription createOsgiIdentityCapability(BundleDescription description) {
+ if (description.getSymbolicName() == null)
+ return null;
+ GenericDescriptionImpl result = new GenericDescriptionImpl();
+ result.setType(ResourceConstants.IDENTITY_NAMESPACE);
+ Dictionary<String, Object> attributes = new Hashtable<String, Object>(description.getDeclaredAttributes());
+ // remove osgi.wiring.bundle and bundle-version attributes
+ attributes.remove(ResourceConstants.WIRING_BUNDLE_NAMESPACE);
+ attributes.remove(Constants.BUNDLE_VERSION_ATTRIBUTE);
+ attributes.put(ResourceConstants.IDENTITY_NAMESPACE, description.getSymbolicName());
+ attributes.put(ResourceConstants.IDENTITY_TYPE_ATTRIBUTE, description.getHost() == null ? ResourceConstants.IDENTITY_TYPE_BUNDLE : ResourceConstants.IDENTITY_TYPE_FRAGMENT);
+ attributes.put(ResourceConstants.IDENTITY_VERSION_ATTRIBUTE, description.getVersion());
+ result.setAttributes(attributes);
+ Map<String, String> directives = new HashMap<String, String>(description.getDeclaredDirectives());
+ // remove defaults directive values
+ if (!description.isSingleton())
+ directives.remove(Constants.SINGLETON_DIRECTIVE);
+ if (description.attachFragments() && description.dynamicFragments())
+ directives.remove(Constants.FRAGMENT_ATTACHMENT_DIRECTIVE);
+ result.setDirectives(directives);
+ return result;
+ }
}
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 6f7b4d2e5..aa8d9cbf5 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
@@ -871,7 +871,11 @@ public abstract class StateImpl implements State {
}
private void addSystemCapabilities(List<GenericDescription> capabilities, ManifestElement[] elements) {
- StateBuilder.createOSGiCapabilities(elements, capabilities);
+ try {
+ StateBuilder.createOSGiCapabilities(elements, capabilities);
+ } catch (BundleException e) {
+ throw new RuntimeException("Unexpected exception adding system capabilities.", e); //$NON-NLS-1$
+ }
}
@SuppressWarnings("rawtypes")
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 5a60207f1..716d86c79 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
@@ -17,7 +17,8 @@ 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.Version;
+import org.eclipse.osgi.util.ManifestElement;
+import org.osgi.framework.*;
import org.osgi.framework.wiring.*;
abstract class VersionConstraintImpl implements VersionConstraint {
@@ -101,6 +102,8 @@ abstract class VersionConstraintImpl implements VersionConstraint {
protected abstract Map<String, Object> getInteralAttributes();
+ protected abstract boolean hasMandatoryAttributes(String[] mandatory);
+
public BundleRequirement getRequirement() {
String namespace = getInternalNameSpace();
if (namespace == null)
@@ -156,6 +159,26 @@ abstract class VersionConstraintImpl implements VersionConstraint {
public String toString() {
return getNamespace() + BaseDescriptionImpl.toString(getAttributes(), false) + BaseDescriptionImpl.toString(getDirectives(), true);
}
+
+ public boolean matches(Capability capability) {
+ if (capability instanceof BundleCapability)
+ return matches((BundleCapability) capability);
+ // now we must do the generic thing
+ if (!namespace.equals(capability.getNamespace()))
+ return false;
+ String filterSpec = getDirectives().get(ResourceConstants.REQUIREMENT_FILTER_DIRECTIVE);
+ try {
+ if (filterSpec != null && !FrameworkUtil.createFilter(filterSpec).matches(capability.getAttributes()))
+ return false;
+ } catch (InvalidSyntaxException e) {
+ return false;
+ }
+ return hasMandatoryAttributes(ManifestElement.getArrayFromList(capability.getDirectives().get(ResourceConstants.CAPABILITY_MANDATORY_DIRECTIVE)));
+ }
+
+ public BundleRevision getResource() {
+ return getRevision();
+ }
}
static StringBuffer addFilterAttributes(StringBuffer filter, Map<String, ?> attributes) {

Back to the top