fosslight-util 2.2.22__tar.gz → 2.2.24__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. {fosslight_util-2.2.22/src/fosslight_util.egg-info → fosslight_util-2.2.24}/PKG-INFO +1 -1
  2. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/pyproject.toml +1 -1
  3. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/_get_downloadable_url.py +119 -43
  4. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/write_cyclonedx.py +60 -3
  5. {fosslight_util-2.2.22 → fosslight_util-2.2.24/src/fosslight_util.egg-info}/PKG-INFO +1 -1
  6. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/tests/test_download_maven.py +54 -4
  7. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/LICENSE +0 -0
  8. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/MANIFEST.in +0 -0
  9. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/README.md +0 -0
  10. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/setup.cfg +0 -0
  11. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/__init__.py +0 -0
  12. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/compare_yaml.py +0 -0
  13. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/constant.py +0 -0
  14. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/correct.py +0 -0
  15. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/cover.py +0 -0
  16. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/download.py +0 -0
  17. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/exclude.py +0 -0
  18. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/get_pom_license.py +0 -0
  19. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/help.py +0 -0
  20. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/merge.py +0 -0
  21. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/oss_item.py +0 -0
  22. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/output_format.py +0 -0
  23. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/parsing_yaml.py +0 -0
  24. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/read_excel.py +0 -0
  25. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/resources/frequentLicenselist.json +0 -0
  26. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/resources/frequent_license_nick_list.json +0 -0
  27. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/resources/licenses.json +0 -0
  28. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/set_log.py +0 -0
  29. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/spdx_licenses.py +0 -0
  30. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/time.py +0 -0
  31. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/timer_thread.py +0 -0
  32. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/write_excel.py +0 -0
  33. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/write_opossum.py +0 -0
  34. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/write_scancodejson.py +0 -0
  35. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/write_spdx.py +0 -0
  36. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/write_txt.py +0 -0
  37. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util/write_yaml.py +0 -0
  38. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util.egg-info/SOURCES.txt +0 -0
  39. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util.egg-info/dependency_links.txt +0 -0
  40. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util.egg-info/entry_points.txt +0 -0
  41. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util.egg-info/requires.txt +0 -0
  42. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/src/fosslight_util.egg-info/top_level.txt +0 -0
  43. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/tests/test_chromium_gitiles.py +0 -0
  44. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/tests/test_cyclonedx.py +0 -0
  45. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/tests/test_decide_checkout.py +0 -0
  46. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/tests/test_download.py +0 -0
  47. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/tests/test_download_packagist.py +0 -0
  48. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/tests/test_download_timeout.py +0 -0
  49. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/tests/test_download_user_agent.py +0 -0
  50. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/tests/test_download_version_attempts.py +0 -0
  51. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/tests/test_download_version_hint.py +0 -0
  52. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/tests/test_opossum.py +0 -0
  53. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/tests/test_spdx.py +0 -0
  54. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/tests/test_spdx_licenses.py +0 -0
  55. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/tests/test_text.py +0 -0
  56. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/tests/test_write_excel_hidden_sheet.py +0 -0
  57. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/tests/test_write_output.py +0 -0
  58. {fosslight_util-2.2.22 → fosslight_util-2.2.24}/tests/test_write_yaml.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fosslight_util
3
- Version: 2.2.22
3
+ Version: 2.2.24
4
4
  Summary: FOSSLight Util
5
5
  Author: LG Electronics
6
6
  License-Expression: Apache-2.0
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
7
7
 
8
8
  [project]
9
9
  name = "fosslight_util"
10
- version = "2.2.22"
10
+ version = "2.2.24"
11
11
  description = "FOSSLight Util"
12
12
  readme = "README.md"
13
13
  license = "Apache-2.0"
@@ -343,19 +343,8 @@ def version_exists(pkg_type, origin_name, version):
343
343
  elif pkg_type == 'maven':
344
344
  # Prefer Central index when available, then probe known Maven hosts for the
345
345
  # exact version so non-Central releases (e.g. Spring milestones) are kept.
346
- try:
347
- r = requests.get(
348
- f'https://api.deps.dev/v3alpha/systems/maven/packages/{origin_name}',
349
- timeout=5,
350
- )
351
- if r.status_code == 200:
352
- versions = r.json().get('versions', [])
353
- for vobj in versions:
354
- vkey = vobj.get('versionKey') or {}
355
- if vkey.get('version') == version:
356
- return True
357
- except Exception as e:
358
- logger.debug(f'Maven Central version index check failed: {e}')
346
+ if _maven_central_index_has(origin_name, version):
347
+ return True
359
348
  group_path, artifact_id = _maven_group_artifact(origin_name)
