Skip to content

Commit c8ea4d9

Browse files
fix(release): install Temurin 25 jmods for Classic packaging
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent c21ef7e commit c8ea4d9

2 files changed

Lines changed: 149 additions & 1 deletion

File tree

‎scripts/prepare_jdks.py‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ def build_download_url(version: str, spec: TargetSpec) -> str:
6060
)
6161

6262

63+
def build_jmods_url(version: str, spec: TargetSpec) -> str:
64+
return (
65+
f"https://api.adoptium.net/v3/binary/latest/{version}/ga/"
66+
f"{spec.adoptium_os}/{spec.adoptium_arch}/jmods/hotspot/normal/eclipse?project=jdk"
67+
)
68+
69+
6370
def java_binary_candidates(home_dir: Path) -> list[Path]:
6471
return [home_dir / "bin" / "java", home_dir / "bin" / "java.exe"]
6572

@@ -68,6 +75,11 @@ def has_java_binary(home_dir: Path) -> bool:
6875
return any(candidate.exists() for candidate in java_binary_candidates(home_dir))
6976

7077

78+
def has_jmods(home_dir: Path) -> bool:
79+
jmods_dir = home_dir / "jmods"
80+
return jmods_dir.is_dir() and any(jmods_dir.glob("*.jmod"))
81+
82+
7183
def has_java_version(home_dir: Path, version: str) -> bool:
7284
release_file = home_dir / "release"
7385
if not release_file.is_file():
@@ -159,6 +171,17 @@ def download_file(url: str, destination: Path) -> None:
159171
log(f" downloaded : {format_size(bytes_written)}")
160172

161173

174+
def locate_jmods_dir(root: Path) -> Path:
175+
candidates = [
176+
directory
177+
for directory in root.rglob("jmods")
178+
if directory.is_dir() and any(directory.glob("*.jmod"))
179+
]
180+
if not candidates:
181+
raise RuntimeError(f"Could not locate a jmods directory under {root}")
182+
return sorted(candidates, key=lambda item: (len(item.relative_to(root).parts), str(item)))[0]
183+
184+
162185
def locate_java_home(root: Path) -> Path:
163186
candidates: list[Path] = []
164187
for pattern in ("java", "java.exe"):
@@ -188,6 +211,50 @@ def write_metadata(destination: Path, spec: TargetSpec, version: str, source_url
188211
)
189212

190213

