@@ -59,6 +59,11 @@ def parse_args():
5959 parser .add_argument (
6060 "--root" , default = "." , help = "specify build scripts root directory"
6161 )
62+ parser .add_argument (
63+ "--jdk21" ,
64+ action = "store_true" ,
65+ help = "update SDK 21 on build hosts (needed by Jenkins)" ,
66+ )
6267
6368 return parser .parse_args ()
6469
@@ -255,6 +260,87 @@ def update_deps(root, bump, skip):
255260 exit (1 )
256261
257262
263+ def update_jdk21 (root ):
264+ base_url = "https://download.oracle.com/java/21/archive/"
265+
266+ filename = os .path .join (root , "ci/linux-install-jdk21.sh" )
267+ with open (filename , "r" ) as f :
268+ content = f .read ()
269+
270+ old_version = re .search (
271+ r"version=21\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)" , content
272+ ).group ()
273+ _ , minor , patch = old_version .split ("." )
274+ minor = int (minor )
275+ patch = int (patch )
276+ log .debug (f"Found version 21.{ minor } .{ patch } in '{ filename } '" )
277+
278+ # Let's try to increase the minor version number first
279+ response = requests .head (base_url + f"jdk-21.{ minor + 1 } .0_linux-x64_bin.tar.gz" )
280+ while response .status_code == 200 :
281+ minor += 1
282+ log .debug (f"Found more recent version 21.{ minor } .0" )
283+
284+ # Reset the patch version if there is a more recent minor version
285+ patch = 0
286+
287+ time .sleep (1 ) # Let's not DDOS them
288+ response = requests .head (
289+ base_url + f"jdk-21.{ minor + 1 } .0_linux-x64_bin.tar.gz"
290+ )
291+
292+ # Now try to increase the patch version number
293+ response = requests .head (
294+ base_url + f"jdk-21.{ minor } .{ patch + 1 } _linux-x64_bin.tar.gz"
295+ )
296+ while response .status_code == 200 :
297+ patch += 1
298+ log .debug (f"Found more recent version 21.{ minor } .{ patch } " )
299+ time .sleep (1 ) # Let's not DDOS them
300+ response = requests .head (
301+ base_url + f"jdk-21.{ minor } .{ patch + 1 } _linux-x64_bin.tar.gz"
302+ )
303+
304+ new_version = f"version=21.{ minor } .{ patch } "
305+ if new_version == old_version :
306+ log .debug (
307+ f"Java Development Kit 21 is already the newest version ('{ new_version } ' == '{ old_version } ')"
308+ )
309+ return
310+
311+ # Find old SHAs
312+ aarch64_old_sha , x64_old_sha = re .findall (r"sha=[0-9a-f]{64}" , content )
313+ log .debug (f"Found SHA '{ aarch64_old_sha } ' for aarch64 in '{ filename } '" )
314+ log .debug (f"Found SHA '{ x64_old_sha } ' for x64 '{ filename } '" )
315+
316+ # Get new SHAs
317+ url = base_url + f"jdk-21.{ minor } .{ patch } _linux-aarch64_bin.tar.gz.sha256"
318+ aarch64_new_sha = f"sha={ requests .get (url ).text } "
319+ log .debug (f"Fetched new SHA '{ aarch64_new_sha } ' for aarch64" )
320+ url = base_url + f"jdk-21.{ minor } .{ patch } _linux-x64_bin.tar.gz.sha256"
321+ x64_new_sha = f"sha={ requests .get (url ).text } "
322+ log .debug (f"Fetched new SHA '{ x64_new_sha } ' for x64" )
323+
324+ # Replace version number and SHAs
325+ log .debug (f"Replacing old version '{ old_version } ' with new version '{ new_version } '" )
326+ content = content .replace (old_version , new_version , 1 )
327+ log .debug (f"Replacing old SHA '{ aarch64_old_sha } ' with new sha '{ aarch64_new_sha } '" )
328+ content = content .replace (aarch64_old_sha , aarch64_new_sha , 1 )
329+ log .debug (f"Replacing old SHA '{ x64_old_sha } ' with new sha '{ x64_new_sha } '" )
330+ content = content .replace (x64_old_sha , x64_new_sha , 1 )
331+
332+ log .debug (f"Writing changes to file '{ filename } '" )
333+ with open (filename , "w" ) as f :
334+ f .write (content )
335+
336+ if not git_commit (
337+ root ,
338+ f"Updated Java Development Kit to 21.{ minor } .{ patch } " ,
339+ ):
340+ log .error (f"Failed to commit changes after updating Java Development Kit" )
341+ exit (1 )
342+
343+
258344def main ():
259345 args = parse_args ()
260346 loglevel = "DEBUG" if args .debug else "INFO"
@@ -263,6 +349,8 @@ def main():
263349 )
264350
265351 update_deps (args .root , args .bump , args .skip )
352+ if args .jdk21 :
353+ update_jdk21 (args .root )
266354
267355
268356if __name__ == "__main__" :
0 commit comments