Merge pull request #433 from NewGyu/devel

fix cannot download SNAPSHOT version
This commit is contained in:
Greg DeKoenigsberg 2015-06-09 13:07:37 -04:00
commit 8929d5c6a1

View file

@ -184,29 +184,12 @@ class MavenDownloader:
if artifact.is_snapshot(): if artifact.is_snapshot():
path = "/%s/maven-metadata.xml" % (artifact.path()) path = "/%s/maven-metadata.xml" % (artifact.path())
xml = self._request(self.base + path, "Failed to download maven-metadata.xml", lambda r: etree.parse(r)) xml = self._request(self.base + path, "Failed to download maven-metadata.xml", lambda r: etree.parse(r))
basexpath = "/metadata/versioning/" timestamp = xml.xpath("/metadata/versioning/snapshot/timestamp/text()")[0]
p = xml.xpath(basexpath + "/snapshotVersions/snapshotVersion") buildNumber = xml.xpath("/metadata/versioning/snapshot/buildNumber/text()")[0]
if p: return self._uri_for_artifact(artifact, artifact.version.replace("SNAPSHOT", timestamp + "-" + buildNumber))
return self._find_matching_artifact(p, artifact)
else: else:
return self._uri_for_artifact(artifact) return self._uri_for_artifact(artifact)
def _find_matching_artifact(self, elems, artifact):
filtered = filter(lambda e: e.xpath("extension/text() = '%s'" % artifact.extension), elems)
if artifact.classifier:
filtered = filter(lambda e: e.xpath("classifier/text() = '%s'" % artifact.classifier), elems)
if len(filtered) > 1:
print(
"There was more than one match. Selecting the first one. Try adding a classifier to get a better match.")
elif not len(filtered):
print("There were no matches.")
return None
elem = filtered[0]
value = elem.xpath("value/text()")
return self._uri_for_artifact(artifact, value[0])
def _uri_for_artifact(self, artifact, version=None): def _uri_for_artifact(self, artifact, version=None):
if artifact.is_snapshot() and not version: if artifact.is_snapshot() and not version:
raise ValueError("Expected uniqueversion for snapshot artifact " + str(artifact)) raise ValueError("Expected uniqueversion for snapshot artifact " + str(artifact))