Skip to content

Commit fa3aa9a

Browse files
committed
Update Temurin support
Signed-off-by: Dan Webb <[email protected]>
1 parent f2e340a commit fa3aa9a

File tree

6 files changed

+190
-54
lines changed

6 files changed

+190
-54
lines changed

.tool-versions

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ruby system

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ This file is used to list changes made in each version of the Java cookbook.
44

55
## Unreleased
66

7+
- Update Temurin support
8+
- Add script to check for Java updates
9+
710
## 12.1.1 - *2024-12-05*
811

912
## 12.1.0 - *2024-12-03*

bin/check_java_versions.rb

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'net/http'
4+
require 'json'
5+
require 'uri'
6+
7+
TEMURIN_REPOS = {
8+
'8' => 'adoptium/temurin8-binaries',
9+
'11' => 'adoptium/temurin11-binaries',
10+
'17' => 'adoptium/temurin17-binaries',
11+
}.freeze
12+
13+
def get_latest_release(repo)
14+
uri = URI("https://api.github.com/repos/#{repo}/releases/latest")
15+
response = Net::HTTP.get_response(uri)
16+
17+
if response.is_a?(Net::HTTPSuccess)
18+
JSON.parse(response.body)
19+
else
20+
puts "Failed to fetch release info for #{repo}: #{response.code} #{response.message}"
21+
nil
22+
end
23+
end
24+
25+
def verify_url(url)
26+
uri = URI(url)
27+
response = Net::HTTP.get_response(uri)
28+
29+
case response
30+
when Net::HTTPRedirection
31+
location = response['location']
32+
puts " ✓ URL redirects successfully to: #{location}"
33+
true
34+
when Net::HTTPSuccess
35+
puts ' ✓ URL is directly accessible'
36+
true
37+
else
38+
puts " ✗ URL is not accessible: #{response.code} #{response.message}"
39+
false
40+
end
41+
end
42+
43+
def find_linux_x64_jdk(assets)
44+
assets.find { |asset| asset['name'] =~ /OpenJDK\d+U-jdk_x64_linux_hotspot.*\.tar\.gz$/ }
45+
end
46+
47+
def check_versions
48+
puts 'Checking Temurin versions...'
49+
puts '-' * 50
50+
51+
TEMURIN_REPOS.each do |version, repo|
52+
puts "\nChecking Java #{version}..."
53+
release = get_latest_release(repo)
54+
next unless release
55+
56+
tag = release['tag_name']
57+
puts "Latest release: #{tag}"
58+
59+
asset = find_linux_x64_jdk(release['assets'])
60+
if asset
61+
url = asset['browser_download_url']
62+
puts "Download URL: #{url}"
63+
if verify_url(url)
64+
puts 'Current version in cookbook needs updating!' if url != current_url_in_cookbook(version)
65+
end
66+
else
67+
puts ' ✗ No Linux x64 JDK found in release assets'
68+
end
69+
end
70+
end
71+
72+
def current_url_in_cookbook(version)
73+
# Read the current URLs from openjdk_helpers.rb
74+
helpers_file = File.join(File.dirname(__FILE__), '..', 'libraries', 'openjdk_helpers.rb')
75+
content = File.read(helpers_file)
76+
77+
case version
78+
when '8'
79+
content.match(/temurin.*when '8'\s+'(.+?)'/m)&.[](1)
80+
when '11'
81+
content.match(/temurin.*when '11'\s+'(.+?)'/m)&.[](1)
82+
when '17'
83+
content.match(/temurin.*when '17'\s+'(.+?)'/m)&.[](1)
84+
end
85+
end
86+
87+
if __FILE__ == $PROGRAM_NAME
88+
check_versions
89+
end

kitchen.yml

+33
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,39 @@ suites:
8888
inspec_tests: [test/integration/openjdk]
8989
inputs: { java_version: "17" }
9090

91+
- name: temurin-8
92+
run_list:
93+
- recipe[test::openjdk]
94+
attributes:
95+
java:
96+
version: "8"
97+
flavor: "temurin"
98+
verifier:
99+
inspec_tests: [test/integration/openjdk]
100+
inputs: { java_version: "8" }
101+
102+
- name: temurin-11
103+
run_list:
104+
- recipe[test::openjdk]
105+
attributes:
106+
java:
107+
version: "11"
108+
flavor: "temurin"
109+
verifier:
110+
inspec_tests: [test/integration/openjdk]
111+
inputs: { java_version: "11" }
112+
113+
- name: temurin-17
114+
run_list:
115+
- recipe[test::openjdk]
116+
attributes:
117+
java:
118+
version: "17"
119+
flavor: "temurin"
120+
verifier:
121+
inspec_tests: [test/integration/openjdk]
122+
inputs: { java_version: "17" }
123+
91124
# Corretto
92125
- name: corretto-8
93126
run_list:

libraries/openjdk_helpers.rb

+45-54
Original file line numberDiff line numberDiff line change
@@ -34,71 +34,62 @@ def default_openjdk_install_method(version)
3434
end
3535
end
3636

37-
def default_openjdk_url(version, variant = nil)
38-
# Always default to OpenJDK
39-
# If the user passes variant we'll also select that variant's URL
40-
case version
41-
when '8'
42-
case variant
43-
when 'semeru'
44-
'https://github.com/ibmruntimes/semeru8-binaries/releases/download/jdk8u322-b06_openj9-0.30.0/ibm-semeru-open-jdk_x64_linux_8u322b06_openj9-0.30.0.tar.gz'
45-
when 'temurin'
46-
'https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u322-b06/OpenJDK8U-jdk_x64_linux_hotspot_8u322b06.tar.gz'
37+
def default_openjdk_url(version, flavor = 'openjdk')
38+
case flavor.downcase
39+
when 'temurin'
40+
case version
41+
when '8'
42+
'https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u432-b06/OpenJDK8U-jdk_x64_linux_hotspot_8u432b06.tar.gz'
43+
when '11'
44+
'https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.25%2B9/OpenJDK11U-jdk_x64_linux_hotspot_11.0.25_9.tar.gz'
45+
when '17'
46+
'https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.13%2B11/OpenJDK17U-jdk_x64_linux_hotspot_17.0.13_11.tar.gz'
4747
else
4848
Chef::Log.fatal('Version specified does not have a URL value set')
4949
raise 'Version supplied does not have a download URL set'
5050
end
51-
when '9'
52-
'https://download.java.net/java/GA/jdk9/9/binaries/openjdk-9_linux-x64_bin.tar.gz'
53-
when '10'
54-
'https://download.java.net/java/GA/jdk10/10/binaries/openjdk-10_linux-x64_bin.tar.gz'
55-
when '11'
56-
case variant
57-
when 'semeru'
51+
when 'semeru'
52+
case version
53+
when '8'
54+
'https://github.com/ibmruntimes/semeru8-binaries/releases/download/jdk8u322-b06_openj9-0.30.0/ibm-semeru-open-jdk_x64_linux_8u322b06_openj9-0.30.0.tar.gz'
55+
when '11'
5856
'https://github.com/ibmruntimes/semeru11-binaries/releases/download/jdk-11.0.14.1%2B1_openj9-0.30.1/ibm-semeru-open-jdk_x64_linux_11.0.14.1_1_openj9-0.30.1.tar.gz'
59-
when 'temurin'
60-
'https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.15%2B10/OpenJDK11U-jdk_x64_linux_hotspot_11.0.15_10.tar.gz'
61-
else
62-
'https://download.java.net/java/ga/jdk11/openjdk-11_linux-x64_bin.tar.gz'
63-
end
64-
when '12'
65-
'https://download.java.net/java/GA/jdk12/33/GPL/openjdk-12_linux-x64_bin.tar.gz'
66-
when '13'
67-
'https://download.java.net/java/GA/jdk13/5b8a42f3905b406298b72d750b6919f6/33/GPL/openjdk-13_linux-x64_bin.tar.gz'
68-
when '14'
69-
'https://download.java.net/java/GA/jdk14/076bab302c7b4508975440c56f6cc26a/36/GPL/openjdk-14_linux-x64_bin.tar.gz'
70-
when '15'
71-
'https://download.java.net/java/GA/jdk15/779bf45e88a44cbd9ea6621d33e33db1/36/GPL/openjdk-15_linux-x64_bin.tar.gz'
72-
when '16'
73-
case variant
74-
when 'semeru'
57+
when '16'
7558
'https://github.com/ibmruntimes/semeru16-binaries/releases/download/jdk-16.0.2%2B7_openj9-0.27.1/ibm-semeru-open-jdk_ppc64le_linux_16.0.2_7_openj9-0.27.1.tar.gz'
76-
when 'temurin'
77-
'https://github.com/adoptium/temurin16-binaries/releases/download/jdk-16.0.2%2B7/OpenJDK16U-jdk_x64_linux_hotspot_16.0.2_7.tar.gz'
78-
else
79-
'https://download.java.net/java/GA/jdk16/7863447f0ab643c585b9bdebf67c69db/36/GPL/openjdk-16_linux-x64_bin.tar.gz'
80-
end
81-
when '17'
82-
case variant
83-
when 'semeru'
59+
when '17'
8460
'https://github.com/ibmruntimes/semeru17-binaries/releases/download/jdk-17.0.2%2B8_openj9-0.30.0/ibm-semeru-open-jdk_x64_linux_17.0.2_8_openj9-0.30.0.tar.gz'
85-
when 'temurin'
86-
'https://github.com/adoptium/temurin18-binaries/releases/download/jdk-18.0.1%2B10/OpenJDK18U-jdk_x64_linux_hotspot_18.0.1_10.tar.gz'
87-
else
88-
'https://download.java.net/java/GA/jdk17/0d483333a00540d886896bac774ff48b/35/GPL/openjdk-17_linux-x64_bin.tar.gz'
89-
end
90-
when '18'
91-
case variant
92-
when 'semeru'
61+
when '18'
9362
'https://github.com/AdoptOpenJDK/semeru18-binaries/releases/download/jdk-18.0.1%2B10_openj9-0.32.0/ibm-semeru-open-jdk_x64_linux_18.0.1_10_openj9-0.32.0.tar.gz'
94-
when 'temurin'
95-
'https://github.com/adoptium/temurin18-binaries/releases/download/jdk-18.0.1%2B10/OpenJDK18U-jdk_x64_linux_hotspot_18.0.1_10.tar.gz'
9663
else
97-
'https://download.java.net/java/GA/jdk18.0.1/3f48cabb83014f9fab465e280ccf630b/10/GPL/openjdk-18.0.1_linux-x64_bin.tar.gz'
64+
Chef::Log.fatal('Version specified does not have a URL value set')
65+
raise 'Version supplied does not have a download URL set'
9866
end
9967
else
100-
Chef::Log.fatal('Version specified does not have a URL value set')
101-
raise 'Version supplied does not have a download URL set'
68+
case version
69+
when '9'
70+
'https://download.java.net/java/GA/jdk9/9/binaries/openjdk-9_linux-x64_bin.tar.gz'
71+
when '10'
72+
'https://download.java.net/java/GA/jdk10/10/binaries/openjdk-10_linux-x64_bin.tar.gz'
73+
when '11'
74+
'https://download.java.net/java/ga/jdk11/openjdk-11_linux-x64_bin.tar.gz'
75+
when '12'
76+
'https://download.java.net/java/GA/jdk12/33/GPL/openjdk-12_linux-x64_bin.tar.gz'
77+
when '13'
78+
'https://download.java.net/java/GA/jdk13/5b8a42f3905b406298b72d750b6919f6/33/GPL/openjdk-13_linux-x64_bin.tar.gz'
79+
when '14'
80+
'https://download.java.net/java/GA/jdk14/076bab302c7b4508975440c56f6cc26a/36/GPL/openjdk-14_linux-x64_bin.tar.gz'
81+
when '15'
82+
'https://download.java.net/java/GA/jdk15/779bf45e88a44cbd9ea6621d33e33db1/36/GPL/openjdk-15_linux-x64_bin.tar.gz'
83+
when '16'
84+
'https://download.java.net/java/GA/jdk16/7863447f0ab643c585b9bdebf67c69db/36/GPL/openjdk-16_linux-x64_bin.tar.gz'
85+
when '17'
86+
'https://download.java.net/java/GA/jdk17/0d483333a00540d886896bac774ff48b/35/GPL/openjdk-17_linux-x64_bin.tar.gz'
87+
when '18'
88+
'https://download.java.net/java/GA/jdk18.0.1/3f48cabb83014f9fab465e280ccf630b/10/GPL/openjdk-18.0.1_linux-x64_bin.tar.gz'
89+
else
90+
Chef::Log.fatal('Version specified does not have a URL value set')
91+
raise 'Version supplied does not have a download URL set'
92+
end
10293
end
10394
end
10495

spec/libraries/openjdk_helpers_spec.rb

+19
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,25 @@ class DummyClass < Chef::Node
3434
.to raise_error('Version supplied does not have a download URL set')
3535
end
3636
end
37+
38+
context 'Temurin' do
39+
let(:version) { '17' }
40+
41+
it 'returns the correct download URL for Temurin' do
42+
expect(subject.default_openjdk_url(version, 'temurin'))
43+
.to eq 'https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.13%2B11/OpenJDK17U-jdk_x64_linux_hotspot_17.0.13_11.tar.gz'
44+
end
45+
46+
it 'returns the correct download URL for Temurin 11' do
47+
expect(subject.default_openjdk_url('11', 'temurin'))
48+
.to eq 'https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.25%2B9/OpenJDK11U-jdk_x64_linux_hotspot_11.0.25_9.tar.gz'
49+
end
50+
51+
it 'returns the correct download URL for Temurin 8' do
52+
expect(subject.default_openjdk_url('8', 'temurin'))
53+
.to eq 'https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u432-b06/OpenJDK8U-jdk_x64_linux_hotspot_8u432b06.tar.gz'
54+
end
55+
end
3756
end
3857

3958
describe '#default_openjdk_install_method' do

0 commit comments

Comments
 (0)