@@ -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+
6370def 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+
7183def 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+
162185def 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+
191258def 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
0 commit comments