fix cannot download SNAPSHOT version

reviewable/pr18780/r1
NewGyu 10 years ago committed by Greg DeKoenigsberg
parent 05e0b35a45
commit 02258902f9

@ -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))
@ -309,7 +292,7 @@ def main():
repository_url = dict(default=None), repository_url = dict(default=None),
username = dict(default=None), username = dict(default=None),
password = dict(default=None), password = dict(default=None),
state = dict(default="present", choices=["present","absent"]), # TODO - Implement a "latest" state state = dict(default="present", choices=["present","absent"]), # TODO - Implement a "latest" state
dest = dict(default=None), dest = dict(default=None),
) )
) )

Loading…
Cancel
Save