Message.verbose("\t" + getName() + "looking for artifact " + artifact
+ " (is " + artifacts[i] + " in system namespace)");
}
long start = System.currentTimeMillis();
try {
ResolvedResource artifactRef = getArtifactRef(artifact, null);
if (artifactRef != null) {
origin = new ArtifactOrigin(artifactRef.getResource().isLocal(),
artifactRef.getResource().getName());
if (useOrigin && artifactRef.getResource().isLocal()) {
Message.verbose("\t[NOT REQUIRED] " + artifacts[i]);
cacheManager.saveArtifactOrigin(artifacts[i], origin);
archiveFile = cacheManager.getArchiveFileInCache(artifacts[i],
origin);
adr.setDownloadStatus(DownloadStatus.NO);
adr.setSize(archiveFile.length());
adr.setArtifactOrigin(origin);
} else {
// refresh archive file now that we better now its origin
archiveFile = cacheManager.getArchiveFileInCache(artifacts[i],
origin, useOrigin);
if (ResourceHelper.equals(artifactRef.getResource(), archiveFile)) {
Message.error("invalid configuration for resolver '"
+ getName()
+ "': pointing artifacts to ivy cache is forbidden !");
return null;
}
Message.info("downloading " + artifactRef.getResource() + " ...");
if (eventManager != null) {
eventManager.fireIvyEvent(new StartArtifactDownloadEvent(this,
artifacts[i], origin));
}
File tmp = cacheManager.getArchiveFileInCache(new DefaultArtifact(
artifacts[i].getModuleRevisionId(), artifacts[i]
.getPublicationDate(), artifacts[i].getName(),
artifacts[i].getType(), artifacts[i].getExt() + ".part",
artifacts[i].getExtraAttributes()), origin, useOrigin);
// deal with artifact with url special case
if (artifactRef.getResource().getName().equals(
String.valueOf(artifacts[i].getUrl()))) {
Message.verbose("\t" + getName() + ": downloading "
+ artifactRef.getResource().getName());
Message.debug("\t\tto " + tmp);
if (tmp.getParentFile() != null) {
tmp.getParentFile().mkdirs();
}
extartifactrep.get(artifactRef.getResource().getName(), tmp);
adr.setSize(tmp.length());
} else {
adr.setSize(getAndCheck(artifactRef.getResource(), tmp));
}
if (!tmp.renameTo(archiveFile)) {
Message.warn("\t[FAILED ] " + artifacts[i]
+ " impossible to move temp file to definitive one ("
+ (System.currentTimeMillis() - start) + "ms)");