* Resolve dependencies of a module described by a module descriptor.
*/
public ResolveReport resolve(ModuleDescriptor md, ResolveOptions options)
throws ParseException, IOException {
DependencyResolver oldDictator = getDictatorResolver();
IvyContext context = IvyContext.getContext();
try {
String[] confs = options.getConfs(md);
options.setConfs(confs);
if (options.getResolveId() == null) {
options.setResolveId(ResolveOptions.getDefaultResolveId(md));
}
eventManager.fireIvyEvent(new StartResolveEvent(md, confs));
long start = System.currentTimeMillis();
if (ResolveOptions.LOG_DEFAULT.equals(options.getLog())) {
Message.info(":: resolving dependencies :: " + md.getResolvedModuleRevisionId()
+ (options.isTransitive() ? "" : " [not transitive]"));
Message.info("\tconfs: " + Arrays.asList(confs));
} else {
Message.verbose(":: resolving dependencies :: " + md.getResolvedModuleRevisionId()
+ (options.isTransitive() ? "" : " [not transitive]"));
Message.verbose("\tconfs: " + Arrays.asList(confs));
}
Message.verbose("\tvalidate = " + options.isValidate());
Message.verbose("\trefresh = " + options.isRefresh());
ResolveReport report = new ResolveReport(md, options.getResolveId());
ResolveData data = new ResolveData(this, options);
context.setResolveData(data);
// resolve dependencies
IvyNode[] dependencies = getDependencies(md, options, report);
report.setDependencies(Arrays.asList(dependencies), options.getArtifactFilter());
if (options.getCheckIfChanged()) {
report.checkIfChanged();
}
// produce resolved ivy file and ivy properties in cache
ResolutionCacheManager cacheManager = settings.getResolutionCacheManager();
cacheManager.saveResolvedModuleDescriptor(md);
// we store the resolved dependencies revisions and statuses per asked dependency
// revision id, for direct dependencies only.
// this is used by the deliver task to resolve dynamic revisions to static ones
File ivyPropertiesInCache = cacheManager.getResolvedIvyPropertiesInCache(
md.getResolvedModuleRevisionId());
Properties props = new Properties();
if (dependencies.length > 0) {
Map forcedRevisions = new HashMap();
for (int i = 0; i < dependencies.length; i++) {
if (dependencies[i].getModuleRevision() != null
&& dependencies[i].getModuleRevision().isForce()) {
forcedRevisions.put(dependencies[i].getModuleId(), dependencies[i].getResolvedId());
}
}
IvyNode root = dependencies[0].getRoot();
// <ModuleId,IvyNode>();
Map topLevelDeps = new HashMap(); //
for (int i = 0; i < dependencies.length; i++) {
if (!dependencies[i].hasProblem()) {
DependencyDescriptor dd = dependencies[i].getDependencyDescriptor(root);
if (dd != null) {
ModuleId orgMod = dependencies[i].getModuleId();
topLevelDeps.put(orgMod, dependencies[i]);
}
}
}
for (int i = 0; i < dependencies.length; i++) {
if (!dependencies[i].hasProblem() && !dependencies[i].isCompletelyEvicted()) {
DependencyDescriptor dd = dependencies[i].getDependencyDescriptor(root);
if (dd == null) {
ModuleId mid = dependencies[i].getModuleId();
IvyNode tlDep = (IvyNode)topLevelDeps.get(mid);
if (tlDep != null) {
dd = tlDep.getDependencyDescriptor(root);
}
}
if (dd != null) {
ModuleRevisionId depResolvedId = dependencies[i].getResolvedId();
ModuleDescriptor depDescriptor = dependencies[i].getDescriptor();
ModuleRevisionId depRevisionId = dd.getDependencyRevisionId();
ModuleRevisionId forcedRevisionId = (ModuleRevisionId)
forcedRevisions.get(dependencies[i].getModuleId());
if (dependencies[i].getModuleRevision() != null
&& dependencies[i].getModuleRevision().isForce()
&& !depResolvedId.equals(depRevisionId)
&& !settings.getVersionMatcher().isDynamic(depRevisionId)) {
// if we were forced to this revision and we
// are not a dynamic revision, reset to the
// asked revision
depResolvedId = depRevisionId;
depDescriptor = null;
}
if (depResolvedId == null) {
throw new NullPointerException("getResolvedId() is null for "
+ dependencies[i].toString());
}
if (depRevisionId == null) {
throw new NullPointerException("getDependencyRevisionId() "
+ "is null for " + dd.toString());
}
String rev = depResolvedId.getRevision();
String forcedRev = forcedRevisionId == null ? rev : forcedRevisionId.getRevision();
// The evicted modules have no description, so we can't put the status
String status = depDescriptor == null ? "?" : depDescriptor.getStatus();
Message.debug("storing dependency " + depResolvedId + " in props");
props.put(depRevisionId.encodeToString(), rev + " " + status + " " + forcedRev + " " + depResolvedId.getBranch());
}
}
}
}
FileOutputStream out = new FileOutputStream(ivyPropertiesInCache);
props.store(out, md.getResolvedModuleRevisionId() + " resolved revisions");
out.close();
Message.verbose("\tresolved ivy file produced in cache");
report.setResolveTime(System.currentTimeMillis() - start);
if (options.isDownload()) {
Message.verbose(":: downloading artifacts ::");
downloadArtifacts(report, options.getArtifactFilter(),
(DownloadOptions) new DownloadOptions().setLog(options.getLog()));
}
if (options.isOutputReport()) {
outputReport(report, cacheManager, options);
}
Message.verbose("\tresolve done (" + report.getResolveTime() + "ms resolve - "
+ report.getDownloadTime() + "ms download)");
Message.sumupProblems();
eventManager.fireIvyEvent(new EndResolveEvent(md, confs, report));
return report;
} catch (RuntimeException ex) {
Message.error(ex.getMessage());
Message.sumupProblems();
throw ex;
} finally {
context.setResolveData(null);
setDictatorResolver(oldDictator);
}
}