synchronized (this.monitor) {
if (resolver == null)
throw new IllegalStateException("no resolver set"); //$NON-NLS-1$
if (resolving == true)
throw new IllegalStateException("An attempt to start a nested resolve process has been detected."); //$NON-NLS-1$
ResolverHook currentHook = null;
try {
resolving = true;
long start = 0;
if (StateManager.DEBUG_PLATFORM_ADMIN_RESOLVER)
start = System.currentTimeMillis();
if (!incremental) {
resolved = false;
reResolve = getBundles();
// need to get any removal pendings before flushing
if (removalPendings.size() > 0) {
BundleDescription[] removed = internalGetRemovalPending();
reResolve = mergeBundles(reResolve, removed);
}
flush(reResolve);
} else {
if (resolved && reResolve == null)
return new StateDeltaImpl(this);
if (developmentMode) {
// in dev mode we need to aggressively flush removal pendings
if (removalPendings.size() > 0) {
BundleDescription[] removed = internalGetRemovalPending();
reResolve = mergeBundles(reResolve, removed);
}
}
if (reResolve == null)
reResolve = internalGetRemovalPending();
if (triggers == null) {
Set<BundleDescription> triggerSet = new HashSet<BundleDescription>();
Collection<BundleDescription> closure = getDependencyClosure(Arrays.asList(reResolve));
for (BundleDescription toRefresh : closure) {
Bundle bundle = toRefresh.getBundle();
if (bundle != null && (bundle.getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED | Bundle.RESOLVED)) == 0)
triggerSet.add(toRefresh);
}
triggers = triggerSet.toArray(new BundleDescription[triggerSet.size()]);
}
}
// use the Headers class to handle ignoring case while matching keys (bug 180817)
@SuppressWarnings("unchecked")
Headers<Object, Object>[] tmpPlatformProperties = new Headers[platformProperties.length];
for (int i = 0; i < platformProperties.length; i++) {
tmpPlatformProperties[i] = new Headers<Object, Object>(platformProperties[i].size());
for (Enumeration<Object> keys = platformProperties[i].keys(); keys.hasMoreElements();) {
Object key = keys.nextElement();
tmpPlatformProperties[i].put(key, platformProperties[i].get(key));
}
}
ResolverHookFactory currentFactory = hookFactory;
if (currentFactory != null) {
@SuppressWarnings("unchecked")
Collection<BundleRevision> triggerRevisions = Collections.unmodifiableCollection(triggers == null ? Collections.EMPTY_LIST : Arrays.asList((BundleRevision[]) triggers));
currentHook = begin(triggerRevisions);
}
ResolverHookException error = null;
try {
resolver.resolve(reResolve, tmpPlatformProperties);
} catch (ResolverHookException e) {
error = e;
resolverErrors.clear();
}
resolved = removalPendings.size() == 0;
StateDeltaImpl savedChanges = changes == null ? new StateDeltaImpl(this) : changes;
savedChanges.setResolverHookException(error);
changes = new StateDeltaImpl(this);
if (StateManager.DEBUG_PLATFORM_ADMIN_RESOLVER) {
long time = System.currentTimeMillis() - start;
Debug.println("Time spent resolving: " + time); //$NON-NLS-1$
cumulativeTime = cumulativeTime + time;
FrameworkDebugOptions.getDefault().setOption("org.eclipse.core.runtime.adaptor/resolver/timing/value", Long.toString(cumulativeTime)); //$NON-NLS-1$
}
if (savedChanges.getChanges().length > 0)
updateTimeStamp();
return savedChanges;
} finally {
if (currentHook != null)
currentHook.end();
resolving = false;
}
}
}