utils/dep_freshness/registries/maven.py
Krzysztof kuhy Rudnicki a4ea305164 dep_freshness: Gradle ecosystem -- version catalogs, wrapper, Maven registries
The gate had no way to read a Gradle build, which left the two Kotlin
forks (tachiyomisy, syncyomi-src) outside the fleet-wide rule.

- parsers/gradle.py reads gradle/libs.versions.toml ([libraries] and
  [plugins] in every shape: inline string, module + version.ref,
  group/name/version, rich {strictly|require|prefer} tables) into
  `maven:<group>:<artifact>` deps, pointing the fix at the [versions]
  line when a ref is used; BOM-managed entries without a version are
  skipped. gradle-wrapper.properties becomes `toolchain:gradle`.
- registries/maven.py asks Google Maven, Central and the plugin portal
  in that order, reading the full <versions> list -- AndroidX writes
  alphas into <latest>. Plugins resolve through their marker artifact.
- registries/toolchain.gradle_latest reads services.gradle.org.
- http.get_text shares the transport with get_json (XML bodies).
- Templates: the pre-commit `files:` and the CI cache key know the
  catalog. 100% branch on every new file; fixtures only.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Yc4TiPjhbQLfH35QBPfrbP
2026-09-12 19:10:42 +02:00

56 lines
1.9 KiB
Python

"""Maven repositories: newest stable of `group:artifact`, from maven-metadata.
Three repositories, asked in order until one knows the artifact: Google
Maven (every `androidx.*` and `com.android.*` artifact lives ONLY there),
Maven Central, and the Gradle plugin portal (plugin marker artifacts
`<id>:<id>.gradle.plugin`). A 404 means "not here", not "not anywhere", so
it moves on; anything else surfaces as `Offline` from the HTTP layer.
`<latest>` and `<release>` in the metadata are not trusted: AndroidX writes
`1.2.0-alpha03` into `<latest>` routinely. The full `<versions>` list goes
through `newest_stable` like every other ecosystem.
"""
from __future__ import annotations
from xml.etree import ElementTree
from dep_freshness._tables import MAVEN_REPOS
from dep_freshness.registries.http import get_text
from dep_freshness.versions import newest_stable
def metadata_url(repo: str, name: str) -> str | None:
"""`.../group/path/artifact/maven-metadata.xml`, or None for a bad name."""
group, sep, artifact = name.partition(":")
if not sep or not group or not artifact:
return None
return f"{repo}{group.replace('.', '/')}/{artifact}/maven-metadata.xml"
def versions_in(xml: str) -> list[str]:
"""Every `<version>` in a maven-metadata document; [] when unparseable."""
try:
root = ElementTree.fromstring(xml)
except ElementTree.ParseError:
return []
return [
(node.text or "").strip()
for node in root.iter("version")
if node.text and node.text.strip()
]
def latest(name: str) -> str | None:
for repo in MAVEN_REPOS:
url = metadata_url(repo, name)
if url is None:
return None
body = get_text(url)
if body is None:
continue
stable = newest_stable(versions_in(body))
if stable is not None:
return stable
return None