use of org.eclipse.osgi.service.resolver.ExportPackageDescription in project rt.equinox.framework by eclipse.
the class ResolverImpl method stateResolveBundle.
private void stateResolveBundle(ResolverBundle rb) {
// if in dev mode then we want to tell the state about the constraints we were able to resolve
if (!rb.isResolved() && !developmentMode)
return;
if (rb.isFragment())
stateResolveFragConstraints(rb);
else
stateResolveConstraints(rb);
// Build up the state wires
Map<String, List<StateWire>> stateWires = new HashMap<>();
// Gather selected exports
ResolverExport[] exports = rb.getSelectedExports();
List<ExportPackageDescription> selectedExports = new ArrayList<>(exports.length);
for (int i = 0; i < exports.length; i++) {
if (permissionChecker.checkPackagePermission(exports[i].getExportPackageDescription()))
selectedExports.add(exports[i].getExportPackageDescription());
}
ExportPackageDescription[] selectedExportsArray = selectedExports.toArray(new ExportPackageDescription[selectedExports.size()]);
// Gather substitute exports
ResolverExport[] substituted = rb.getSubstitutedExports();
List<ExportPackageDescription> substitutedExports = new ArrayList<>(substituted.length);
for (int i = 0; i < substituted.length; i++) {
substitutedExports.add(substituted[i].getExportPackageDescription());
}
ExportPackageDescription[] substitutedExportsArray = substitutedExports.toArray(new ExportPackageDescription[substitutedExports.size()]);
// Gather exports that have been wired to
ExportPackageDescription[] exportsWiredToArray = getExportsWiredTo(rb, stateWires);
// Gather bundles that have been wired to
BundleConstraint[] requires = rb.getRequires();
List<BundleDescription> bundlesWiredTo = new ArrayList<>(requires.length);
List<StateWire> requireWires = new ArrayList<>(requires.length);
for (int i = 0; i < requires.length; i++) 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<>(capabilities.length);
for (GenericCapability capability : capabilities) if (capability.isEffective() && permissionChecker.checkCapabilityPermission(capability.getGenericDescription()))
selectedCapabilities.add(capability.getGenericDescription());
GenericDescription[] selectedCapabilitiesArray = selectedCapabilities.toArray(new GenericDescription[selectedCapabilities.size()]);
GenericConstraint[] genericRequires = rb.getGenericRequires();
List<GenericDescription> resolvedGenericRequires = new ArrayList<>(genericRequires.length);
for (GenericConstraint genericConstraint : genericRequires) {
VersionSupplier[] matching = genericConstraint.getMatchingCapabilities();
if (matching != null)
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<>();
stateWires.put(genericConstraint.getNameSpace(), genericWires);
}
genericWires.add(genericWire);
}
}
GenericDescription[] capabilitiesWiredToArray = resolvedGenericRequires.toArray(new GenericDescription[resolvedGenericRequires.size()]);
BundleDescription[] hostBundles = null;
if (rb.isFragment()) {
VersionSupplier[] matchingBundles = rb.getHost().getPossibleSuppliers();
if (matchingBundles != null && matchingBundles.length > 0) {
hostBundles = new BundleDescription[matchingBundles.length];
List<StateWire> hostWires = new ArrayList<>(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;
if (rb.isNewFragmentExports()) {
// update the host's set of selected exports
ResolverExport[] hostExports = ((ResolverBundle) matchingBundles[i]).getSelectedExports();
newSelectedExports = new ExportPackageDescription[hostExports.length];
for (int j = 0; j < hostExports.length; j++) newSelectedExports[j] = hostExports[j].getExportPackageDescription();
}
if (rb.isNewFragmentCapabilities()) {
// update the host's set of selected capabilities
GenericCapability[] hostCapabilities = ((ResolverBundle) matchingBundles[i]).getGenericCapabilities();
newSelectedCapabilities = new GenericDescription[hostCapabilities.length];
for (int j = 0; j < hostCapabilities.length; j++) newSelectedCapabilities[j] = hostCapabilities[j].getGenericDescription();
}
if (newSelectedCapabilities != null || newSelectedExports != null) {
if (newSelectedCapabilities == null)
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(), ((BundleDescriptionImpl) hostBundles[i]).getWires());
}
}
}
}
}
// Resolve the bundle in the state
state.resolveBundle(rb.getBundleDescription(), rb.isResolved(), hostBundles, selectedExportsArray, substitutedExportsArray, selectedCapabilitiesArray, bundlesWiredToArray, exportsWiredToArray, capabilitiesWiredToArray, stateWires);
}
use of org.eclipse.osgi.service.resolver.ExportPackageDescription in project rt.equinox.framework by eclipse.
the class ResolverImpl method resolveDynamicImport.
// Resolve dynamic import
public synchronized ExportPackageDescription resolveDynamicImport(BundleDescription importingBundle, String requestedPackage) {
if (state == null)
// $NON-NLS-1$
throw new IllegalStateException("RESOLVER_NO_STATE");
// Make sure the resolver is initialized
if (!initialized)
initialize();
hook = (state instanceof StateImpl) ? ((StateImpl) state).getResolverHook() : null;
try {
ResolverBundle rb = bundleMapping.get(importingBundle);
if (rb.getExport(requestedPackage) != null)
// do not allow dynamic wires for packages which this bundle exports
return null;
ResolverImport[] resolverImports = rb.getImportPackages();
// If there is a matching one then pass it into resolveImport()
for (int j = 0; j < resolverImports.length; j++) {
// Make sure it is a dynamic import
if (!resolverImports[j].isDynamic())
continue;
// Resolve the import
ExportPackageDescription supplier = resolveDynamicImport(resolverImports[j], requestedPackage);
if (supplier != null)
return supplier;
}
// look for packages added dynamically
ImportPackageSpecification[] addedDynamicImports = importingBundle.getAddedDynamicImportPackages();
for (ImportPackageSpecification addedDynamicImport : addedDynamicImports) {
ResolverImport newImport = new ResolverImport(rb, addedDynamicImport);
ExportPackageDescription supplier = resolveDynamicImport(newImport, requestedPackage);
if (supplier != null)
return supplier;
}
if (DEBUG || DEBUG_IMPORTS)
// $NON-NLS-1$
ResolverImpl.log("Failed to resolve dynamic import: " + requestedPackage);
// Couldn't resolve the import, so return null
return null;
} finally {
hook = null;
}
}
use of org.eclipse.osgi.service.resolver.ExportPackageDescription in project tycho by eclipse.
the class DependencyComputer method addHostPlugin.
private void addHostPlugin(HostSpecification hostSpec, HashSet<BundleDescription> added, Map<BundleDescription, ArrayList<AccessRule>> map, ArrayList<DependencyEntry> entries) {
BaseDescription desc = hostSpec.getSupplier();
if (desc instanceof BundleDescription) {
BundleDescription host = (BundleDescription) desc;
// add host plug-in
if (added.add(host) && addPlugin(host, false, map, entries)) {
BundleSpecification[] required = host.getRequiredBundles();
for (int i = 0; i < required.length; i++) {
addDependency((BundleDescription) required[i].getSupplier(), added, map, entries);
}
// add Import-Package
ImportPackageSpecification[] imports = host.getImportPackages();
for (int i = 0; i < imports.length; i++) {
BaseDescription supplier = imports[i].getSupplier();
if (supplier instanceof ExportPackageDescription) {
addDependencyViaImportPackage(((ExportPackageDescription) supplier).getExporter(), added, map, entries);
}
}
}
}
}
use of org.eclipse.osgi.service.resolver.ExportPackageDescription in project rt.equinox.framework by eclipse.
the class StateResolverTest method testMultipleExportsUses01.
public void testMultipleExportsUses01() throws BundleException {
State state = buildEmptyState();
Hashtable manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "A1");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.EXPORT_PACKAGE, "a; version=2.0; uses:=d, d; version=2.0");
// $NON-NLS-1$
BundleDescription a1_100 = state.getFactory().createBundleDescription(state, manifest, "a1_100", 0);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "A2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.EXPORT_PACKAGE, "a; version=1.0; uses:=d, d; version=1.0");
// $NON-NLS-1$
BundleDescription a2_100 = state.getFactory().createBundleDescription(state, manifest, "a2_100", 1);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "B1");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.EXPORT_PACKAGE, "b, b; mandatory:=\"test\"; test=value; uses:=d");
// $NON-NLS-1$
manifest.put(Constants.IMPORT_PACKAGE, "a;bundle-symbolic-name=A2, d");
// $NON-NLS-1$
BundleDescription b1_100 = state.getFactory().createBundleDescription(state, manifest, "b1_100", 2);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "C1");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.EXPORT_PACKAGE, "c; uses:=b");
// $NON-NLS-1$
manifest.put(Constants.IMPORT_PACKAGE, "b; test=value, d");
// $NON-NLS-1$
BundleDescription c1_100 = state.getFactory().createBundleDescription(state, manifest, "c1_100", 3);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "D1");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.IMPORT_PACKAGE, "a, c, d");
// $NON-NLS-1$
BundleDescription d1_100 = state.getFactory().createBundleDescription(state, manifest, "d1_100", 4);
state.addBundle(a1_100);
state.addBundle(a2_100);
state.addBundle(b1_100);
state.addBundle(c1_100);
state.addBundle(d1_100);
state.resolve();
ExportPackageDescription[] b1ResolvedImports = b1_100.getResolvedImports();
ExportPackageDescription[] d1ResolvedImports = d1_100.getResolvedImports();
ExportPackageDescription[] isConsistent = isConsistent(b1ResolvedImports, d1ResolvedImports);
// $NON-NLS-1$
assertNull("1.1 Packages are not consistent: " + isConsistent, isConsistent);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "B1");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.EXPORT_PACKAGE, "b; uses:=a");
// $NON-NLS-1$
manifest.put(Constants.IMPORT_PACKAGE, "a;bundle-symbolic-name=A1");
// $NON-NLS-1$
b1_100 = state.getFactory().createBundleDescription(state, manifest, "b1_100", 2);
state.updateBundle(b1_100);
state.resolve();
b1ResolvedImports = b1_100.getResolvedImports();
d1ResolvedImports = d1_100.getResolvedImports();
isConsistent = isConsistent(b1ResolvedImports, d1ResolvedImports);
// $NON-NLS-1$
assertNull("1.2 Packages are not consistent: " + isConsistent, isConsistent);
}
use of org.eclipse.osgi.service.resolver.ExportPackageDescription in project rt.equinox.framework by eclipse.
the class StateResolverTest method testFragmentConstraints06.
public void testFragmentConstraints06() throws BundleException {
int id = 0;
State state = buildEmptyState();
Hashtable manifest = new Hashtable();
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "a");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.IMPORT_PACKAGE, "a");
// $NON-NLS-1$
manifest.put(Constants.REQUIRE_BUNDLE, "b");
// $NON-NLS-1$
BundleDescription a = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "aFrag1");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.FRAGMENT_HOST, "a");
// $NON-NLS-1$
manifest.put(Constants.IMPORT_PACKAGE, "b, c, d");
// $NON-NLS-1$
manifest.put(Constants.REQUIRE_BUNDLE, "c, d, e");
// $NON-NLS-1$
BundleDescription aFrag1 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "aFrag2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.FRAGMENT_HOST, "a");
// $NON-NLS-1$
manifest.put(Constants.IMPORT_PACKAGE, "b, c, e");
// $NON-NLS-1$
manifest.put(Constants.REQUIRE_BUNDLE, "c, d, f");
// $NON-NLS-1$
BundleDescription aFrag2 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "aFrag3");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.FRAGMENT_HOST, "a");
// $NON-NLS-1$
manifest.put(Constants.IMPORT_PACKAGE, "b, c");
// $NON-NLS-1$
manifest.put(Constants.REQUIRE_BUNDLE, "c, d");
// $NON-NLS-1$
BundleDescription aFrag3 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "b");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.EXPORT_PACKAGE, "a, b, c");
// $NON-NLS-1$
BundleDescription b = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "c");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.EXPORT_PACKAGE, "c1, c2, c3");
// $NON-NLS-1$
BundleDescription c = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "d");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.EXPORT_PACKAGE, "d1, d2, d3");
// $NON-NLS-1$
BundleDescription d = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
state.addBundle(a);
state.addBundle(aFrag1);
state.addBundle(aFrag2);
state.addBundle(aFrag3);
state.addBundle(b);
state.addBundle(c);
state.addBundle(d);
state.resolve();
// $NON-NLS-1$
assertTrue("0.1", a.isResolved());
// $NON-NLS-1$
assertFalse("0.2", aFrag1.isResolved());
// $NON-NLS-1$
assertFalse("0.3", aFrag2.isResolved());
// $NON-NLS-1$
assertTrue("0.4", aFrag3.isResolved());
// $NON-NLS-1$
assertTrue("0.5", b.isResolved());
// $NON-NLS-1$
assertTrue("0.6", c.isResolved());
// $NON-NLS-1$
assertTrue("0.7", d.isResolved());
ExportPackageDescription[] aResolvedImports = a.getResolvedImports();
ExportPackageDescription[] bSelectedExports = b.getSelectedExports();
// $NON-NLS-1$
assertEquals("1.0", 3, aResolvedImports.length);
// $NON-NLS-1$
assertEquals("1.1", 3, bSelectedExports.length);
for (int i = 0; i < aResolvedImports.length; i++) {
assertEquals(bSelectedExports[i], aResolvedImports[i]);
}
BundleDescription[] aResolvedRequires = a.getResolvedRequires();
// $NON-NLS-1$
assertEquals("1.0", 3, aResolvedRequires.length);
// $NON-NLS-1$
assertEquals("1.1", b, aResolvedRequires[0]);
// $NON-NLS-1$
assertEquals("1.2", c, aResolvedRequires[1]);
// $NON-NLS-1$
assertEquals("1.3", d, aResolvedRequires[2]);
}
Aggregations