}
public ResolvedModuleRevision cacheModuleDescriptor(
DependencyResolver resolver, final ResolvedResource mdRef, Artifact moduleArtifact,
ResourceDownloader downloader, CacheMetadataOptions options) throws ParseException {
ModuleDescriptorParser parser = ModuleDescriptorParserRegistry
.getInstance().getParser(mdRef.getResource());
Date cachedPublicationDate = null;
ArtifactDownloadReport report;
ModuleRevisionId mrid = moduleArtifact.getModuleRevisionId();
Artifact originalMetadataArtifact = getOriginalMetadataArtifact(moduleArtifact);
if (!lockMetadataArtifact(mrid)) {
Message.error("impossible to acquire lock for " + mrid);
return null;
}
try {
// now let's see if we can find it in cache and if it is up to date
ResolvedModuleRevision rmr = findModuleInCache(
mrid, options.isValidate(), resolver.getName());
if (rmr != null) {
if (rmr.getDescriptor().isDefault() && rmr.getResolver() != this) {
Message.verbose("\t" + getName() + ": found revision in cache: " + mrid
+ " (resolved by " + rmr.getResolver().getName()
+ "): but it's a default one, maybe we can find a better one");
} else {
if (!options.isCheckmodified() && !options.isChanging()) {
Message.verbose("\t" + getName() + ": revision in cache: " + mrid);
return DefaultModuleRevision.searchedRmr(rmr);
}
long repLastModified = mdRef.getLastModified();
long cacheLastModified = rmr.getDescriptor().getLastModified();
if (!rmr.getDescriptor().isDefault() && repLastModified <= cacheLastModified) {
Message.verbose("\t" + getName() + ": revision in cache (not updated): "
+ mrid);
return DefaultModuleRevision.searchedRmr(rmr);
} else {
Message.verbose("\t" + getName() + ": revision in cache is not up to date: "
+ mrid);
if (options.isChanging()) {
// ivy file has been updated, we should see if it has a new publication
// date to see if a new download is required (in case the dependency is
// a changing one)
cachedPublicationDate =
rmr.getDescriptor().getResolvedPublicationDate();
}
}
}
}
// now download module descriptor and parse it
report = download(
originalMetadataArtifact,
new ArtifactResourceResolver() {
public ResolvedResource resolve(Artifact artifact) {
return mdRef;
}
}, downloader,
new CacheDownloadOptions().setListener(options.getListener()).setForce(true));
Message.verbose("\t" + report);
if (report.getDownloadStatus() == DownloadStatus.FAILED) {
Message.warn("problem while downloading module descriptor: " + mdRef.getResource()
+ ": " + report.getDownloadDetails()
+ " (" + report.getDownloadTimeMillis() + "ms)");
return null;
}
URL cachedMDURL = null;
try {
cachedMDURL = report.getDownloadedFile().toURL();
} catch (MalformedURLException ex) {
Message.warn("malformed url exception for original in cache file: "
+ report.getDownloadedFile() + ": " + ex.getMessage());
return null;
}
try {
ModuleDescriptor md = parser.parseDescriptor(
settings, cachedMDURL, mdRef.getResource(), options.isValidate());
Message.debug("\t" + getName() + ": parsed downloaded md file for " + mrid
+ "; parsed=" + md.getModuleRevisionId());
// check if we should delete old artifacts