360
349
  if group_path and artifact_id and version:
361
350
  return _maven_version_available(group_path, artifact_id, version)
@@ -563,18 +552,42 @@ def extract_name_version_from_link(link, checkout_version, allow_latest=True):
563
552
  if pkg_type in ["pypi", "maven", "npm", "npm2", "pub", "go", "packagist"]:
564
553
  if oss_version:
565
554
  try:
566
- if not version_exists(pkg_type, origin_name, oss_version):
567
- if oss_version.startswith('v') and version_exists(pkg_type, origin_name, oss_version[1:]):
568
- logger.info(f'Version {oss_version} not found; using without leading v: {oss_version[1:]}')
569
- oss_version = oss_version[1:]
570
- elif allow_latest:
571
- logger.info(f'Version {oss_version} not found for {oss_name}; will attempt latest fallback')
572
- need_latest = True
573
- else:
574
- logger.info(
575
- f'Version {oss_version} not found for {oss_name}; '
576
- 'not replacing it with latest on this attempt'
577
- )
555
+ chosen = ""
556
+ if pkg_type == "maven":
557
+ # One host at a time: version, then version.RELEASE on that host.
558
+ chosen = _resolve_maven_published_version(origin_name, oss_version)
559
+ if (
560
+ not chosen
561
+ and oss_version.startswith('v')
562
+ and version_exists(pkg_type, origin_name, oss_version[1:])
563
+ ):
564
+ chosen = oss_version[1:]
565
+ elif version_exists(pkg_type, origin_name, oss_version):
566
+ chosen = oss_version
567
+ elif oss_version.startswith('v') and version_exists(
568
+ pkg_type, origin_name, oss_version[1:]
569
+ ):
570
+ chosen = oss_version[1:]
571
+ if chosen:
572
+ if chosen != oss_version:
573
+ if chosen == oss_version[1:]:
574
+ logger.info(
575
+ f'Version {oss_version} not found; '
576
+ f'using without leading v: {chosen}'
577
+ )
578
+ else:
579
+ logger.info(
580
+ f'Version {oss_version} not found for {oss_name}; using {chosen}'
581
+ )
582
+ oss_version = chosen
583
+ elif allow_latest:
584
+ logger.info(f'Version {oss_version} not found for {oss_name}; will attempt latest fallback')
585
+ need_latest = True
586
+ else:
587
+ logger.info(
588
+ f'Version {oss_version} not found for {oss_name}; '
589
+ 'not replacing it with latest on this attempt'
590
+ )
578
591
  except Exception as e:
579
592
  if allow_latest:
580
593
  logger.info(f'Version validation failed ({oss_name}:{oss_version}) {e}; will attempt latest fallback')
@@ -1074,16 +1087,91 @@ def _maven_repo_bases_for(group_path: str) -> tuple[str, ...]:
1074
1087
  return tuple(ordered)
1075
1088
 
1076
1089
 
