Search in sources :

Example 1 with GenericDescription

use of org.eclipse.osgi.service.resolver.GenericDescription in project rt.equinox.framework by eclipse.

the class ResolverBundle method initialize.

void initialize(boolean useSelectedExports) {
    if (getBundleDescription().getHost() != null) {
        host = new BundleConstraint(this, getBundleDescription().getHost());
        exports = new ResolverExport[0];
        imports = new ResolverImport[0];
        requires = new BundleConstraint[0];
        GenericSpecification[] requirements = getBundleDescription().getGenericRequires();
        List<GenericConstraint> constraints = new ArrayList<>();
        for (GenericSpecification requirement : requirements) {
            if (StateImpl.OSGI_EE_NAMESPACE.equals(requirement.getType())) {
                constraints.add(new GenericConstraint(this, requirement, resolver.isDevelopmentMode()));
            }
        }
        genericReqiures = constraints.toArray(new GenericConstraint[constraints.size()]);
        GenericDescription[] capabilities = getBundleDescription().getGenericCapabilities();
        GenericCapability identity = null;
        for (GenericDescription capability : capabilities) {
            if (IdentityNamespace.IDENTITY_NAMESPACE.equals(capability.getType())) {
                identity = new GenericCapability(this, capability, resolver.isDevelopmentMode());
                break;
            }
        }
        genericCapabilities = identity == null ? new GenericCapability[0] : new GenericCapability[] { identity };
        return;
    }
    ImportPackageSpecification[] actualImports = getBundleDescription().getImportPackages();
    // Reorder imports so that optionals are at the end so that we wire statics before optionals
    List<ResolverImport> importList = new ArrayList<>(actualImports.length);
    for (int i = actualImports.length - 1; i >= 0; i--) if (ImportPackageSpecification.RESOLUTION_OPTIONAL.equals(actualImports[i].getDirective(Constants.RESOLUTION_DIRECTIVE)))
        importList.add(new ResolverImport(this, actualImports[i]));
    else
        importList.add(0, new ResolverImport(this, actualImports[i]));
    imports = importList.toArray(new ResolverImport[importList.size()]);
    ExportPackageDescription[] actualExports = useSelectedExports ? getBundleDescription().getSelectedExports() : getBundleDescription().getExportPackages();
    exports = new ResolverExport[actualExports.length];
    for (int i = 0; i < actualExports.length; i++) exports[i] = new ResolverExport(this, actualExports[i]);
    BundleSpecification[] actualRequires = getBundleDescription().getRequiredBundles();
    requires = new BundleConstraint[actualRequires.length];
    for (int i = 0; i < requires.length; i++) requires[i] = new BundleConstraint(this, actualRequires[i]);
    GenericSpecification[] actualGenericRequires = getBundleDescription().getGenericRequires();
    genericReqiures = new GenericConstraint[actualGenericRequires.length];
    for (int i = 0; i < genericReqiures.length; i++) {
        genericReqiures[i] = new GenericConstraint(this, actualGenericRequires[i], resolver.isDevelopmentMode());
    }
    GenericDescription[] actualCapabilities = useSelectedExports ? getBundleDescription().getSelectedGenericCapabilities() : getBundleDescription().getGenericCapabilities();
    genericCapabilities = new GenericCapability[actualCapabilities.length];
    for (int i = 0; i < genericCapabilities.length; i++) {
        genericCapabilities[i] = new GenericCapability(this, actualCapabilities[i], resolver.isDevelopmentMode());
    }
    fragments = null;
    fragmentExports = null;
    fragmentImports = null;
    fragmentRequires = null;
    fragmentGenericCapabilities = null;
    fragmentGenericRequires = null;
}
Also used : ExportPackageDescription(org.eclipse.osgi.service.resolver.ExportPackageDescription) ArrayList(java.util.ArrayList) GenericDescription(org.eclipse.osgi.service.resolver.GenericDescription) BundleSpecification(org.eclipse.osgi.service.resolver.BundleSpecification) VersionConstraint(org.eclipse.osgi.service.resolver.VersionConstraint) ImportPackageSpecification(org.eclipse.osgi.service.resolver.ImportPackageSpecification) GenericSpecification(org.eclipse.osgi.service.resolver.GenericSpecification)

