use of org.eclipse.osgi.internal.resolver.ExportPackageDescriptionImpl 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()]));
}
}
Aggregations