1090
+ def _maven_central_index_has(origin_name: str, version: str) -> bool:
1091
+ """True when deps.dev lists this exact Maven version."""
1092
+ try:
1093
+ response = requests.get(
1094
+ f'https://api.deps.dev/v3alpha/systems/maven/packages/{origin_name}',
1095
+ timeout=5,
1096
+ )
1097
+ if response.status_code == 200:
1098
+ for vobj in response.json().get('versions', []):
1099
+ vkey = vobj.get('versionKey') or {}
1100
+ if vkey.get('version') == version:
1101
+ return True
1102
+ except Exception as ex:
1103
+ logger.debug(f'Maven Central version index check failed: {ex}')
1104
+ return False
1105
+
1106
+
1107
+ def _maven_release_version(version: str) -> str:
1108
+ if version and not version.upper().endswith(".RELEASE"):
1109
+ return f"{version}.RELEASE"
1110
+ return ""
1111
+
1112
+
1113
+ def _maven_pom_on_repo(repo_base: str, group_path: str, artifact_id: str, version: str) -> bool:
1114
+ pom_url = (
1115
+ f"{repo_base}/{group_path}/{artifact_id}/{version}/"
1116
+ f"{artifact_id}-{version}.pom"
1117
+ )
1118
+ return _maven_http_ok(pom_url)
1119
+
1120
+
1121
+ def _maven_sources_on_repo(repo_base: str, group_path: str, artifact_id: str, version: str) -> str:
1122
+ """Sources jar on one host, or empty. Does not cache a miss."""
1123
+ cached = _MAVEN_SOURCES_PROBE_CACHE.get((group_path, artifact_id, version))
1124
+ if cached and cached.startswith(f"{repo_base}/"):
1125
+ return cached
1126
+ version_dir = f"{repo_base}/{group_path}/{artifact_id}/{version}"
1127
+ for classifier in MAVEN_SOURCE_CLASSIFIERS:
1128
+ sources_url = f"{version_dir}/{artifact_id}-{version}-{classifier}.jar"
1129
+ if _maven_http_ok(sources_url):
1130
+ logger.info(f"Maven sources found: {sources_url}")
1131
+ return sources_url
1132
+ listed = _maven_sources_from_directory(version_dir, artifact_id, version)
1133
+ if listed:
1134
+ logger.info(f"Maven sources found via listing: {listed}")
1135
+ return listed
1136
+ return ""
1137
+
1138
+
1139
+ def _maven_gav_on_repo(repo_base: str, group_path: str, artifact_id: str, version: str) -> bool:
1140
+ """True if this host has the GAV as a sources jar or pom."""
1141
+ found = _maven_sources_on_repo(repo_base, group_path, artifact_id, version)
1142
+ if found:
1143
+ _MAVEN_SOURCES_PROBE_CACHE[(group_path, artifact_id, version)] = found
1144
+ return True
1145
+ return _maven_pom_on_repo(repo_base, group_path, artifact_id, version)
1146
+
1147
+
1148
+ def _resolve_maven_published_version(origin_name: str, version: str) -> str:
1149
+ """Return ``version`` or ``version.RELEASE`` from the first host that has either.
1150
+
1151
+ The plain version is checked on a host before ``.RELEASE`` on that same host.
1152
+ """
1153
+ if not version:
1154
+ return ""
1155
+ if _maven_central_index_has(origin_name, version):
1156
+ return version
1157
+ group_path, artifact_id = _maven_group_artifact(origin_name)
1158
+ if not group_path or not artifact_id:
1159
+ return ""
1160
+ release = _maven_release_version(version)
1161
+ for repo_base in _maven_repo_bases_for(group_path):
1162
+ if _maven_gav_on_repo(repo_base, group_path, artifact_id, version):
1163
+ return version
1164
+ if release and _maven_gav_on_repo(repo_base, group_path, artifact_id, release):
1165
+ return release
1166
+ return ""
1167
+
1168
+
1077
1169
  def _maven_version_available(group_path: str, artifact_id: str, version: str) -> bool:
1078
1170
  """True if a known host has this GAV as sources jar or pom (reuse sources probe cache)."""
1079
1171
  if _probe_maven_sources_jar(group_path, artifact_id, version):
1080
1172
  return True
1081
1173
  for repo_base in _maven_repo_bases_for(group_path):
1082
- pom_url = (
1083
- f"{repo_base}/{group_path}/{artifact_id}/{version}/"
1084
- f"{artifact_id}-{version}.pom"
1085
- )
1086
- if _maven_http_ok(pom_url):
1174
+ if _maven_pom_on_repo(repo_base, group_path, artifact_id, version):
1087
1175
  return True
1088
1176
  return False
1089
1177
 
@@ -1143,21 +1231,9 @@ def _probe_maven_sources_jar(group_path: str, artifact_id: str, version: str) ->
1143
1231
 
1144
1232
  found = ""
1145
1233
  for repo_base in _maven_repo_bases_for(group_path):
1146
- version_dir = f"{repo_base}/{group_path}/{artifact_id}/{version}"
1147
- for classifier in MAVEN_SOURCE_CLASSIFIERS:
1148
- sources_url = f"{version_dir}/{artifact_id}-{version}-{classifier}.jar"
1149
- if _maven_http_ok(sources_url):
1150
- logger.info(f"Maven sources found: {sources_url}")
1151
- found = sources_url
1152
- break
1234
+ found = _maven_sources_on_repo(repo_base, group_path, artifact_id, version)
1153
1235
  if found:
1154
1236
  break
1155
- # Directory listing only when classifier URLs miss; bounded by MAVEN_HTTP_TIMEOUT.
1156
- listed = _maven_sources_from_directory(version_dir, artifact_id, version)
1157
- if listed:
1158
- logger.info(f"Maven sources found via listing: {listed}")
1159
- found = listed
1160
- break
1161
1237
 
1162
1238
  _MAVEN_SOURCES_PROBE_CACHE[cache_key] = found
1163
1239
  return found
@@ -8,6 +8,7 @@ import os
8
8
  import logging
9
9
  import re
10
10
  from pathlib import Path
11
+ from urllib.parse import quote, unquote
11
12
  from fosslight_util.constant import (FOSSLIGHT_BINARY, FOSSLIGHT_DEPENDENCY, FOSSLIGHT_SCANNER,
12
13
  FOSSLIGHT_SOURCE, LOGGER_NAME)