Example 2 with GenericDescription

use of org.eclipse.osgi.service.resolver.GenericDescription 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);
}
Also used : HashMap(java.util.HashMap) ExportPackageDescription(org.eclipse.osgi.service.resolver.ExportPackageDescription) ArrayList(java.util.ArrayList) StateWire(org.eclipse.osgi.service.resolver.StateWire) GenericDescription(org.eclipse.osgi.service.resolver.GenericDescription) ArrayList(java.util.ArrayList) List(java.util.List) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) VersionConstraint(org.eclipse.osgi.service.resolver.VersionConstraint)

Example 3 with GenericDescription

use of org.eclipse.osgi.service.resolver.GenericDescription in project rt.equinox.framework by eclipse.

the class StateBuilder method createEquinoxCapabilities.

private static List<GenericDescription> createEquinoxCapabilities(ManifestElement[] equinoxCapabilities) throws BundleException {
    if (equinoxCapabilities == null)
        return null;
    ArrayList<GenericDescription> results = new ArrayList<>(equinoxCapabilities.length);
    for (int i = 0; i < equinoxCapabilities.length; i++) {
        String[] genericNames = equinoxCapabilities[i].getValueComponents();
        for (int j = 0; j < genericNames.length; j++) {
            GenericDescriptionImpl desc = new GenericDescriptionImpl();
            String name = genericNames[j];
            int colonIdx = genericNames[j].indexOf(':');
            if (colonIdx > 0) {
                name = genericNames[j].substring(0, colonIdx);
                desc.setType(genericNames[j].substring(colonIdx + 1));
                if (IdentityNamespace.IDENTITY_NAMESPACE.equals(desc.getType()))
                    // $NON-NLS-1$ //$NON-NLS-2$
                    throw new BundleException("A bundle is not allowed to define a capability in the " + IdentityNamespace.IDENTITY_NAMESPACE + " name space.");
            }
            Map<String, Object> mapAttrs = getAttributes(equinoxCapabilities[i], new String[] { Constants.VERSION_ATTRIBUTE });
            Dictionary<String, Object> attrs = mapAttrs == null ? new Hashtable<String, Object>() : new Hashtable<>(mapAttrs);
            attrs.put(desc.getType(), name);
            String versionString = equinoxCapabilities[i].getAttribute(Constants.VERSION_ATTRIBUTE);
            if (versionString != null)
                attrs.put(Constants.VERSION_ATTRIBUTE, Version.parseVersion(versionString));
            desc.setAttributes(attrs);
            results.add(desc);
        }
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) GenericDescription(org.eclipse.osgi.service.resolver.GenericDescription) BundleException(org.osgi.framework.BundleException)

Example 4 with GenericDescription

use of org.eclipse.osgi.service.resolver.GenericDescription in project rt.equinox.framework by eclipse.

the class ResolverBundle method attachFragment.

void attachFragment(ResolverBundle fragment, boolean dynamicAttach) {
    if (isFragment())
        // cannot attach to fragments;
        return;
    if (!getBundleDescription().attachFragments() || (isResolved() && !getBundleDescription().dynamicFragments()))
        // host is restricting attachment
        return;
    if (fragment.getHost().getNumPossibleSuppliers() > 0 && !((HostSpecification) fragment.getHost().getVersionConstraint()).isMultiHost())
        // fragment is restricting attachment
        return;
    ImportPackageSpecification[] newImports = fragment.getBundleDescription().getImportPackages();
    BundleSpecification[] newRequires = fragment.getBundleDescription().getRequiredBundles();
    ExportPackageDescription[] newExports = fragment.getBundleDescription().getExportPackages();
    GenericDescription[] newGenericCapabilities = fragment.getBundleDescription().getGenericCapabilities();
    GenericSpecification[] newGenericRequires = fragment.getBundleDescription().getGenericRequires();
    // if this is not during initialization then check if constraints conflict
    if (dynamicAttach && constraintsConflict(fragment.getBundleDescription(), newImports, newRequires, newGenericRequires))
        // do not allow fragments with conflicting constraints
        return;
    if (isResolved() && newExports.length > 0)
        fragment.setNewFragmentExports(true);
    initFragments();
    // already attached to this host
    for (Iterator<ResolverBundle> iFragments = fragments.iterator(); iFragments.hasNext(); ) {
        ResolverBundle existingFragment = iFragments.next();
        String bsn = existingFragment.getName();
        if (bsn != null && bsn.equals(fragment.getName()))
            return;
    }
    if (fragments.contains(fragment))
        return;
    fragments.add(fragment);
    fragment.getHost().addPossibleSupplier(this);
    if (newImports.length > 0) {
        ArrayList<ResolverImport> hostImports = new ArrayList<>(newImports.length);
        for (int i = 0; i < newImports.length; i++) if (!isImported(newImports[i].getName()))
            hostImports.add(new ResolverImport(this, newImports[i]));
        fragmentImports.put(fragment.bundleID, hostImports);
    }
    if (newRequires.length > 0) {
        ArrayList<BundleConstraint> hostRequires = new ArrayList<>(newRequires.length);
        for (int i = 0; i < newRequires.length; i++) if (!isRequired(newRequires[i].getName()))
            hostRequires.add(new BundleConstraint(this, newRequires[i]));
        fragmentRequires.put(fragment.bundleID, hostRequires);
    }
    if (newGenericRequires.length > 0) {
        ArrayList<GenericConstraint> hostGenericRequires = new ArrayList<>(newGenericRequires.length);
        for (int i = 0; i < newGenericRequires.length; i++) {
            // only add namespaces that are not osgi.ee
            if (!StateImpl.OSGI_EE_NAMESPACE.equals(newGenericRequires[i].getType())) {
                hostGenericRequires.add(new GenericConstraint(this, newGenericRequires[i], resolver.isDevelopmentMode()));
            }
        }
        if (!hostGenericRequires.isEmpty())
            fragmentGenericRequires.put(fragment.bundleID, hostGenericRequires);
    }
    ArrayList<ResolverExport> hostExports = new ArrayList<>(newExports.length);
    if (newExports.length > 0 && dynamicAttach) {
        for (int i = 0; i < newExports.length; i++) {
            ResolverExport[] currentExports = getExports(newExports[i].getName());
            boolean foundEquivalent = false;
            for (int j = 0; j < currentExports.length && !foundEquivalent; j++) {
                if (equivalentExports(currentExports[j], newExports[i]))
                    foundEquivalent = true;
            }
            if (!foundEquivalent) {
                ExportPackageDescription hostExport = new ExportPackageDescriptionImpl(getBundleDescription(), newExports[i]);
                hostExports.add(new ResolverExport(this, hostExport));
            }
        }
        fragmentExports.put(fragment.bundleID, hostExports);
    }
    List<GenericCapability> hostCapabilities = new ArrayList<>(newGenericCapabilities.length);
    if (newGenericCapabilities.length > 0 && dynamicAttach) {
        for (GenericDescription capability : newGenericCapabilities) {
            if (!IdentityNamespace.IDENTITY_NAMESPACE.equals(capability.getType())) {
                GenericDescription hostCapabililty = new GenericDescriptionImpl(getBundleDescription(), capability);
                hostCapabilities.add(new GenericCapability(this, hostCapabililty, resolver.isDevelopmentMode()));
            }
        }
        if (hostCapabilities.size() > 0) {
            fragmentGenericCapabilities.put(fragment.bundleID, hostCapabilities);
            if (isResolved())
                fragment.setNewFragmentCapabilities(true);
        }
    }
    if (dynamicAttach) {
        resolver.getResolverExports().put(hostExports.toArray(new ResolverExport[hostExports.size()]));
        resolver.addGenerics(hostCapabilities.toArray(new GenericCapability[hostCapabilities.size()]));
    }
}
Also used : HostSpecification(org.eclipse.osgi.service.resolver.HostSpecification) ExportPackageDescription(org.eclipse.osgi.service.resolver.ExportPackageDescription) ArrayList(java.util.ArrayList) GenericDescription(org.eclipse.osgi.service.resolver.GenericDescription) GenericDescriptionImpl(org.eclipse.osgi.internal.resolver.GenericDescriptionImpl) ExportPackageDescriptionImpl(org.eclipse.osgi.internal.resolver.ExportPackageDescriptionImpl) GenericSpecification(org.eclipse.osgi.service.resolver.GenericSpecification) BundleSpecification(org.eclipse.osgi.service.resolver.BundleSpecification) VersionConstraint(org.eclipse.osgi.service.resolver.VersionConstraint) ImportPackageSpecification(org.eclipse.osgi.service.resolver.ImportPackageSpecification)

Example 5 with GenericDescription

use of org.eclipse.osgi.service.resolver.GenericDescription in project rt.equinox.framework by eclipse.

the class ResolverImpl method rewireGeneric.

private void rewireGeneric(GenericConstraint constraint, List<ResolverBundle> visited) {
    if (constraint.getSelectedSupplier() != null)
        return;
    GenericDescription[] suppliers = ((GenericSpecification) constraint.getVersionConstraint()).getSuppliers();
    if (suppliers == null)
        return;
    VersionHashMap<GenericCapability> namespace = resolverGenerics.get(constraint.getNameSpace());
    if (namespace == null) {
        // $NON-NLS-1$
        System.err.println("Could not find matching capability for " + constraint.getVersionConstraint());
        // TODO log error!!
        return;
    }
    String constraintName = constraint.getName();
    List<GenericCapability> matches = constraintName == null ? namespace.get(constraintName) : namespace.getAllValues();
    for (GenericCapability match : matches) {
        for (GenericDescription supplier : suppliers) if (match.getBaseDescription() == supplier)
            constraint.addPossibleSupplier(match);
    }
    VersionSupplier[] matchingCapabilities = constraint.getPossibleSuppliers();
    if (matchingCapabilities != null)
        for (int i = 0; i < matchingCapabilities.length; i++) rewireBundle(matchingCapabilities[i].getResolverBundle(), visited);
}
Also used : GenericDescription(org.eclipse.osgi.service.resolver.GenericDescription) GenericSpecification(org.eclipse.osgi.service.resolver.GenericSpecification)

Aggregations

GenericDescription (org.eclipse.osgi.service.resolver.GenericDescription)5 ArrayList (java.util.ArrayList)4 ExportPackageDescription (org.eclipse.osgi.service.resolver.ExportPackageDescription)3 GenericSpecification (org.eclipse.osgi.service.resolver.GenericSpecification)3 VersionConstraint (org.eclipse.osgi.service.resolver.VersionConstraint)3 BundleSpecification (org.eclipse.osgi.service.resolver.BundleSpecification)2 ImportPackageSpecification (org.eclipse.osgi.service.resolver.ImportPackageSpecification)2 HashMap (java.util.HashMap)1 List (java.util.List)1 ExportPackageDescriptionImpl (org.eclipse.osgi.internal.resolver.ExportPackageDescriptionImpl)1 GenericDescriptionImpl (org.eclipse.osgi.internal.resolver.GenericDescriptionImpl)1 BundleDescription (org.eclipse.osgi.service.resolver.BundleDescription)1 HostSpecification (org.eclipse.osgi.service.resolver.HostSpecification)1 StateWire (org.eclipse.osgi.service.resolver.StateWire)1 BundleException (org.osgi.framework.BundleException)1