From 476be62bfd38dcc2e34d3859078b1cab59bf4b80 Mon Sep 17 00:00:00 2001 From: Eric Edgar Date: Wed, 3 Oct 2012 12:18:42 -0500 Subject: [PATCH 1/2] Add binary jdk and jre support for oracle systems --- attributes/default.rb | 3 ++- providers/ark.rb | 19 +++++++++----- recipes/oracle.rb | 2 +- recipes/oracle_jre.rb | 59 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 8 deletions(-) create mode 100644 recipes/oracle_jre.rb diff --git a/attributes/default.rb b/attributes/default.rb index ab2bec7a..1b38423b 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -20,9 +20,10 @@ # remove the deprecated Ubuntu jdk packages default['java']['remove_deprecated_packages'] = false -# default jdk attributes +# default jdk/jre attributes default['java']['install_flavor'] = "openjdk" default['java']['jdk_version'] = '6' +default['java']['jre_version'] = '6' default['java']['arch'] = kernel['machine'] =~ /x86_64/ ? "x86_64" : "i586" default['java']['bin_cmds'] = ['java','jar'] diff --git a/providers/ark.rb b/providers/ark.rb index 79da26e3..8e4bf2a7 100644 --- a/providers/ark.rb +++ b/providers/ark.rb @@ -129,18 +129,24 @@ def download_jdk(tarball_name, new_resource) end end - cmd = Chef::ShellOut.new( + case tarball_name + when /!^.*\rpm.bin/ + cmd = Chef::ShellOut.new( %Q[ mv "#{tmpdir}/#{app_dir_name}" "#{app_dir}" ] ).run_command - unless cmd.exitstatus == 0 - Chef::Application.fatal!(%Q[ Command \' mv "#{tmpdir}/#{app_dir_name}" "#{app_dir}" \' failed ]) - end + unless cmd.exitstatus == 0 + Chef::Application.fatal!(%Q[ Command \' mv "#{tmpdir}/#{app_dir_name}" "#{app_dir}" \' failed ]) + end + end + FileUtils.rm_r tmpdir new_resource.updated_by_last_action(true) end - #update-alternatives - if new_resource.default + case tarball_name + when /!^.*\rpm.bin/ + #update-alternatives + if new_resource.default Chef::Log.debug "app_home is #{app_home} and app_dir is #{app_dir}" current_link = ::File.symlink?(app_home) ? ::File.readlink(app_home) : nil if current_link != app_dir @@ -167,6 +173,7 @@ def download_jdk(tarball_name, new_resource) end end end + end end end diff --git a/recipes/oracle.rb b/recipes/oracle.rb index f85011e9..588a55f6 100644 --- a/recipes/oracle.rb +++ b/recipes/oracle.rb @@ -54,7 +54,7 @@ url tarball_url checksum tarball_checksum app_home java_home - bin_cmds [ "java" ] + bin_cmds [ "java", "javac" ] action :install end diff --git a/recipes/oracle_jre.rb b/recipes/oracle_jre.rb new file mode 100644 index 00000000..79da0939 --- /dev/null +++ b/recipes/oracle_jre.rb @@ -0,0 +1,59 @@ +# +# Author:: Bryan W. Berry () +# Cookbook Name:: java +# Recipe:: oracle +# +# Copyright 2011, Bryan w. Berry +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +java_home = node['java']["java_home"] +arch = node['java']['arch'] +jre_version = node['java']['jre_version'] + +#convert version number to a string if it isn't already +if jre_version.instance_of? Fixnum + jre_version = jre_version.to_s +end + +case jre_version +when "6" + tarball_url = node['java']['jre']['6'][arch]['url'] + tarball_checksum = node['java']['jre']['6'][arch]['checksum'] +when "7" + tarball_url = node['java']['jre']['7'][arch]['url'] + tarball_checksum = node['java']['jre']['7'][arch]['checksum'] +end + +ruby_block "set-env-java-home" do + block do + ENV["JAVA_HOME"] = java_home + end +end + +file "/etc/profile.d/jre.sh" do + content <<-EOS + export JAVA_HOME=#{node['java']["java_home"]} + EOS + mode 0755 +end + + +java_ark "jre" do + url tarball_url + checksum tarball_checksum + app_home java_home + bin_cmds [ "java" ] + action :install +end From 670b21df97cbb554d422a7dc8fce437514349ae5 Mon Sep 17 00:00:00 2001 From: Eric Edgar Date: Thu, 4 Oct 2012 20:50:24 -0500 Subject: [PATCH 2/2] Repair support for ubuntu.... and remain backwards compatible with centos. --- providers/ark.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/providers/ark.rb b/providers/ark.rb index 8e4bf2a7..af622dd0 100644 --- a/providers/ark.rb +++ b/providers/ark.rb @@ -105,6 +105,7 @@ def download_jdk(tarball_name, new_resource) tmpdir = Dir.mktmpdir case tarball_name when /^.*\.bin/ + Chef::Log.debug("Extracting #{tarball_name} to #{tmpdir}") cmd = Chef::ShellOut.new( %Q[ cd "#{tmpdir}"; cp "#{Chef::Config[:file_cache_path]}/#{tarball_name}" . ; @@ -129,8 +130,8 @@ def download_jdk(tarball_name, new_resource) end end - case tarball_name - when /!^.*\rpm.bin/ + if not ( tarball_name =~ /^.*rpm\.bin/ ) + Chef::Log.debug("mv #{tmpdir}/#{app_dir_name} to #{app_dir}") cmd = Chef::ShellOut.new( %Q[ mv "#{tmpdir}/#{app_dir_name}" "#{app_dir}" ] ).run_command @@ -143,8 +144,7 @@ def download_jdk(tarball_name, new_resource) new_resource.updated_by_last_action(true) end - case tarball_name - when /!^.*\rpm.bin/ + if not ( tarball_name =~ /^.*rpm\.bin/ ) #update-alternatives if new_resource.default Chef::Log.debug "app_home is #{app_home} and app_dir is #{app_dir}"