13
14
  import traceback
@@ -66,6 +67,62 @@ except Exception as error:
66
67
  logger.info(f'Failed to import cyclonedx-python-lib: {error}')
67
68
 
68
69
 
70
+ class _DependencyPurl(PackageURL if _cyclonedx_import_error is None else object):
71
+ """Serialize parsed fields with PURL encoding, without folding npm case."""
72
+
73
+ def to_string(self, encode=True):
74
+ # PURL specification 5.4: ':' is allowed only in qualifier values; other
75
+ # components must percent-encode it and other separators used as data.
76
+ def encode_component(value, allow_colon=False):
77
+ if not encode:
78
+ return value
79
+ safe = '.-_~:' if allow_colon else '.-_~'
80
+ return quote(str(value), safe=safe)
81
+
82
+ parts = ['pkg:', self.type, '/']
83
+ if self.namespace:
84
+ parts.extend(('/'.join(encode_component(segment) for segment in self.namespace.split('/')), '/'))
85
+ parts.append(encode_component(self.name))
86
+ if self.version:
87
+ parts.extend(('@', encode_component(self.version)))
88
+ if self.qualifiers:
89
+ parts.extend(('?', '&'.join(
90
+ f'{key}={encode_component(value, allow_colon=True)}'
91
+ for key, value in sorted(self.qualifiers.items()) if value)))
92
+ if self.subpath:
93
+ parts.extend(('#', '/'.join(encode_component(segment) for segment in self.subpath.split('/'))))
94
+ return ''.join(parts)
95
+
96
+
97
+ def _parse_dependency_purl(value):
98
+ parsed = PackageURL.from_string(value)
99
+ if parsed.type == 'npm':
100
+ package_path = value.split('?', 1)[0].split('#', 1)[0]
101
+ package_path = package_path.split(':', 1)[1].strip().lstrip('/').rstrip('/').split('/', 1)[1]
102
+ # Remove the version before splitting the namespace/name. Its decoded
103
+ # or unencoded value may contain slashes (e.g., link:../local-lib). A raw
104
+ # '@' after the first character is the version delimiter (this also covers
105
+ # an empty version, e.g. 'name@'). A leading '@' is the npm scope marker
106
+ # (e.g. '@scope/name') and must be kept.
107
+ version_idx = package_path.find('@', 1)
108
+ if version_idx != -1:
109
+ package_path = package_path[:version_idx].rstrip('/')
110
+ namespace = unquote(package_path.rsplit('/', 1)[0]) if '/' in package_path else None
111
+ name = unquote(package_path.rsplit('/', 1)[-1])
112
+ parsed = PackageURL(
113
+ type=parsed.type, namespace=namespace, name=name,
114
+ version=parsed.version, qualifiers=parsed.qualifiers, subpath=parsed.subpath,
115
+ normalize_purl=False,
116
+ )
117
+ # Normalize the output, not the source spelling. Parsed fields also allow
118
+ # dependency lookup to match equivalent encoded and unencoded references.
119
+ return _DependencyPurl(
120
+ type=parsed.type, namespace=parsed.namespace, name=parsed.name,
121
+ version=parsed.version, qualifiers=parsed.qualifiers, subpath=parsed.subpath,
122
+ normalize_purl=False,
123
+ )
124
+
125
+
69
126
  def write_cyclonedx(output_file_without_ext, output_extension, scan_item, scanner_covers=None):
70
127
  success = True
71
128
  error_msg = ''
