{
// Acquire global lock.
boolean locked = m_felix.acquireGlobalLock();
if (!locked)
{
throw new ResolveException(
"Unable to acquire global lock for resolve.", null, null);
}
// Make sure we are not already resolving, which can be
// the case if a resolver hook does something bad.
if (m_isResolving)
{
m_felix.releaseGlobalLock();
throw new IllegalStateException("Nested resolve operations not allowed.");
}
m_isResolving = true;
Map<BundleRevision, List<ResolverWire>> wireMap = null;
try
{
// Make our own copy of revisions.
mandatory = (mandatory.isEmpty())
? mandatory : new HashSet<BundleRevision>(mandatory);
optional = (optional.isEmpty())
? optional : new HashSet<BundleRevision>(optional);
// Prepare resolver hooks, if any.
ResolverHookRecord record = prepareResolverHooks(mandatory, optional);
// Select any singletons in the resolver state.
selectSingletons(record);
// Extensions are resolved differently.
for (Iterator<BundleRevision> it = mandatory.iterator(); it.hasNext(); )
{
BundleRevision br = it.next();
BundleImpl bundle = (BundleImpl) br.getBundle();
if (bundle.isExtension())
{
it.remove();
}
else if (Util.isSingleton(br) && !isSelectedSingleton(br))
{
throw new ResolveException("Singleton conflict.", br, null);
}
}
for (Iterator<BundleRevision> it = optional.iterator(); it.hasNext(); )
{
BundleRevision br = it.next();
BundleImpl bundle = (BundleImpl) br.getBundle();
if (bundle.isExtension())
{
it.remove();
}
else if (Util.isSingleton(br) && !isSelectedSingleton(br))
{
it.remove();
}
}
// Catch any resolve exception to rethrow later because
// we may need to call end() on resolver hooks.
ResolveException rethrow = null;
try
{
// Resolve the revision.
wireMap = m_resolver.resolve(
new ResolveContextImpl(