Map/* <ModuleDescriptor, List<ResolveRequest>> */inworkspaceModules = new LinkedHashMap();
List/* <ResolveRequest> */otherModules = new ArrayList();
Map/* <ResolveRequest, Ivy> */ivys = new HashMap();
Map/* <ResolveRequest, ModuleDescriptor> */mds = new HashMap();
final MultiStatus errorsStatus = new MultiStatus(IvyPlugin.ID, IStatus.ERROR,
"Some projects fail to be resolved", null);
int step = IVY_LOAD_LENGTH / toResolve.size();
boolean forceFailOnError = false;
// Ivy use the SaxParserFactory, and we want it to instanciate the xerces parser which is in
// the dependencies of IvyDE, so accessible via the current classloader
ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(IvyResolveJob.class.getClassLoader());
try {
Iterator itRequests = toResolve.iterator();
while (itRequests.hasNext()) {
ResolveRequest request = (ResolveRequest) itRequests.next();
IvyDEMessage.info("Processing resolve request " + request.toString());
forceFailOnError = forceFailOnError || request.isForceFailOnError();
monitor.subTask("loading " + request.getResolver().toString());
IProject project = request.getResolver().getProject();
if (project != null && !project.isAccessible()) {
IvyDEMessage.warn("Skipping resolve on closed project " + project.getName());
monitor.worked(step);
continue;
}
IvyDEMessage.verbose("Loading ivysettings for " + request.toString());
CachedIvy cachedIvy = request.getCachedIvy();
Ivy ivy;
try {
ivy = cachedIvy.getIvy();
} catch (IvyDEException e) {
cachedIvy.setErrorMarker(e);
IvyDEMessage.error("Failed to configure Ivy for " + request + ": "
+ e.getMessage());
errorsStatus.add(e.asStatus(IStatus.ERROR, "Failed to configure Ivy for "
+ request));
monitor.worked(step);
continue;
}
cachedIvy.setErrorMarker(null);
ivys.put(request, ivy);
// IVYDE-168 : Ivy needs the IvyContext in the threadlocal in order to found the
// default branch
ivy.pushContext();
ModuleDescriptor md;
try {
md = cachedIvy.getModuleDescriptor(ivy);
} catch (IvyDEException e) {
cachedIvy.setErrorMarker(e);
IvyDEMessage.error("Failed to load the descriptor for " + request + ": "
+ e.getMessage());
errorsStatus.add(e.asStatus(IStatus.ERROR, "Failed to load the descriptor for "
+ request));
monitor.worked(step);
continue;
} finally {
ivy.popContext();
}
cachedIvy.setErrorMarker(null);
mds.put(request, md);
if (request.isInWorkspace()) {
List requests = (List) inworkspaceModules.get(md);
if (requests == null) {
requests = new ArrayList();
inworkspaceModules.put(md, requests);
}
requests.add(request);
} else {
otherModules.add(request);
}
monitor.worked(step);
}
} finally {
Thread.currentThread().setContextClassLoader(old);
}
step = (MONITOR_LENGTH - IVY_LOAD_LENGTH - POST_RESOLVE_LENGTH) / toResolve.size();
if (inworkspaceModules.isEmpty()) {
IvyDEMessage.verbose("No module to resolve in workspace");
} else {
IvyDEMessage.info(inworkspaceModules.size() + " module(s) to resolve in workspace");
// for the modules which are using the workspace resolver, make sure
// we resolve them in the correct order
// The version matcher used will be the one configured for the first project
ResolveRequest request = (ResolveRequest) ((List) inworkspaceModules.values()
.iterator().next()).get(0);
VersionMatcher versionMatcher = ((Ivy) ivys.get(request)).getSettings()
.getVersionMatcher();
WarningNonMatchingVersionReporter vReporter = new WarningNonMatchingVersionReporter();
CircularDependencyStrategy circularDependencyStrategy = WarnCircularDependencyStrategy
.getInstance();
ModuleDescriptorSorter sorter = new ModuleDescriptorSorter(inworkspaceModules.keySet(),
versionMatcher, vReporter, circularDependencyStrategy);
List sortedModuleDescriptors = sorter.sortModuleDescriptors();
Iterator it = sortedModuleDescriptors.iterator();
while (it.hasNext()) {
ModuleDescriptor module = (ModuleDescriptor) it.next();
List requests = (List) inworkspaceModules.get(module);
IvyDEMessage.info(requests.size() + " container(s) of module " + module
+ " to resolve in workspace");
for (int i = 0; i < requests.size(); i++) {
request = (ResolveRequest) requests.get(i);
Ivy ivy = (Ivy) ivys.get(request);
ModuleDescriptor md = (ModuleDescriptor) mds.get(request);
boolean canceled = launchResolveThread(request, monitor, step, errorsStatus,
ivy, md);
if (canceled) {
IvyDEMessage.warn("Resolve job canceled");
return Status.CANCEL_STATUS;
}
}
}
}
if (otherModules.isEmpty()) {
IvyDEMessage.verbose("No module to resolve outside the workspace");
} else {
IvyDEMessage.info(otherModules.size() + " module(s) to resolve outside the workspace");
Iterator it = otherModules.iterator();
while (it.hasNext()) {
ResolveRequest request = (ResolveRequest) it.next();
Ivy ivy = (Ivy) ivys.get(request);
ModuleDescriptor md = (ModuleDescriptor) mds.get(request);
boolean canceled = launchResolveThread(request, monitor, step, errorsStatus, ivy,
md);
if (canceled) {
IvyDEMessage.warn("Resolve job canceled");
return Status.CANCEL_STATUS;
}
}
}
step = POST_RESOLVE_LENGTH / toResolve.size();
monitor.setTaskName("Post resolve");
// launch every post batch resolve
Iterator itRequests = toResolve.iterator();
while (itRequests.hasNext()) {
ResolveRequest request = (ResolveRequest) itRequests.next();
if (!request.isResolveFailed()) {
monitor.setTaskName(request.getResolver().toString());
request.getResolver().postBatchResolve();
}
monitor.worked(step);
}
if (errorsStatus.getChildren().length != 0) {
// some errors happend, stop here
if (forceFailOnError || IvyPlugin.getPreferenceStoreHelper().isErrorPopup()) {
return errorsStatus;
}
return Status.OK_STATUS;