Files
id_configurator/tests/dockerfiles/repos/build_test_jar.py
T
2026-09-04 22:53:35 +02:00

52 lines
1.6 KiB
Python

"""Build a minimal, offline, hand-rolled jar and its pom.xml, laid out as a
Maven-compatible repository, for integration-testing the `java` module of
id-configurator.
No network access and no build backend (maven/gradle) are used: the jar is
a plain zip file assembled with the standard library only, so this script
can run in a minimal Python image with nothing installed.
"""
from __future__ import annotations
import pathlib
import zipfile
GROUP = "org.interdiode"
GROUP_PATH = GROUP.replace(".", "/")
ARTIFACT = "idconfiguratortestpkg"
VERSION = "0.0.1"
OUT_DIR = pathlib.Path("/srv") / GROUP_PATH / ARTIFACT / VERSION
MANIFEST = "Manifest-Version: 1.0\n"
POM = f"""<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>{GROUP}</groupId>
<artifactId>{ARTIFACT}</artifactId>
<version>{VERSION}</version>
<packaging>jar</packaging>
<description>Test-only artifact served by the id-configurator integration tests</description>
</project>
"""
def build_jar(path: pathlib.Path) -> None:
with zipfile.ZipFile(path, "w", zipfile.ZIP_DEFLATED) as archive:
archive.writestr("META-INF/MANIFEST.MF", MANIFEST)
archive.writestr(
"marker.txt",
"test-only artifact served by the id-configurator integration tests\n",
)
def main() -> None:
OUT_DIR.mkdir(parents=True, exist_ok=True)
build_jar(OUT_DIR / f"{ARTIFACT}-{VERSION}.jar")
(OUT_DIR / f"{ARTIFACT}-{VERSION}.pom").write_text(POM, encoding="utf-8")
if __name__ == "__main__":
main()