214+
def install_jmods_from_archive(archive_path: Path, archive_type: str, install_home: Path) -> None:
215+
with tempfile.TemporaryDirectory(prefix="wepush-jmods-") as tmp_dir:
216+
extract_root = Path(tmp_dir) / "extract"
217+
extract_root.mkdir(parents=True, exist_ok=True)
218+
if archive_type == "zip":
219+
safe_extract_zip(archive_path, extract_root)
220+
else:
221+
safe_extract_tar(archive_path, extract_root)
222+
source_dir = locate_jmods_dir(extract_root)
223+
destination = install_home / "jmods"
224+
if destination.exists():
225+
shutil.rmtree(destination)
226+
shutil.copytree(source_dir, destination, symlinks=True)
227+
228+
229+
def ensure_jmods(
230+
downloads_dir: Path,
231+
version: str,
232+
spec: TargetSpec,
233+
install_home: Path,
234+
force: bool,
235+
) -> None:
236+
if has_jmods(install_home):
237+
log(f" jmods : {install_home / 'jmods'}")
238+
return
239+
240+
source_url = build_jmods_url(version, spec)
241+
archive_path = downloads_dir / f"temurin-{version}-{spec.key}-jmods.{spec.archive_suffix}"
242+
log(f" jmods source: {source_url}")
243+
if force and archive_path.exists():
244+
archive_path.unlink()
245+
if not archive_path.exists():
246+
log(f" download jmods -> {archive_path.name}")
247+
download_file(source_url, archive_path)
248+
else:
249+
log(f" jmods archive reuse -> {archive_path.name}")
250+
251+
log(f" extract jmods -> {archive_path.name}")
252+
install_jmods_from_archive(archive_path, spec.archive_type, install_home)
253+
if not has_jmods(install_home):
254+
raise RuntimeError(f"Prepared JDK is missing jmods: {install_home / 'jmods'}")
255+
log(f" jmods : {install_home / 'jmods'}")
256+
257+
191258
def install_from_existing_java_home(install_home: Path, java_home: Path) -> None:
192259
if not has_java_binary(java_home):
193260
raise RuntimeError(f"Provided java home is missing java executable: {java_home}")
@@ -209,6 +276,7 @@ def prepare_target(
209276
source_url = build_download_url(version, spec)
210277
downloads_dir = project_root / "downloads" / "jdks"
211278
archive_path = downloads_dir / f"temurin-{version}-{spec.key}.{spec.archive_suffix}"
279+
jmods_archive_path = downloads_dir / f"temurin-{version}-{spec.key}-jmods.{spec.archive_suffix}"
212280
install_home = project_root / "jdks" / spec.platform_dir / spec.arch_dir / "home"
213281
log(f"==> {spec.key}")
214282
log(f" source: {source_url}")
@@ -221,18 +289,22 @@ def prepare_target(
221289
if force:
222290
if archive_path.exists():
223291
archive_path.unlink()
292+
if jmods_archive_path.exists():
293+
jmods_archive_path.unlink()
224294
if install_home.exists():
225295
shutil.rmtree(install_home)
226296

227297
if has_java_binary(install_home) and has_java_version(install_home, version):
228298
log(f" reuse : {install_home}")
299+
ensure_jmods(downloads_dir, version, spec, install_home, force)
229300
return install_home
230301

231302
if java_home_override is not None:
232303
if not has_java_version(java_home_override, version):
233304
raise RuntimeError(f"Provided java home must contain JDK {version}: {java_home_override}")
234305
log(f" reuse JAVA_HOME -> {java_home_override}")
235306
install_from_existing_java_home(install_home, java_home_override)
307+
ensure_jmods(downloads_dir, version, spec, install_home, force)
236308
write_metadata(install_home, spec, version, f"java-home:{java_home_override}")
237309
log(f" ready : {install_home}")
238310
return install_home
@@ -267,6 +339,7 @@ def prepare_target(
267339
if not has_java_binary(install_home):
268340
raise RuntimeError(f"Prepared JDK is missing java executable: {install_home}")
269341

342+
ensure_jmods(downloads_dir, version, spec, install_home, force)
270343
write_metadata(install_home, spec, version, source_url)
271344
log(f" ready : {install_home}")
272345
return install_home

‎scripts/test_prepare_jdks.py‎

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
from __future__ import annotations
22

3+
import io
4+
import tarfile
35
import tempfile
46
import unittest
7+
import zipfile
58
from pathlib import Path
69
from unittest.mock import patch
710

8-
from scripts.prepare_jdks import TARGETS, format_size, has_java_version, install_from_existing_java_home, locate_java_home, parse_targets, prepare_target
11+
from scripts.prepare_jdks import (
12+
TARGETS,
13+
format_size,
14+
has_java_version,
15+
has_jmods,
16+
install_from_existing_java_home,
17+
install_jmods_from_archive,
18+
locate_java_home,
19+
locate_jmods_dir,
20+
parse_targets,
21+
prepare_target,
22+
)
923

1024

1125
class PrepareJdksTests(unittest.TestCase):
@@ -27,11 +41,14 @@ def test_replaces_cached_java_21_with_requested_java_25(self) -> None:
2741
(home / "bin").mkdir(parents=True)
2842
(home / "bin" / "java").write_text("", encoding="utf-8")
2943
(home / "release").write_text(f'JAVA_VERSION="{version}"\n', encoding="utf-8")
44+
(source_home / "jmods").mkdir()
45+
(source_home / "jmods" / "java.base.jmod").write_bytes(b"jmod")
3046
with patch("scripts.prepare_jdks.download_file") as download:
3147
result = prepare_target(root, "25", TARGETS["mac-arm64"], False, False, source_home)
3248
download.assert_not_called()
3349
self.assertEqual(result, cached_home)
3450
self.assertTrue(has_java_version(result, "25"))
51+
self.assertTrue(has_jmods(result))
3552

3653
def test_rejects_java_home_with_old_version(self) -> None:
3754
with tempfile.TemporaryDirectory() as tmp_dir:
@@ -72,6 +89,64 @@ def test_locate_java_home_for_macos_layout(self) -> None:
7289
(home / "bin" / "java").write_text("", encoding="utf-8")
7390
self.assertEqual(locate_java_home(root), home)
7491

92+
def test_locate_jmods_dir_for_nested_and_macos_layouts(self) -> None:
93+
with tempfile.TemporaryDirectory() as tmp_dir:
94+
root = Path(tmp_dir)
95+
nested = root / "jdk-25" / "jmods"
96+
nested.mkdir(parents=True)
97+
(nested / "java.base.jmod").write_bytes(b"jmod")
98+
self.assertEqual(locate_jmods_dir(root), nested)
99+
100+
macos = root / "temurin-25.jdk" / "Contents" / "Home" / "jmods"
101+
macos.mkdir(parents=True)
102+
(macos / "java.base.jmod").write_bytes(b"jmod")
103+
self.assertEqual(locate_jmods_dir(root / "temurin-25.jdk"), macos)
104+
105+
def test_install_jmods_from_tar_and_zip(self) -> None:
106+
with tempfile.TemporaryDirectory() as tmp_dir:
107+
root = Path(tmp_dir)
108+
tar_path = root / "jmods.tar.gz"
109+
payload = b"jmod"
110+
with tarfile.open(tar_path, "w:gz") as archive:
111+
info = tarfile.TarInfo("jdk-25.jdk/Contents/Home/jmods/java.base.jmod")
112+
info.size = len(payload)
113+
archive.addfile(info, io.BytesIO(payload))
114+
tar_home = root / "tar-home"
115+
tar_home.mkdir()
116+
install_jmods_from_archive(tar_path, "tar.gz", tar_home)
117+
self.assertEqual((tar_home / "jmods" / "java.base.jmod").read_bytes(), payload)
118+
119+
zip_path = root / "jmods.zip"
120+
with zipfile.ZipFile(zip_path, "w") as archive:
121+
archive.writestr("jdk-25/jmods/java.desktop.jmod", payload)
122+
zip_home = root / "zip-home"
123+
zip_home.mkdir()
124+
install_jmods_from_archive(zip_path, "zip", zip_home)
125+
self.assertTrue(has_jmods(zip_home))
126+
127+
def test_cached_jdk_without_jmods_downloads_jmods_only(self) -> None:
128+
with tempfile.TemporaryDirectory() as tmp_dir:
129+
root = Path(tmp_dir)
130+
cached_home = root / "jdks" / "linux" / "x64" / "home"
131+
(cached_home / "bin").mkdir(parents=True)
132+
(cached_home / "bin" / "java").write_text("", encoding="utf-8")
133+
(cached_home / "release").write_text('JAVA_VERSION="25.0.1"\n', encoding="utf-8")
134+
135+
def write_archive(url: str, destination: Path) -> None:
136+
del url
137+
destination.parent.mkdir(parents=True, exist_ok=True)
138+
payload = b"jmod"
139+
with tarfile.open(destination, "w:gz") as archive:
140+
info = tarfile.TarInfo("jdk-25/jmods/java.base.jmod")
141+
info.size = len(payload)
142+
archive.addfile(info, io.BytesIO(payload))
143+
144+
with patch("scripts.prepare_jdks.download_file", side_effect=write_archive) as download:
145+
result = prepare_target(root, "25", TARGETS["linux-x64"], False, False, None)
146+
download.assert_called_once()
147+
self.assertIn("/jmods/", download.call_args.args[0])
148+
self.assertTrue(has_jmods(result))
149+
75150
def test_install_from_existing_java_home(self) -> None:
76151
with tempfile.TemporaryDirectory() as tmp_dir:
77152
root = Path(tmp_dir)

0 commit comments

Comments
 (0)