Search in sources :

Example 1 with StateImpl

use of org.eclipse.osgi.internal.resolver.StateImpl 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;
    }
}
Also used : ExportPackageDescription(org.eclipse.osgi.service.resolver.ExportPackageDescription) StateImpl(org.eclipse.osgi.internal.resolver.StateImpl) ImportPackageSpecification(org.eclipse.osgi.service.resolver.ImportPackageSpecification) VersionConstraint(org.eclipse.osgi.service.resolver.VersionConstraint)

Example 2 with StateImpl

use of org.eclipse.osgi.internal.resolver.StateImpl in project rt.equinox.framework by eclipse.

the class ResolverImpl method resolve.

public synchronized void resolve(BundleDescription[] reRefresh, Dictionary<Object, Object>[] platformProperties) {
    if (DEBUG)
        // $NON-NLS-1$
        ResolverImpl.log("*** BEGIN RESOLUTION ***");
    if (state == null)
        // $NON-NLS-1$
        throw new IllegalStateException("RESOLVER_NO_STATE");
    // set developmentMode each resolution
    developmentMode = platformProperties.length == 0 ? false : StateImpl.DEVELOPMENT_MODE.equals(platformProperties[0].get(StateImpl.OSGI_RESOLVER_MODE));
    // set uses timeout each resolution
    usesTimeout = getUsesTimeout(platformProperties);
    // set limit for constraints with multiple suppliers each resolution
    usesMultipleSuppliersLimit = getMultipleSuppliersLimit(platformProperties);
    hook = (state instanceof StateImpl) ? ((StateImpl) state).getResolverHook() : null;
    if (!initialized) {
        initialize();
    }
    try {
        reRefresh = addDevConstraints(reRefresh);
        // Unresolve all the supplied bundles and their dependents
        if (reRefresh != null)
            for (int i = 0; i < reRefresh.length; i++) {
                ResolverBundle rb = bundleMapping.get(reRefresh[i]);
                if (rb != null)
                    unresolveBundle(rb, false);
            }
        // reorder exports and bundles after unresolving the bundles
        resolverExports.reorder();
        resolverBundles.reorder();
        reorderGenerics();
        // always get the latest EEs
        getCurrentEEs(platformProperties);
        // $NON-NLS-1$//$NON-NLS-2$
        boolean resolveOptional = platformProperties.length == 0 ? false : "true".equals(platformProperties[0].get("osgi.resolveOptional"));
        ResolverBundle[] currentlyResolved = null;
        if (resolveOptional) {
            BundleDescription[] resolvedBundles = state.getResolvedBundles();
            currentlyResolved = new ResolverBundle[resolvedBundles.length];
            for (int i = 0; i < resolvedBundles.length; i++) currentlyResolved[i] = bundleMapping.get(resolvedBundles[i]);
        }
        // attempt to resolve all unresolved bundles
        Collection<ResolverBundle> hookDisabled = Collections.EMPTY_LIST;
        if (hook != null) {
            List<ResolverBundle> resolvableBundles = new ArrayList<>(unresolvedBundles);
            List<BundleRevision> resolvableRevisions = new ArrayList<>(resolvableBundles.size());
            for (ResolverBundle bundle : resolvableBundles) resolvableRevisions.add(bundle.getBundleDescription());
            ArrayMap<BundleRevision, ResolverBundle> resolvable = new ArrayMap<>(resolvableRevisions, resolvableBundles);
            int size = resolvableBundles.size();
            hook.filterResolvable(resolvable);
            if (resolvable.size() < size) {
                hookDisabled = new ArrayList<>(unresolvedBundles);
                hookDisabled.removeAll(resolvableBundles);
            }
        }
        usesCalculationTimeout = false;
        List<ResolverBundle> toResolve = new ArrayList<>(unresolvedBundles);
        // first resolve the system bundle to allow osgi.ee capabilities to be resolved
        List<ResolverBundle> unresolvedSystemBundles = new ArrayList<>(1);
        String systemBSN = getSystemBundle();
        for (Iterator<ResolverBundle> iToResolve = toResolve.iterator(); iToResolve.hasNext(); ) {
            ResolverBundle rb = iToResolve.next();
            String symbolicName = rb.getName();
            if (symbolicName != null && symbolicName.equals(systemBSN)) {
                unresolvedSystemBundles.add(rb);
                iToResolve.remove();
            }
        }
        if (!unresolvedSystemBundles.isEmpty())
            resolveBundles(unresolvedSystemBundles.toArray(new ResolverBundle[unresolvedSystemBundles.size()]), platformProperties, hookDisabled);
        // Now resolve the rest
        resolveBundles(toResolve.toArray(new ResolverBundle[toResolve.size()]), platformProperties, hookDisabled);
        Collection<ResolverBundle> optionalResolved = resolveOptional ? resolveOptionalConstraints(currentlyResolved) : Collections.EMPTY_LIST;
        ResolverHook current = hook;
        if (current != null) {
            hook = null;
            current.end();
        }
        // set the resolved status of the bundles in the State
        // Note this must be done after calling end above in case end throws errors
        stateResolveBundles(bundleMapping.values().toArray(new ResolverBundle[bundleMapping.size()]));
        for (ResolverBundle bundle : optionalResolved) {
            state.resolveBundle(bundle.getBundleDescription(), false, null, null, null, null, null, null, null, null);
            stateResolveBundle(bundle);
        }
        // reorder exports and bundles after resolving the bundles
        resolverExports.reorder();
        resolverBundles.reorder();
        reorderGenerics();
        if (resolveOptional)
            resolveOptionalConstraints(currentlyResolved);
        if (DEBUG)
            // $NON-NLS-1$
            ResolverImpl.log("*** END RESOLUTION ***");
    } finally {
        if (hook != null)
            // need to make sure end is always called
            hook.end();
        hook = null;
    }
}
Also used : ResolverHook(org.osgi.framework.hooks.resolver.ResolverHook) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) StateImpl(org.eclipse.osgi.internal.resolver.StateImpl) ArrayList(java.util.ArrayList) ArrayMap(org.eclipse.osgi.framework.util.ArrayMap) VersionConstraint(org.eclipse.osgi.service.resolver.VersionConstraint) BundleRevision(org.osgi.framework.wiring.BundleRevision)

Aggregations

StateImpl (org.eclipse.osgi.internal.resolver.StateImpl)2 VersionConstraint (org.eclipse.osgi.service.resolver.VersionConstraint)2 ArrayList (java.util.ArrayList)1 ArrayMap (org.eclipse.osgi.framework.util.ArrayMap)1 BundleDescription (org.eclipse.osgi.service.resolver.BundleDescription)1 ExportPackageDescription (org.eclipse.osgi.service.resolver.ExportPackageDescription)1 ImportPackageSpecification (org.eclipse.osgi.service.resolver.ImportPackageSpecification)1 ResolverHook (org.osgi.framework.hooks.resolver.ResolverHook)1 BundleRevision (org.osgi.framework.wiring.BundleRevision)1