Search in sources :

Example 96 with BundleDescription

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

the class NewResolverTest method testBasicScenario1.

public void testBasicScenario1() throws BundleException {
    State state = buildEmptyState();
    final String MAN_A = "Bundle-SymbolicName: A\n" + "Export-Package: servlet; specification-version=2.1";
    BundleDescription bA = state.getFactory().createBundleDescription(parseManifest(MAN_A), "org.eclipse.basic1A", 0);
    state.addBundle(bA);
    final String MAN_B = "Bundle-SymbolicName: B\n" + "Import-Package: servlet; specification-version=2.1";
    BundleDescription bB = state.getFactory().createBundleDescription(parseManifest(MAN_B), "org.eclipse.basic1B", 1);
    state.addBundle(bB);
    state.resolve();
    BundleDescription b0 = state.getBundle(0);
    assertNotNull("0.1", b0);
    assertFullyResolved("0.2", b0);
    BundleDescription b1 = state.getBundle(1);
    assertNotNull("0.3", b1);
    assertFullyResolved("0.4", b1);
}
Also used : State(org.eclipse.osgi.service.resolver.State) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription)

Example 97 with BundleDescription

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

the class PlatformBundleListener method resolve.

private void resolve(boolean uninstalled) {
    database.readLock();
    try {
        if (lastResolveStamp != database.getRevisionsTimestamp()) {
            Collection<ModuleRevision> containerRemovalPending = container.getRemovalPending();
            BundleDescription[] stateRemovalPendingDescs = systemState.getRemovalPending();
            Collection<BundleDescription> stateRemovalPending = new ArrayList<>(stateRemovalPendingDescs.length);
            for (BundleDescription description : stateRemovalPendingDescs) {
                if (!containerRemovalPending.contains(description.getUserObject())) {
                    stateRemovalPending.add(description);
                }
            }
            if (!stateRemovalPending.isEmpty()) {
                systemState.resolve(stateRemovalPending.toArray(new BundleDescription[stateRemovalPending.size()]), true);
            } else {
                systemState.resolve(!uninstalled);
            }
            lastResolveStamp = database.getRevisionsTimestamp();
            systemState.setTimeStamp(database.getRevisionsTimestamp());
        }
    } finally {
        database.readUnlock();
    }
}
Also used : BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription)

Example 98 with BundleDescription

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

the class ResolverImpl method addDevConstraints.

private BundleDescription[] addDevConstraints(BundleDescription[] reRefresh) {
    if (!developmentMode)
        // we don't care about this unless we are in development mode
        return reRefresh;
    // when in develoment mode we need to reRefresh hosts  of unresolved fragments that add new constraints
    // and reRefresh and unresolved bundles that have dependents
    Set<BundleDescription> additionalRefresh = new HashSet<>();
    ResolverBundle[] unresolved = unresolvedBundles.toArray(new ResolverBundle[unresolvedBundles.size()]);
    for (int i = 0; i < unresolved.length; i++) {
        addUnresolvedWithDependents(unresolved[i], additionalRefresh);
        addHostsFromFragmentConstraints(unresolved[i], additionalRefresh);
    }
    if (additionalRefresh.size() == 0)
        // no new bundles found to refresh
        return reRefresh;
    // add the original reRefresh bundles to the set
    if (reRefresh != null)
        for (int i = 0; i < reRefresh.length; i++) additionalRefresh.add(reRefresh[i]);
    return additionalRefresh.toArray(new BundleDescription[additionalRefresh.size()]);
}
Also used : BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) VersionConstraint(org.eclipse.osgi.service.resolver.VersionConstraint) HashSet(java.util.HashSet)

Example 99 with BundleDescription

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

the class ResolverImpl method unresolveBundle.

private void unresolveBundle(ResolverBundle bundle, boolean removed) {
    // check the removed list if unresolving then remove from the removed list
    List<BundleDescription> removedBundles = removalPending.remove(new Long(bundle.getBundleDescription().getBundleId()));
    for (BundleDescription removedDesc : removedBundles) {
        ResolverBundle re = bundleMapping.get(removedDesc);
        if (re == null) {
            continue;
        }
        unresolveBundle(re, true);
        state.removeBundleComplete(removedDesc);
        resolverExports.remove(re.getExportPackages());
        resolverBundles.remove(re);
        removeGenerics(re.getGenericCapabilities());
        bundleMapping.remove(removedDesc);
        groupingChecker.clear(re);
        // the bundle is removed
        if (removedDesc == bundle.getBundleDescription())
            removed = true;
    }
    if (!bundle.getBundleDescription().isResolved() && !developmentMode)
        return;
    CompositeResolveHelperRegistry currentLinks = compositeHelpers;
    if (currentLinks != null) {
        CompositeResolveHelper helper = currentLinks.getCompositeResolveHelper(bundle.getBundleDescription());
        if (helper != null)
            helper.giveExports(null);
    }
    // if not removed then add to the list of unresolvedBundles,
    // passing false for devmode because we need all fragments detached
    setBundleUnresolved(bundle, removed, false);
    // Get bundles dependent on 'bundle'
    BundleDescription[] dependents = bundle.getBundleDescription().getDependents();
    state.resolveBundle(bundle.getBundleDescription(), false, null, null, null, null, null, null, null, null);
    // Unresolve dependents of 'bundle'
    for (int i = 0; i < dependents.length; i++) {
        ResolverBundle db = bundleMapping.get(dependents[i]);
        if (db == null) {
            continue;
        }
        unresolveBundle(db, false);
    }
}
Also used : BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) VersionConstraint(org.eclipse.osgi.service.resolver.VersionConstraint)

Example 100 with BundleDescription

use of org.eclipse.osgi.service.resolver.BundleDescription 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)

Aggregations

BundleDescription (org.eclipse.osgi.service.resolver.BundleDescription)202 BundleException (org.osgi.framework.BundleException)106 State (org.eclipse.osgi.service.resolver.State)87 Hashtable (java.util.Hashtable)70 Dictionary (java.util.Dictionary)28 ExportPackageDescription (org.eclipse.osgi.service.resolver.ExportPackageDescription)18 ArrayList (java.util.ArrayList)11 StateDelta (org.eclipse.osgi.service.resolver.StateDelta)11 BundleDelta (org.eclipse.osgi.service.resolver.BundleDelta)10 List (java.util.List)9 HashMap (java.util.HashMap)8 File (java.io.File)6 Map (java.util.Map)6 CaseInsensitiveDictionaryMap (org.eclipse.osgi.framework.util.CaseInsensitiveDictionaryMap)6 VersionConstraint (org.eclipse.osgi.service.resolver.VersionConstraint)6 Version (org.osgi.framework.Version)6 BundleWiring (org.osgi.framework.wiring.BundleWiring)5 BundleContext (org.osgi.framework.BundleContext)2 ResolverHook (org.osgi.framework.hooks.resolver.ResolverHook)2 Collection (java.util.Collection)1