ResolvedResource ivyRef = findIvyFileRef(nsDd, data);
checkInterrupted();
// get module descriptor
final ModuleDescriptorParser parser;
ModuleDescriptor nsMd;
ModuleDescriptor systemMd = null;
if (ivyRef == null) {
if (!isAllownomd()) {
Message.verbose("\t" + getName() + ": no ivy file found for " + systemMrid);
return null;
}
parser = XmlModuleDescriptorParser.getInstance();
nsMd = DefaultModuleDescriptor.newDefaultInstance(nsMrid, nsDd
.getAllDependencyArtifacts());
ResolvedResource artifactRef = findFirstArtifactRef(nsMd, nsDd, data);
checkInterrupted();
if (artifactRef == null) {
Message.verbose("\t" + getName() + ": no ivy file nor artifact found for "
+ systemMrid);
return null;
} else {
long lastModified = artifactRef.getLastModified();
if (lastModified != 0 && nsMd instanceof DefaultModuleDescriptor) {
((DefaultModuleDescriptor) nsMd).setLastModified(lastModified);
}
Message.verbose("\t" + getName() + ": no ivy file found for " + systemMrid
+ ": using default data");
if (isDynamic) {
nsMd.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(nsMrid,
artifactRef.getRevision()));
}
systemMd = toSystem(nsMd);
MetadataArtifactDownloadReport madr =
new MetadataArtifactDownloadReport(systemMd.getMetadataArtifact());
madr.setDownloadStatus(DownloadStatus.NO);
madr.setSearched(true);
rmr = new ResolvedModuleRevision(this, this, systemMd, madr);
}
} else {
if (ivyRef instanceof MDResolvedResource) {
rmr = ((MDResolvedResource) ivyRef).getResolvedModuleRevision();
}
if (rmr == null) {
rmr = parse(ivyRef, systemDd, data);
if (rmr == null) {
return null;
}
}
if (!rmr.getReport().isDownloaded()) {
return toSystem(rmr);
} else {
nsMd = rmr.getDescriptor();
parser = ModuleDescriptorParserRegistry.getInstance().getParser(
ivyRef.getResource());
// check descriptor data is in sync with resource revision and names
systemMd = toSystem(nsMd);
if (checkconsistency) {
checkDescriptorConsistency(systemMrid, systemMd, ivyRef);
checkDescriptorConsistency(nsMrid, nsMd, ivyRef);
} else {
if (systemMd instanceof DefaultModuleDescriptor) {
String revision = getRevision(ivyRef, systemMrid, systemMd);
((DefaultModuleDescriptor) systemMd).setModuleRevisionId(
ModuleRevisionId.newInstance(systemMrid, revision));
} else {
Message.warn(
"consistency disabled with instance of non DefaultModuleDescriptor..."
+ " module info can't be updated, so consistency check will be done");
checkDescriptorConsistency(nsMrid, nsMd, ivyRef);
checkDescriptorConsistency(systemMrid, systemMd, ivyRef);
}
}
MetadataArtifactDownloadReport madr =
new MetadataArtifactDownloadReport(systemMd.getMetadataArtifact());
madr.setDownloadStatus(rmr.getReport().getDownloadStatus());
madr.setDownloadDetails(rmr.getReport().getDownloadDetails());
madr.setArtifactOrigin(rmr.getReport().getArtifactOrigin());
madr.setDownloadTimeMillis(rmr.getReport().getDownloadTimeMillis());
madr.setSize(rmr.getReport().getSize());
madr.setOriginalLocalFile(rmr.getReport().getOriginalLocalFile());
madr.setSearched(true);
rmr = new ResolvedModuleRevision(this, this, systemMd, madr);
}
}
// resolve revision
ModuleRevisionId resolvedMrid = systemMrid;
if (isDynamic) {
resolvedMrid = systemMd.getResolvedModuleRevisionId();
if (resolvedMrid.getRevision() == null
|| resolvedMrid.getRevision().length() == 0) {
if (ivyRef.getRevision() == null || ivyRef.getRevision().length() == 0) {
resolvedMrid = ModuleRevisionId.newInstance(resolvedMrid, "working@"
+ getName());
} else {
resolvedMrid = ModuleRevisionId.newInstance(resolvedMrid, ivyRef
.getRevision());
}
}
Message.verbose("\t\t[" + toSystem(resolvedMrid).getRevision() + "] "
+ systemMrid.getModuleId());
}
systemMd.setResolvedModuleRevisionId(resolvedMrid);
// check module descriptor revision
if (!getSettings().getVersionMatcher().accept(systemMrid, systemMd)) {
Message.info("\t" + getName() + ": unacceptable revision => was="
+ systemMd.getModuleRevisionId().getRevision() + " required="
+ systemMrid.getRevision());
return null;
}
// resolve and check publication date
if (data.getDate() != null) {
long pubDate = getPublicationDate(systemMd, systemDd, data);
if (pubDate > data.getDate().getTime()) {
Message.info("\t" + getName() + ": unacceptable publication date => was="
+ new Date(pubDate) + " required=" + data.getDate());
return null;
} else if (pubDate == -1) {
Message.info("\t" + getName()
+ ": impossible to guess publication date: artifact missing for "
+ systemMrid);
return null;
}
systemMd.setResolvedPublicationDate(new Date(pubDate));
}
if (!systemMd.isDefault()
&& data.getSettings().logNotConvertedExclusionRule()
&& systemMd instanceof DefaultModuleDescriptor) {
DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) systemMd;
if (dmd.isNamespaceUseful()) {
Message.warn(
"the module descriptor "
+ ivyRef.getResource()
+ " has information which can't be converted into "
+ "the system namespace. "
+ "It will require the availability of the namespace '"
+ getNamespace().getName() + "' to be fully usable.");
}
}
RepositoryCacheManager cacheManager = getRepositoryCacheManager();
// the metadata artifact which was used to cache the original metadata file
Artifact requestedMetadataArtifact =
ivyRef == null
? systemMd.getMetadataArtifact()
: parser.getMetadataArtifact(
ModuleRevisionId.newInstance(systemMrid, ivyRef.getRevision()),
ivyRef.getResource());
cacheManager.originalToCachedModuleDescriptor(this, ivyRef, requestedMetadataArtifact,
rmr, new ModuleDescriptorWriter() {
public void write(ResolvedResource originalMdResource, ModuleDescriptor md,
File src, File dest)
throws IOException, ParseException {
if (originalMdResource == null) {
// a basic ivy file is written containing default data
XmlModuleDescriptorWriter.write(md, dest);
} else {
// copy and update ivy file from source to cache
parser.toIvyFile(
new FileInputStream(src),
originalMdResource.getResource(), dest,
md);
long repLastModified = originalMdResource.getLastModified();
if (repLastModified > 0) {