Skip to content

Commit f26a7ee

Browse files
committed
Included a new recipe to install openjdk8 openj9 build
Signed-off-by: Chandrakala <[email protected]>
1 parent 70116c7 commit f26a7ee

File tree

3 files changed

+151
-1
lines changed

3 files changed

+151
-1
lines changed

cookbooks/travis_java/attributes/default.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
default['travis_java']['default_version'] = 'openjdk8'
1111
end
1212

13-
default['travis_java']['jdk_switcher_url'] = 'https://raw.githubusercontent.com/michaelklishin/jdk_switcher/1e091549285fb0f2591cef679b4135cfbfcc0b4c/jdk_switcher.sh'
13+
default['travis_java']['jdk_switcher_url'] = 'https://raw.githubusercontent.com/michaelklishin/jdk_switcher/10fee199ca369af1aba9fc012bf6ac8870ca2e74/jdk_switcher.sh'
1414
default['travis_java']['jdk_switcher_path'] = '/opt/jdk_switcher/jdk_switcher.sh'
1515
default['travis_java']['jvm_base_dir'] = '/usr/lib/jvm'
1616

@@ -31,3 +31,6 @@
3131
default['travis_java']['ibmjava']['platform'] = 'linux'
3232
default['travis_java']['ibmjava8']['jvm_name'] = "java-8-ibm-#{node['travis_java']['arch']}"
3333
default['travis_java']['ibmjava8']['pinned_release'] = nil
34+
35+
default['travis_java']['openjdk8-openj9']['jvm_name'] = "openjdk8-openj9-#{node['travis_java']['arch']}"
36+
default['travis_java']['openjdk8-openj9']['pinned_release'] = nil
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
require 'json'
2+
require 'open-uri'
3+
require 'fileutils'
4+
require 'digest'
5+
require 'net/https'
6+
require 'net/http'
7+
8+
module TravisJava
9+
module OpenJDKOpenJ9
10+
def install_openjdk_openj9(version)
11+
attribute_key = "openjdk" + version.to_s + "-openj9"
12+
java_home = ::File.join(node['travis_java']['jvm_base_dir'], node['travis_java'][attribute_key]['jvm_name'])
13+
pinned_release = node['travis_java'][attribute_key]['pinned_release']
14+
# arch = node['travis_java']['arch']
15+
arch = "x64_Linux" if node['travis_java']['arch'] == "amd64"
16+
arch = "ppc64le_Linux" if node['travis_java']['arch'] == "ppc64el"
17+
url = ::File.join("https://api.adoptopenjdk.net", attribute_key, "releases", arch, "latest")
18+
19+
# Obtain the uri of the latest IBM Java build for the specified version from index.yml
20+
if pinned_release
21+
url = ::File.join("https://api.adoptopenjdk.net", attribute_key, "releases", arch)
22+
entry = find_version_entry(url, pinned_release)
23+
else
24+
entry = find_version_entry(url, version)
25+
end
26+
27+
# Download and install the IBM Java build
28+
install_build(entry, java_home, version)
29+
30+
# Delete IBM Java installable and installer properties file
31+
delete_files(version)
32+
33+
link_cacerts(java_home, version)
34+
end
35+
36+
# This method downloads and installs the java build
37+
# @param [Hash] entry - latest entry from the index.yml for the specified ibm java version containing uri
38+
# @param [String] java_home - directory path where OpenJDK build will be installed
39+
# @param [String] version - java version
40+
# @return - None
41+
42+
def install_build(entry, java_home, version)
43+
binary = File.join(Dir.tmpdir, "openjdk" + version.to_s + "_openj9.tgz")
44+
# Download the Openjdk build from source url to the local machine
45+
remote_file binary do
46+
src_url = entry['uri']
47+
source src_url.to_s
48+
mode '0755'
49+
checksum entry['sha256sum']
50+
action :create
51+
notifies :run, "ruby_block[Verify Checksum of #{binary} file]", :immediately
52+
end
53+
54+
# Verify Checksum of the downloaded IBM Java build
55+
ruby_block "Verify Checksum of #{binary} file" do
56+
block do
57+
checksum = Digest::SHA256.hexdigest(File.read(binary))
58+
expected_checksum = entry['sha256sum']
59+
if checksum != expected_checksum
60+
raise "Checksum of the downloaded OpendJDK build #{checksum} does not match the #{expected_checksum}"
61+
end
62+
end
63+
action :nothing
64+
end
65+
66+
execute "Remove old java build installed at #{java_home}" do
67+
command "rm -rf #{java_home}"
68+
action :run
69+
end
70+
71+
# Extract the OpenJDK build
72+
execute "Extract OpenJDK#{version} build" do
73+
command "tar -zxf #{binary}"
74+
action :run
75+
end
76+
77+
execute "Move the OpenJDK#{version} build to #{java_home} dir" do
78+
command "mv ./#{entry['release']} #{java_home}"
79+
action :run
80+
end
81+
end
82+
83+
def link_cacerts(java_home, version)
84+
link "#{java_home}/jre/lib/security/cacerts" do
85+
to '/etc/ssl/certs/java/cacerts'
86+
not_if { version > 8 }
87+
end
88+
89+
link "#{java_home}/lib/security/cacerts" do
90+
to '/etc/ssl/certs/java/cacerts'
91+
not_if { version <= 8 }
92+
end
93+
end
94+
95+
# This method deletes the IBM Java installable and installer properties files
96+
# @param [String] version - java version
97+
# @return - None
98+
99+
def delete_files(version)
100+
binary = File.join(Dir.tmpdir, "openjdk" + version.to_s + "_openj9" + ".tgz")
101+
102+
file binary do
103+
action :delete
104+
end
105+
end
106+
107+
def find_version_entry(url, version)
108+
binary = []
109+
release = version
110+
json = open(url.to_s, &:read)
111+
parsed = JSON.parse(json, object_class: JSON::GenericObject)
112+
case parsed
113+
when Array
114+
release = parsed[0]["release_name"] if version.to_s == "8"
115+
binary = find_binary(parsed, release)
116+
when Object
117+
release = parsed["release_name"] if version.to_s == "8"
118+
binary = parsed["binaries"][0] if parsed["release_name"].to_s == release.to_s
119+
end
120+
fill_entry(binary, release)
121+
end
122+
123+
def fill_entry(binary, release)
124+
entry = {}
125+
entry["uri"] = binary["binary_link"]
126+
content = open(binary["checksum_link"].to_s, &:read)
127+
array = content.split(" ")
128+
entry["sha256sum"] = array[0]
129+
entry["release"] = release
130+
entry
131+
end
132+
133+
def find_binary(parsed, release)
134+
binary = []
135+
(0..parsed.count - 1).each do |i|
136+
if parsed[i]["release_name"].to_s == release.to_s
137+
binary = parsed[i]["binaries"][0]
138+
break
139+
end
140+
end
141+
binary
142+
end
143+
end
144+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Chef::Recipe.send(:include, TravisJava::OpenJDKOpenJ9)
2+
3+
install_openjdk_openj9 8

0 commit comments

Comments
 (0)