From f26a7ee09be2ca3aec3b35a004e2d4bc6c802195 Mon Sep 17 00:00:00 2001 From: Chandrakala Date: Tue, 12 Dec 2017 17:37:23 +0530 Subject: [PATCH] Included a new recipe to install openjdk8 openj9 build Signed-off-by: Chandrakala --- cookbooks/travis_java/attributes/default.rb | 5 +- .../travis_java/libraries/openjdk_openj9.rb | 144 ++++++++++++++++++ .../travis_java/recipes/openjdk8_openj9.rb | 3 + 3 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 cookbooks/travis_java/libraries/openjdk_openj9.rb create mode 100644 cookbooks/travis_java/recipes/openjdk8_openj9.rb diff --git a/cookbooks/travis_java/attributes/default.rb b/cookbooks/travis_java/attributes/default.rb index 986fd2cc5..d70081f56 100644 --- a/cookbooks/travis_java/attributes/default.rb +++ b/cookbooks/travis_java/attributes/default.rb @@ -10,7 +10,7 @@ default['travis_java']['default_version'] = 'openjdk8' end -default['travis_java']['jdk_switcher_url'] = 'https://raw.githubusercontent.com/michaelklishin/jdk_switcher/1e091549285fb0f2591cef679b4135cfbfcc0b4c/jdk_switcher.sh' +default['travis_java']['jdk_switcher_url'] = 'https://raw.githubusercontent.com/michaelklishin/jdk_switcher/10fee199ca369af1aba9fc012bf6ac8870ca2e74/jdk_switcher.sh' default['travis_java']['jdk_switcher_path'] = '/opt/jdk_switcher/jdk_switcher.sh' default['travis_java']['jvm_base_dir'] = '/usr/lib/jvm' @@ -31,3 +31,6 @@ default['travis_java']['ibmjava']['platform'] = 'linux' default['travis_java']['ibmjava8']['jvm_name'] = "java-8-ibm-#{node['travis_java']['arch']}" default['travis_java']['ibmjava8']['pinned_release'] = nil + +default['travis_java']['openjdk8-openj9']['jvm_name'] = "openjdk8-openj9-#{node['travis_java']['arch']}" +default['travis_java']['openjdk8-openj9']['pinned_release'] = nil diff --git a/cookbooks/travis_java/libraries/openjdk_openj9.rb b/cookbooks/travis_java/libraries/openjdk_openj9.rb new file mode 100644 index 000000000..145378ab3 --- /dev/null +++ b/cookbooks/travis_java/libraries/openjdk_openj9.rb @@ -0,0 +1,144 @@ +require 'json' +require 'open-uri' +require 'fileutils' +require 'digest' +require 'net/https' +require 'net/http' + +module TravisJava + module OpenJDKOpenJ9 + def install_openjdk_openj9(version) + attribute_key = "openjdk" + version.to_s + "-openj9" + java_home = ::File.join(node['travis_java']['jvm_base_dir'], node['travis_java'][attribute_key]['jvm_name']) + pinned_release = node['travis_java'][attribute_key]['pinned_release'] + # arch = node['travis_java']['arch'] + arch = "x64_Linux" if node['travis_java']['arch'] == "amd64" + arch = "ppc64le_Linux" if node['travis_java']['arch'] == "ppc64el" + url = ::File.join("https://api.adoptopenjdk.net", attribute_key, "releases", arch, "latest") + + # Obtain the uri of the latest IBM Java build for the specified version from index.yml + if pinned_release + url = ::File.join("https://api.adoptopenjdk.net", attribute_key, "releases", arch) + entry = find_version_entry(url, pinned_release) + else + entry = find_version_entry(url, version) + end + + # Download and install the IBM Java build + install_build(entry, java_home, version) + + # Delete IBM Java installable and installer properties file + delete_files(version) + + link_cacerts(java_home, version) + end + + # This method downloads and installs the java build + # @param [Hash] entry - latest entry from the index.yml for the specified ibm java version containing uri + # @param [String] java_home - directory path where OpenJDK build will be installed + # @param [String] version - java version + # @return - None + + def install_build(entry, java_home, version) + binary = File.join(Dir.tmpdir, "openjdk" + version.to_s + "_openj9.tgz") + # Download the Openjdk build from source url to the local machine + remote_file binary do + src_url = entry['uri'] + source src_url.to_s + mode '0755' + checksum entry['sha256sum'] + action :create + notifies :run, "ruby_block[Verify Checksum of #{binary} file]", :immediately + end + + # Verify Checksum of the downloaded IBM Java build + ruby_block "Verify Checksum of #{binary} file" do + block do + checksum = Digest::SHA256.hexdigest(File.read(binary)) + expected_checksum = entry['sha256sum'] + if checksum != expected_checksum + raise "Checksum of the downloaded OpendJDK build #{checksum} does not match the #{expected_checksum}" + end + end + action :nothing + end + + execute "Remove old java build installed at #{java_home}" do + command "rm -rf #{java_home}" + action :run + end + + # Extract the OpenJDK build + execute "Extract OpenJDK#{version} build" do + command "tar -zxf #{binary}" + action :run + end + + execute "Move the OpenJDK#{version} build to #{java_home} dir" do + command "mv ./#{entry['release']} #{java_home}" + action :run + end + end + + def link_cacerts(java_home, version) + link "#{java_home}/jre/lib/security/cacerts" do + to '/etc/ssl/certs/java/cacerts' + not_if { version > 8 } + end + + link "#{java_home}/lib/security/cacerts" do + to '/etc/ssl/certs/java/cacerts' + not_if { version <= 8 } + end + end + + # This method deletes the IBM Java installable and installer properties files + # @param [String] version - java version + # @return - None + + def delete_files(version) + binary = File.join(Dir.tmpdir, "openjdk" + version.to_s + "_openj9" + ".tgz") + + file binary do + action :delete + end + end + + def find_version_entry(url, version) + binary = [] + release = version + json = open(url.to_s, &:read) + parsed = JSON.parse(json, object_class: JSON::GenericObject) + case parsed + when Array + release = parsed[0]["release_name"] if version.to_s == "8" + binary = find_binary(parsed, release) + when Object + release = parsed["release_name"] if version.to_s == "8" + binary = parsed["binaries"][0] if parsed["release_name"].to_s == release.to_s + end + fill_entry(binary, release) + end + + def fill_entry(binary, release) + entry = {} + entry["uri"] = binary["binary_link"] + content = open(binary["checksum_link"].to_s, &:read) + array = content.split(" ") + entry["sha256sum"] = array[0] + entry["release"] = release + entry + end + + def find_binary(parsed, release) + binary = [] + (0..parsed.count - 1).each do |i| + if parsed[i]["release_name"].to_s == release.to_s + binary = parsed[i]["binaries"][0] + break + end + end + binary + end + end +end diff --git a/cookbooks/travis_java/recipes/openjdk8_openj9.rb b/cookbooks/travis_java/recipes/openjdk8_openj9.rb new file mode 100644 index 000000000..e0039226e --- /dev/null +++ b/cookbooks/travis_java/recipes/openjdk8_openj9.rb @@ -0,0 +1,3 @@ +Chef::Recipe.send(:include, TravisJava::OpenJDKOpenJ9) + +install_openjdk_openj9 8