Skip to content

Commit 7932d1a

Browse files
committed
Fix Maven download URL and improve logs
The Maven URL to download a package was wrong when the package groupID had dots inside. We must replace them by `/`. For example, without this MR, to download the package `javax.servlet/servlet-api`, the URL used was: - https://repo1.maven.org/maven2/javax.servlet/servlet-api/3.0-alpha-1/servlet-api-3.0-alpha-1.jar But, if tested using curl: ``` $ curl --head https://repo1.maven.org/maven2/javax.servlet/servlet-api/3.0-alpha-1/servlet-api-3.0-alpha-1.jar HTTP/2 404 ... ``` The right URL is: - https://repo1.maven.org/maven2/javax/servlet/servlet-api/3.0-alpha-1/servlet-api-3.0-alpha-1.jar And if tested with curl: ``` $ curl --head https://repo1.maven.org/maven2/javax/servlet/servlet-api/3.0-alpha-1/servlet-api-3.0-alpha-1.jar HTTP/2 200 ... x-checksum-md5: fe58aea60c6acf7cdf79302d568bc9a8 x-checksum-sha1: 7b491267924e8c81f4f9378caba0ee03423948ca ... ``` This MR also improves logs. Found while working on it/package-registry#27
1 parent 6837150 commit 7932d1a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/e3/maven.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ def __init__(self, group: str, name: str, version: str) -> None:
2121
self.package_group = group
2222
self.package_name = name
2323
self.version = version
24-
self.url = f"https://repo1.maven.org/maven2/{group}/{name}/{version}/{filename}"
24+
self.url = (
25+
f"https://repo1.maven.org/maven2/{group.replace('.', '/')}/{name}/{version}"
26+
f"/{filename}"
27+
)
2528

2629
# To get the expected checksum of the current file, we need to make an
2730
# additonnal HEAD request. This is because maven send the checksum directly on
@@ -32,7 +35,7 @@ def __init__(self, group: str, name: str, version: str) -> None:
3235
sha1_checksum = hdrs.get("x-checksum-sha1")
3336
md5_checksum = hdrs.get("x-checksum-md5")
3437
if not md5_checksum and not sha1_checksum:
35-
raise RuntimeError("No checksum provided")
38+
raise RuntimeError(f"No checksum provided for {group}/{self.filename}")
3639

3740
# No 'elif' because maven can send both together into HTTP headers.
3841
if md5_checksum:

0 commit comments

Comments
 (0)