From 68a31c122fa6e66f996fd2f6e369a04633e22863 Mon Sep 17 00:00:00 2001 From: Acriss Date: Thu, 19 Nov 2026 15:28:26 +0100 Subject: [PATCH 1/5] Pin the exact Temurin build in CI setup-java took the JDK preinstalled on the ubuntu-24.04 and windows-2025 runners whenever it matched the requested version, without asking Adoptium. CI now names the exact Temurin build (25.0.5+8), which setup-java installs or fails on: a wheel can no longer bundle another build with the same version numbers. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yaml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a84561f..dd15760 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -46,6 +46,11 @@ jobs: - runner: windows-2025 platform-tag: win_amd64 runs-on: ${{ matrix.runner }} + env: + # The exact Temurin build to bundle, in OpenJDK notation, such as 25.0.5+8 or 25.0.5.1+2. + # Its first 3 numbers are the ones of the version in pyproject.toml, which `test_java_version` checks. + # setup-java installs this build or fails: it never falls back to another build with the same numbers, such as one preinstalled on the runner. + TEMURIN_VERSION: 25.0.5+8 steps: - uses: actions/checkout@v7.0.1 with: @@ -54,18 +59,10 @@ jobs: with: version-file: pyproject.toml - - id: get-java-version - run: | - uv run python - >> "$GITHUB_OUTPUT" <<'EOF' - from jdk4py import JAVA_VERSION - - version = ".".join(str(number) for number in JAVA_VERSION) - print(f"version={version}") - EOF - uses: actions/setup-java@v6.2.0 with: distribution: temurin - java-version: ${{ steps.get-java-version.outputs.version }} + java-version: ${{ env.TEMURIN_VERSION }} - run: uv run python build_java_runtime.py - if: github.event_name == 'pull_request' From 675ee94ba28d32702cb2177cf3ffc4c2a763372d Mon Sep 17 00:00:00 2001 From: Acriss Date: Thu, 19 Nov 2026 15:29:10 +0100 Subject: [PATCH 2/5] Expose the exact JDK version as JAVA_FULL_VERSION `JAVA_VERSION` keeps the first 3 numbers of the JDK version, taken from the package version: its fourth number counts the jdk4py releases of the line. `JAVA_FULL_VERSION` is the exact JDK version with its build number, such as 25.0.5.1+2. jlink only keeps the version without the build number in the `release` file it writes, so `build_java_runtime.py` copies `JAVA_RUNTIME_VERSION` from the source JDK's `release` file with `--release-info`. `JAVA_FULL_VERSION` reads it on first access and drops the optional suffix, such as `-LTS`. The README documents what each version number means and which JDK build each release bundles. Co-Authored-By: Claude Opus 5.5 --- README.md | 17 ++++++++++++++--- build_java_runtime.py | 20 ++++++++++++++++---- src/jdk4py/__init__.py | 26 ++++++++++++++++++++++++++ tests/test_runtime.py | 9 ++++++++- 4 files changed, 64 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c0a364a..9768a00 100644 --- a/README.md +++ b/README.md @@ -32,13 +32,15 @@ uvx jdk4py java -version ### Python API ```python ->>> from jdk4py import JAVA, JAVA_HOME, JAVA_VERSION +>>> from jdk4py import JAVA, JAVA_FULL_VERSION, JAVA_HOME, JAVA_VERSION >>> JAVA_HOME PosixPath('/Users/johndoe/dev/jdk4py/jdk4py/java-runtime') >>> JAVA PosixPath('/Users/johndoe/dev/jdk4py/jdk4py/java-runtime/bin/java') >>> JAVA_VERSION (25, 0, 5) +>>> JAVA_FULL_VERSION +'25.0.5+8' >>> from subprocess import run >>> some_java_options = ["-Xmx16G", "-Xms2G"] >>> run( @@ -54,5 +56,14 @@ PosixPath('/Users/johndoe/dev/jdk4py/jdk4py/java-runtime/bin/java') `jdk4py`'s version contains 4 numbers: -- The first 3 numbers correspond to the JDK version. -- The fourth number is the library API version. +- The first 3 numbers are the version line of the bundled JDK, such as 25.0.5. `JAVA_VERSION` holds them. +- The fourth number counts the releases of jdk4py in that line. A new release can bundle another build of the JDK, such as an OpenJDK patch release, or change the library. + +The fourth number is not part of the JDK version, even when they look alike. +`JAVA_FULL_VERSION` holds the exact version of the bundled JDK with its build number, such as 25.0.5.1+2: the version can have more than 3 numbers. + +| jdk4py | JDK | +| -------- | --------- | +| 25.0.5.0 | 25.0.5+8 | +| 25.0.2.1 | 25.0.2+10 | +| 25.0.2.0 | 25.0.2+10 | diff --git a/build_java_runtime.py b/build_java_runtime.py index db45065..1977703 100644 --- a/build_java_runtime.py +++ b/build_java_runtime.py @@ -1,9 +1,10 @@ from collections.abc import Collection -from shutil import rmtree +from pathlib import Path +from shutil import rmtree, which from subprocess import run from typing import Final, Literal, TypeAlias, get_args -from jdk4py import JAVA_HOME +from jdk4py import JAVA_HOME, _get_release_property _ADDED_MODULES: Final = frozenset( { @@ -52,16 +53,27 @@ def build_java_runtime() -> None: + jlink = which("jlink") + if jlink is None: + message = "jlink not found." + raise RuntimeError(message) + # The JDK that jlink comes from, whose `release` file has the version with its build number, such as 25.0.5.1+2-LTS. + # jlink only keeps the version without it, so it is added back for `JAVA_FULL_VERSION`. + source_java_home = Path(jlink).resolve().parent.parent + runtime_version = _get_release_property(source_java_home, "JAVA_RUNTIME_VERSION") + rmtree(JAVA_HOME, ignore_errors=True) run( # noqa: S603 - [ # noqa: S607 - "jlink", + [ + jlink, "--no-man-pages", "--strip-debug", "--add-modules", ",".join(_ADDED_MODULES), f"--include-locales={','.join(_INCLUDED_LOCALES)}", + "--release-info", + f'add:JAVA_RUNTIME_VERSION="{runtime_version}"', "--output", JAVA_HOME, ], diff --git a/src/jdk4py/__init__.py b/src/jdk4py/__init__.py index 2e96638..a55e4ff 100644 --- a/src/jdk4py/__init__.py +++ b/src/jdk4py/__init__.py @@ -1,5 +1,7 @@ """JDK packaged for Python.""" +import re as _re +from functools import cache as _cache from importlib.metadata import version as _version from pathlib import Path as _Path from typing import Final as _Final @@ -14,3 +16,27 @@ int(number) for number in _VERSION.split(".") ] JAVA_VERSION: _Final = _JAVA_MAJOR, _JAVA_MINOR, _JAVA_PATCH + + +def _get_release_property(java_home: _Path, key: str, /) -> str: + release_file = java_home / "release" + for line in release_file.read_text(encoding="utf-8").splitlines(): + line_key, _, value = line.partition("=") + if line_key == key: + return value.strip('"') + raise RuntimeError(f"No {key} in {release_file}.") + + +@_cache +def _get_java_full_version() -> str: + runtime_version = _get_release_property(JAVA_HOME, "JAVA_RUNTIME_VERSION") + # Drop the optional suffix after the build number, such as `-LTS` in 25.0.5.1+2-LTS. + return _re.sub(r"(\+\d+)-.*$", r"\1", runtime_version) + + +def __getattr__(name: str) -> str: + # `JAVA_FULL_VERSION` is read from the Java runtime on first access: + # the runtime does not exist yet when `build_java_runtime.py` imports this module. + if name == "JAVA_FULL_VERSION": + return _get_java_full_version() + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") diff --git a/tests/test_runtime.py b/tests/test_runtime.py index de0070b..5f6dc79 100644 --- a/tests/test_runtime.py +++ b/tests/test_runtime.py @@ -5,7 +5,7 @@ from typing import Final, get_args from build_java_runtime import _INCLUDED_LOCALES, _RegionSpecificLocale -from jdk4py import JAVA, JAVA_VERSION +from jdk4py import JAVA, JAVA_FULL_VERSION, JAVA_VERSION _TEST_RESOURCES_DIRECTORY: Final = Path(__file__).parent / "resources" @@ -22,6 +22,13 @@ def test_java_version() -> None: assert match, f"Unexpected output:\n{output}" version = match.group("version") assert tuple(int(number) for number in version.split(".")[:3]) == JAVA_VERSION + build_match = re.search(r"\(build (?P[^)]+)\)", output) + assert build_match, f"Unexpected output:\n{output}" + # The build can end with an optional suffix, such as `-LTS` in 25.0.5.1+2-LTS. + assert re.fullmatch( + rf"{re.escape(JAVA_FULL_VERSION)}(-.+)?", build_match.group("build") + ) + assert JAVA_FULL_VERSION.startswith(f"{version}+") def _run_jar(name: str, /) -> str: From 353598b5b48de3631b8ebf7e6b3f9262cf3e3cee Mon Sep 17 00:00:00 2001 From: Acriss Date: Thu, 19 Nov 2026 15:29:31 +0100 Subject: [PATCH 3/5] Upgrade to JDK 25.0.5.1 to fix CVE-2026-114938 JDK 25.0.5.1 fixes CVE-2026-114938 ("Java4Shell"). It is released as jdk4py 25.0.5.1: `JAVA_VERSION` is `(25, 0, 5)` and `JAVA_FULL_VERSION` is `"25.0.5.1+2"`. CI bundles Temurin 25.0.5.1+2. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yaml | 2 +- README.md | 13 +++++++------ pyproject.toml | 2 +- uv.lock | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index dd15760..3f5ce0e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -50,7 +50,7 @@ jobs: # The exact Temurin build to bundle, in OpenJDK notation, such as 25.0.5+8 or 25.0.5.1+2. # Its first 3 numbers are the ones of the version in pyproject.toml, which `test_java_version` checks. # setup-java installs this build or fails: it never falls back to another build with the same numbers, such as one preinstalled on the runner. - TEMURIN_VERSION: 25.0.5+8 + TEMURIN_VERSION: 25.0.5.1+2 steps: - uses: actions/checkout@v7.0.1 with: diff --git a/README.md b/README.md index 9768a00..9ae8ed9 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ PosixPath('/Users/johndoe/dev/jdk4py/jdk4py/java-runtime/bin/java') >>> JAVA_VERSION (25, 0, 5) >>> JAVA_FULL_VERSION -'25.0.5+8' +'25.0.5.1+2' >>> from subprocess import run >>> some_java_options = ["-Xmx16G", "-Xms2G"] >>> run( @@ -62,8 +62,9 @@ PosixPath('/Users/johndoe/dev/jdk4py/jdk4py/java-runtime/bin/java') The fourth number is not part of the JDK version, even when they look alike. `JAVA_FULL_VERSION` holds the exact version of the bundled JDK with its build number, such as 25.0.5.1+2: the version can have more than 3 numbers. -| jdk4py | JDK | -| -------- | --------- | -| 25.0.5.0 | 25.0.5+8 | -| 25.0.2.1 | 25.0.2+10 | -| 25.0.2.0 | 25.0.2+10 | +| jdk4py | JDK | +| -------- | ---------- | +| 25.0.5.1 | 25.0.5.1+2 | +| 25.0.5.0 | 25.0.5+8 | +| 25.0.2.1 | 25.0.2+10 | +| 25.0.2.0 | 25.0.2+10 | diff --git a/pyproject.toml b/pyproject.toml index 53d122a..b795fbd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,7 @@ license-files = ["LICENSE"] name = "jdk4py" readme = "README.md" requires-python = ">=3.10" -version = "25.0.5.0" +version = "25.0.5.1" [project.scripts] jdk4py = "jdk4py.__main__:main" diff --git a/uv.lock b/uv.lock index 43bb638..ba758a0 100644 --- a/uv.lock +++ b/uv.lock @@ -34,7 +34,7 @@ wheels = [ [[package]] name = "jdk4py" -version = "25.0.5.0" +version = "25.0.5.1" source = { editable = "." } [package.dev-dependencies] From 9c999f6cad38e5f67d4766d54041e13b091063d6 Mon Sep 17 00:00:00 2001 From: Thibault Derousseaux <6574550+tibdex@users.noreply.github.com> Date: Fri, 20 Nov 2026 14:26:28 -0500 Subject: [PATCH 4/5] Keep it simple --- .github/workflows/ci.yaml | 7 +------ README.md | 19 ++++--------------- build_java_runtime.py | 20 ++++---------------- prek.toml | 6 +++--- pyproject.toml | 2 +- src/jdk4py/__init__.py | 26 -------------------------- tests/test_runtime.py | 9 +-------- 7 files changed, 14 insertions(+), 75 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3f5ce0e..6006336 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -46,11 +46,6 @@ jobs: - runner: windows-2025 platform-tag: win_amd64 runs-on: ${{ matrix.runner }} - env: - # The exact Temurin build to bundle, in OpenJDK notation, such as 25.0.5+8 or 25.0.5.1+2. - # Its first 3 numbers are the ones of the version in pyproject.toml, which `test_java_version` checks. - # setup-java installs this build or fails: it never falls back to another build with the same numbers, such as one preinstalled on the runner. - TEMURIN_VERSION: 25.0.5.1+2 steps: - uses: actions/checkout@v7.0.1 with: @@ -62,7 +57,7 @@ jobs: - uses: actions/setup-java@v6.2.0 with: distribution: temurin - java-version: ${{ env.TEMURIN_VERSION }} + java-version: 25.0.5.1+2 - run: uv run python build_java_runtime.py - if: github.event_name == 'pull_request' diff --git a/README.md b/README.md index 9ae8ed9..860f7c0 100644 --- a/README.md +++ b/README.md @@ -32,15 +32,13 @@ uvx jdk4py java -version ### Python API ```python ->>> from jdk4py import JAVA, JAVA_FULL_VERSION, JAVA_HOME, JAVA_VERSION +>>> from jdk4py import JAVA, JAVA_HOME, JAVA_VERSION >>> JAVA_HOME PosixPath('/Users/johndoe/dev/jdk4py/jdk4py/java-runtime') >>> JAVA PosixPath('/Users/johndoe/dev/jdk4py/jdk4py/java-runtime/bin/java') >>> JAVA_VERSION (25, 0, 5) ->>> JAVA_FULL_VERSION -'25.0.5.1+2' >>> from subprocess import run >>> some_java_options = ["-Xmx16G", "-Xms2G"] >>> run( @@ -56,15 +54,6 @@ PosixPath('/Users/johndoe/dev/jdk4py/jdk4py/java-runtime/bin/java') `jdk4py`'s version contains 4 numbers: -- The first 3 numbers are the version line of the bundled JDK, such as 25.0.5. `JAVA_VERSION` holds them. -- The fourth number counts the releases of jdk4py in that line. A new release can bundle another build of the JDK, such as an OpenJDK patch release, or change the library. - -The fourth number is not part of the JDK version, even when they look alike. -`JAVA_FULL_VERSION` holds the exact version of the bundled JDK with its build number, such as 25.0.5.1+2: the version can have more than 3 numbers. - -| jdk4py | JDK | -| -------- | ---------- | -| 25.0.5.1 | 25.0.5.1+2 | -| 25.0.5.0 | 25.0.5+8 | -| 25.0.2.1 | 25.0.2+10 | -| 25.0.2.0 | 25.0.2+10 | +- The first 3 numbers are the first 3 numbers of the bundled JDK version. + `JAVA_VERSION` holds them. +- The fourth number starts at 0 and goes up by 1 with each release that keeps the first 3, for instance to bundle a JDK patch or to change the library. diff --git a/build_java_runtime.py b/build_java_runtime.py index 1977703..db45065 100644 --- a/build_java_runtime.py +++ b/build_java_runtime.py @@ -1,10 +1,9 @@ from collections.abc import Collection -from pathlib import Path -from shutil import rmtree, which +from shutil import rmtree from subprocess import run from typing import Final, Literal, TypeAlias, get_args -from jdk4py import JAVA_HOME, _get_release_property +from jdk4py import JAVA_HOME _ADDED_MODULES: Final = frozenset( { @@ -53,27 +52,16 @@ def build_java_runtime() -> None: - jlink = which("jlink") - if jlink is None: - message = "jlink not found." - raise RuntimeError(message) - # The JDK that jlink comes from, whose `release` file has the version with its build number, such as 25.0.5.1+2-LTS. - # jlink only keeps the version without it, so it is added back for `JAVA_FULL_VERSION`. - source_java_home = Path(jlink).resolve().parent.parent - runtime_version = _get_release_property(source_java_home, "JAVA_RUNTIME_VERSION") - rmtree(JAVA_HOME, ignore_errors=True) run( # noqa: S603 - [ - jlink, + [ # noqa: S607 + "jlink", "--no-man-pages", "--strip-debug", "--add-modules", ",".join(_ADDED_MODULES), f"--include-locales={','.join(_INCLUDED_LOCALES)}", - "--release-info", - f'add:JAVA_RUNTIME_VERSION="{runtime_version}"', "--output", JAVA_HOME, ], diff --git a/prek.toml b/prek.toml index 1cd543b..022273d 100644 --- a/prek.toml +++ b/prek.toml @@ -18,10 +18,10 @@ types = ["python"] require_serial = true [[repos.hooks]] -id = "ty" -name = "ty check" +id = "uv-check" +name = "uv check" language = "system" -entry = "uv run ty check" +entry = "uv check" pass_filenames = false types = ["python"] diff --git a/pyproject.toml b/pyproject.toml index b795fbd..ebb7d75 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -71,5 +71,5 @@ error-on-warning = true [tool.uv] # Keep pinned to ensure same version is used on CI. -required-version = "==0.13.7" +required-version = "==0.13.8" trusted-publishing = "always" diff --git a/src/jdk4py/__init__.py b/src/jdk4py/__init__.py index a55e4ff..2e96638 100644 --- a/src/jdk4py/__init__.py +++ b/src/jdk4py/__init__.py @@ -1,7 +1,5 @@ """JDK packaged for Python.""" -import re as _re -from functools import cache as _cache from importlib.metadata import version as _version from pathlib import Path as _Path from typing import Final as _Final @@ -16,27 +14,3 @@ int(number) for number in _VERSION.split(".") ] JAVA_VERSION: _Final = _JAVA_MAJOR, _JAVA_MINOR, _JAVA_PATCH - - -def _get_release_property(java_home: _Path, key: str, /) -> str: - release_file = java_home / "release" - for line in release_file.read_text(encoding="utf-8").splitlines(): - line_key, _, value = line.partition("=") - if line_key == key: - return value.strip('"') - raise RuntimeError(f"No {key} in {release_file}.") - - -@_cache -def _get_java_full_version() -> str: - runtime_version = _get_release_property(JAVA_HOME, "JAVA_RUNTIME_VERSION") - # Drop the optional suffix after the build number, such as `-LTS` in 25.0.5.1+2-LTS. - return _re.sub(r"(\+\d+)-.*$", r"\1", runtime_version) - - -def __getattr__(name: str) -> str: - # `JAVA_FULL_VERSION` is read from the Java runtime on first access: - # the runtime does not exist yet when `build_java_runtime.py` imports this module. - if name == "JAVA_FULL_VERSION": - return _get_java_full_version() - raise AttributeError(f"module {__name__!r} has no attribute {name!r}") diff --git a/tests/test_runtime.py b/tests/test_runtime.py index 5f6dc79..de0070b 100644 --- a/tests/test_runtime.py +++ b/tests/test_runtime.py @@ -5,7 +5,7 @@ from typing import Final, get_args from build_java_runtime import _INCLUDED_LOCALES, _RegionSpecificLocale -from jdk4py import JAVA, JAVA_FULL_VERSION, JAVA_VERSION +from jdk4py import JAVA, JAVA_VERSION _TEST_RESOURCES_DIRECTORY: Final = Path(__file__).parent / "resources" @@ -22,13 +22,6 @@ def test_java_version() -> None: assert match, f"Unexpected output:\n{output}" version = match.group("version") assert tuple(int(number) for number in version.split(".")[:3]) == JAVA_VERSION - build_match = re.search(r"\(build (?P[^)]+)\)", output) - assert build_match, f"Unexpected output:\n{output}" - # The build can end with an optional suffix, such as `-LTS` in 25.0.5.1+2-LTS. - assert re.fullmatch( - rf"{re.escape(JAVA_FULL_VERSION)}(-.+)?", build_match.group("build") - ) - assert JAVA_FULL_VERSION.startswith(f"{version}+") def _run_jar(name: str, /) -> str: From 6a6fe0ba91f7eab42cc835949bc9610d13777063 Mon Sep 17 00:00:00 2001 From: Thibault Derousseaux <6574550+tibdex@users.noreply.github.com> Date: Fri, 20 Nov 2026 14:35:04 -0500 Subject: [PATCH 5/5] Add comment --- .github/workflows/ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6006336..5cf672b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -57,6 +57,7 @@ jobs: - uses: actions/setup-java@v6.2.0 with: distribution: temurin + # The exact build, so that setup-java never falls back to the JDK preinstalled on the runner. java-version: 25.0.5.1+2 - run: uv run python build_java_runtime.py