MultiStatus errorStatuses = new MultiStatus(IvyPlugin.ID, IStatus.ERROR,
"Failed to update one or more Ivy files. See details.", null);
IvyClasspathContainer[] containers = getIvyClasspathContainers();
for (int i = 0; i < containers.length; i++) {
IvyClasspathContainer container = containers[i];
ModuleDescriptor moduleDescriptor;
try {
moduleDescriptor = container.getState().getModuleDescriptor();
} catch (IvyDEException e) {
errorStatuses
.add(new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.ERROR,
"Failed to get module descriptor at "
+ container.getConf().getIvyXmlPath(), e));
continue;
}
Map/* <ModuleRevisionId, String> */newRevisions = new HashMap();
DependencyDescriptor[] dependencies = moduleDescriptor.getDependencies();
for (int j = 0; j < dependencies.length; j++) {
for (int k = 0; k < multiRevisionDependencies.length; k++) {
MultiRevisionDependencyDescriptor multiRevision = multiRevisionDependencies[k];
ModuleRevisionId dependencyRevisionId = dependencies[j]
.getDependencyRevisionId();
if (dependencies[j].getDependencyId().equals(multiRevision.getModuleId())
&& multiRevision.hasNewRevision()
&& multiRevision.isForContainer(container)) {
newRevisions.put(dependencyRevisionId, multiRevisionDependencies[k]
.getNewRevision());
break; // move on to the next dependency
}
}
}
UpdateOptions updateOptions = new UpdateOptions()
.setResolvedRevisions(newRevisions)
.setReplaceInclude(false)
.setGenerateRevConstraint(false)
.setNamespace(new RevisionPreservingNamespace());
File ivyFile = container.getState().getIvyFile();
File ivyTempFile = new File(ivyFile.toString() + ".temp");
try {
XmlModuleDescriptorUpdater.update(ivyFile.toURI().toURL(), ivyTempFile,
updateOptions);
saveChanges(container, ivyFile, ivyTempFile);
} catch (MalformedURLException e) {
errorStatuses.add(new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.ERROR,
"Failed to write Ivy file " + container.getState().getIvyFile().getPath()
+ " (malformed URL)", e));
} catch (IOException e) {
errorStatuses.add(new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.ERROR,
"Failed to write Ivy file " + container.getState().getIvyFile().getPath(),
e));
} catch (SAXException e) {
errorStatuses.add(new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.ERROR,
"Failed to write Ivy file " + container.getState().getIvyFile().getPath(),
e));
} finally {
ivyTempFile.delete();
}
}