use of org.eclipse.osgi.service.resolver.ImportPackageSpecification in project rt.equinox.framework by eclipse.
the class ResolverBundle method hasUnresolvedConstraint.
private boolean hasUnresolvedConstraint(ResolverConstraint reason, ResolverBundle detachedFragment, ResolverBundle remainingFragment, ResolverImport[] oldImports, BundleConstraint[] oldRequires, List<ResolverImport> additionalImports, List<BundleConstraint> additionalRequires) {
ImportPackageSpecification[] remainingFragImports = remainingFragment.getBundleDescription().getImportPackages();
BundleSpecification[] remainingFragRequires = remainingFragment.getBundleDescription().getRequiredBundles();
VersionConstraint[] constraints;
if (reason instanceof ResolverImport)
constraints = remainingFragImports;
else
constraints = remainingFragRequires;
for (int i = 0; i < constraints.length; i++) if (reason.getName().equals(constraints[i].getName())) {
detachFragment(remainingFragment, reason);
return true;
}
for (int i = 0; i < oldImports.length; i++) {
if (oldImports[i].getVersionConstraint().getBundle() != detachedFragment.getBundleDescription())
// the constraint is not from the detached fragment
continue;
for (int j = 0; j < remainingFragImports.length; j++) {
if (oldImports[i].getName().equals(remainingFragImports[j].getName())) {
// same constraint, must reuse the constraint object but swap out the fragment info
additionalImports.add(oldImports[i]);
oldImports[i].setVersionConstraint(remainingFragImports[j]);
break;
}
}
}
for (int i = 0; i < oldRequires.length; i++) {
if (oldRequires[i].getVersionConstraint().getBundle() != detachedFragment.getBundleDescription())
// the constraint is not from the detached fragment
continue;
for (int j = 0; j < remainingFragRequires.length; j++) {
if (oldRequires[i].getName().equals(remainingFragRequires[j].getName())) {
// same constraint, must reuse the constraint object but swap out the fragment info
additionalRequires.add(oldRequires[i]);
oldRequires[i].setVersionConstraint(remainingFragRequires[j]);
break;
}
}
}
return false;
}
use of org.eclipse.osgi.service.resolver.ImportPackageSpecification 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;
}
use of org.eclipse.osgi.service.resolver.ImportPackageSpecification in project rt.equinox.framework by eclipse.
the class ResolverImpl method stateResolveFragConstraints.
private void stateResolveFragConstraints(ResolverBundle rb) {
ResolverBundle host = (ResolverBundle) rb.getHost().getSelectedSupplier();
ImportPackageSpecification[] imports = rb.getBundleDescription().getImportPackages();
for (int i = 0; i < imports.length; i++) {
ResolverImport hostImport = host == null ? null : host.getImport(imports[i].getName());
ResolverExport export = (ResolverExport) (hostImport == null ? null : hostImport.getSelectedSupplier());
BaseDescription supplier = export == null ? null : export.getExportPackageDescription();
state.resolveConstraint(imports[i], supplier);
}
BundleSpecification[] requires = rb.getBundleDescription().getRequiredBundles();
for (int i = 0; i < requires.length; i++) {
BundleConstraint hostRequire = host == null ? null : host.getRequire(requires[i].getName());
ResolverBundle bundle = (ResolverBundle) (hostRequire == null ? null : hostRequire.getSelectedSupplier());
BaseDescription supplier = bundle == null ? null : bundle.getBundleDescription();
state.resolveConstraint(requires[i], supplier);
}
GenericConstraint[] genericRequires = rb.getGenericRequires();
for (int i = 0; i < genericRequires.length; i++) {
VersionSupplier[] matchingCapabilities = genericRequires[i].getMatchingCapabilities();
if (matchingCapabilities == null)
state.resolveConstraint(genericRequires[i].getVersionConstraint(), null);
else
for (int j = 0; j < matchingCapabilities.length; j++) state.resolveConstraint(genericRequires[i].getVersionConstraint(), matchingCapabilities[j].getBaseDescription());
}
}
use of org.eclipse.osgi.service.resolver.ImportPackageSpecification 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;
}
}
use of org.eclipse.osgi.service.resolver.ImportPackageSpecification in project tycho by eclipse.
the class DependencyComputer method addHostPlugin.
private void addHostPlugin(HostSpecification hostSpec, HashSet<BundleDescription> added, Map<BundleDescription, ArrayList<AccessRule>> map, ArrayList<DependencyEntry> entries) {
BaseDescription desc = hostSpec.getSupplier();
if (desc instanceof BundleDescription) {
BundleDescription host = (BundleDescription) desc;
// add host plug-in
if (added.add(host) && addPlugin(host, false, map, entries)) {
BundleSpecification[] required = host.getRequiredBundles();
for (int i = 0; i < required.length; i++) {
addDependency((BundleDescription) required[i].getSupplier(), added, map, entries);
}
// add Import-Package
ImportPackageSpecification[] imports = host.getImportPackages();
for (int i = 0; i < imports.length; i++) {
BaseDescription supplier = imports[i].getSupplier();
if (supplier instanceof ExportPackageDescription) {
addDependencyViaImportPackage(((ExportPackageDescription) supplier).getExporter(), added, map, entries);
}
}
}
}
}
Aggregations