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;
}
}
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;
}
}
Aggregations