@@ -119,7 +176,7 @@ def write_cyclonedx(output_file_without_ext, output_extension, scan_item, scanne
119
176
  if oss_item.copyright != '':
120
177
  comp.copyright = oss_item.copyright
121
178
  if scanner_name == FOSSLIGHT_DEPENDENCY and file_item.purl:
122
- comp.purl = PackageURL.from_string(file_item.purl)
179
+ comp.purl = _parse_dependency_purl(file_item.purl)
123
180
  if scanner_name != FOSSLIGHT_DEPENDENCY:
124
181
  if file_item.checksum != '0':
125
182
  comp.hashes = [HashType(alg=HashAlgorithm.SHA_1, content=file_item.checksum)]
@@ -164,11 +221,11 @@ def write_cyclonedx(output_file_without_ext, output_extension, scan_item, scanne
164
221
 
165
222
  if len(bom.components) > 0:
166
223
  for comp_purl in relation_tree:
167
- comp = bom.get_component_by_purl(PackageURL.from_string(comp_purl))
224
+ comp = bom.get_component_by_purl(_parse_dependency_purl(comp_purl))
168
225
  if comp:
169
226
  dep_comp_list = []
170
227
  for dep_comp_purl in relation_tree[comp_purl]:
171
- dep_comp = bom.get_component_by_purl(PackageURL.from_string(dep_comp_purl))
228
+ dep_comp = bom.get_component_by_purl(_parse_dependency_purl(dep_comp_purl))
172
229
  if dep_comp:
173
230
  dep_comp_list.append(dep_comp)
174
231
  bom.register_dependency(comp, dep_comp_list)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fosslight_util
3
- Version: 2.2.22
3
+ Version: 2.2.24
4
4
  Summary: FOSSLight Util
5
5
  Author: LG Electronics
6
6
  License-Expression: Apache-2.0
@@ -50,8 +50,8 @@ def test_version_exists_keeps_non_central_maven_version(monkeypatch):
50
50
  def test_extract_keeps_exact_version_when_found_on_candidate_repo(monkeypatch):
51
51
  monkeypatch.setattr(
52
52
  downloadable_url,
53
- "version_exists",
54
- lambda pkg_type, origin_name, version: version == "6.2.0-M1",
53
+ "_resolve_maven_published_version",
54
+ lambda origin_name, version: version if version == "6.2.0-M1" else "",
55
55
  )
56
56
  monkeypatch.setattr(
57
57
  downloadable_url,
@@ -69,12 +69,62 @@ def test_extract_keeps_exact_version_when_found_on_candidate_repo(monkeypatch):
69
69
  assert link.endswith("/spring-core/6.2.0-M1")
70
70
 
71
71
 
72
- def test_extract_falls_back_to_latest_only_when_no_repo_has_version(monkeypatch):
72
+ def test_extract_tries_release_on_same_repo_before_next(monkeypatch):
73
+ milestone = "https://repo.spring.io/milestone"
74
+ central = "https://repo1.maven.org/maven2"
75
+ seen = []
76
+ downloadable_url._MAVEN_SOURCES_PROBE_CACHE.clear()
73
77
  monkeypatch.setattr(
74
78
  downloadable_url,
75
- "version_exists",
79
+ "_maven_repo_bases_for",
80
+ lambda _group_path: (milestone, central),
81
+ )
82
+ monkeypatch.setattr(
83
+ downloadable_url,
84
+ "_maven_central_index_has",
76
85
  lambda *_args, **_kwargs: False,
77
86
  )
87
+
88
+ def fake_http_ok(url, timeout=None):
89
+ seen.append(url)
90
+ return url == (
91
+ f"{milestone}/org/springframework/boot/spring-boot-configuration-processor/"
92
+ "2.3.2.RELEASE/spring-boot-configuration-processor-2.3.2.RELEASE-sources.jar"
93
+ )
94
+
95
+ monkeypatch.setattr(downloadable_url, "_maven_http_ok", fake_http_ok)
96
+ monkeypatch.setattr(
97
+ downloadable_url,
98
+ "_maven_sources_from_directory",
99
+ lambda *_args, **_kwargs: "",
100
+ )
101
+ monkeypatch.setattr(
102
+ downloadable_url,
103
+ "get_latest_package_version",
104
+ lambda *_args, **_kwargs: pytest.fail("latest fallback must not run"),
105
+ )
106
+
107
+ name, version, link, pkg_type = downloadable_url.extract_name_version_from_link(
108
+ "https://mvnrepository.com/artifact/org.springframework.boot/"
109
+ "spring-boot-configuration-processor",
110
+ "2.3.2",
111
+ )
112
+ assert pkg_type == "maven"
113
+ assert name == "org.springframework.boot:spring-boot-configuration-processor"
114
+ assert version == "2.3.2.RELEASE"
115
+ assert link.endswith("/spring-boot-configuration-processor/2.3.2.RELEASE")
116
+ release_at = next(i for i, url in enumerate(seen) if "2.3.2.RELEASE" in url)
117
+ assert any("/2.3.2/" in url for url in seen[:release_at])
118
+ assert all("2.3.2.RELEASE" not in url for url in seen[:release_at])
119
+ assert all(not url.startswith(central) for url in seen)
120
+
121
+
122
+ def test_extract_falls_back_to_latest_only_when_no_repo_has_version(monkeypatch):
123
+ monkeypatch.setattr(
124
+ downloadable_url,
125
+ "_resolve_maven_published_version",
126
+ lambda *_args, **_kwargs: "",
127
+ )
78
128
  monkeypatch.setattr(
79
129
  downloadable_url,
80
130
  "get_latest_package_version",
File without changes