ResolvedResource ivyRef = findIvyFileRef(nsDd, data);
checkInterrupted();
searched = true;
// 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);
if (!checkedCache) {
cachedRmr = findModuleInCache(data, systemMrid);
}
if (cachedRmr != null) {
Message.verbose("\t" + getName() + ": revision in cache: " + systemMrid);
return cachedRmr;
}
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()));
}
}
} else {
ResolvedModuleRevision rmr = null;
if (ivyRef instanceof MDResolvedResource) {
rmr = ((MDResolvedResource) ivyRef).getResolvedModuleRevision();
}
if (rmr == null) {
rmr = parse(ivyRef, systemDd, data);
if (rmr == null) {
return null;
}
}
if (!rmr.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 (nsMd instanceof DefaultModuleDescriptor) {
String revision = getRevision(ivyRef, nsMrid, nsMd);
((DefaultModuleDescriptor) nsMd).setModuleRevisionId(ModuleRevisionId
.newInstance(nsMrid, 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);
}
}
}
}
if (systemMd == null) {
systemMd = toSystem(nsMd);
}
// resolve revision
ModuleRevisionId resolvedMrid = nsMrid;
if (isDynamic) {
resolvedMrid = nsMd.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());
}
nsMd.setResolvedModuleRevisionId(resolvedMrid);
// keep system md in sync with ns md
systemMd.setResolvedModuleRevisionId(toSystem(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;
}
nsMd.setResolvedPublicationDate(new Date(pubDate));
systemMd.setResolvedPublicationDate(new Date(pubDate));
}
if (!nsMd.isDefault()
&& data.getSettings().logNotConvertedExclusionRule()
&& nsMd instanceof DefaultModuleDescriptor) {
DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) nsMd;
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 = data.getCacheManager();
// 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,
systemMd, 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) {