Search in sources :

Example 6 with ImportPackageSpecification

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

Aggregations

ImportPackageSpecification (org.eclipse.osgi.service.resolver.ImportPackageSpecification)6 BundleSpecification (org.eclipse.osgi.service.resolver.BundleSpecification)5 VersionConstraint (org.eclipse.osgi.service.resolver.VersionConstraint)5 ExportPackageDescription (org.eclipse.osgi.service.resolver.ExportPackageDescription)4 ArrayList (java.util.ArrayList)2 BaseDescription (org.eclipse.osgi.service.resolver.BaseDescription)2 GenericDescription (org.eclipse.osgi.service.resolver.GenericDescription)2 GenericSpecification (org.eclipse.osgi.service.resolver.GenericSpecification)2 ExportPackageDescriptionImpl (org.eclipse.osgi.internal.resolver.ExportPackageDescriptionImpl)1 GenericDescriptionImpl (org.eclipse.osgi.internal.resolver.GenericDescriptionImpl)1 StateImpl (org.eclipse.osgi.internal.resolver.StateImpl)1 BundleDescription (org.eclipse.osgi.service.resolver.BundleDescription)1 HostSpecification (org.eclipse.osgi.service.resolver.HostSpecification)1