use of org.eclipse.osgi.service.resolver.StateWire in project rt.equinox.framework by eclipse.
the class ResolverImpl method getExportsWiredTo.
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<>(imports.length);
List<StateWire> importWires = new ArrayList<>(imports.length);
for (int i = 0; i < imports.length; i++) 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()]);
}
use of org.eclipse.osgi.service.resolver.StateWire 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.StateWire in project rt.equinox.framework by eclipse.
the class ResolverImpl method newStateWire.
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);
}
Aggregations