Skip to content

Commit cf960ba

Browse files
author
jtimberman
committed
[COOK-858] - account for freebsd and archlinux
* Add java_home attribute for both platforms * Only perform update-alternatives on debian/redhat families
1 parent 3fadd9e commit cf960ba

File tree

2 files changed

+36
-30
lines changed

2 files changed

+36
-30
lines changed

attributes/default.rb

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
case platform
2626
when "centos","redhat","fedora"
2727
default['java']['java_home'] = "/usr/lib/jvm/java"
28+
when "freebsd"
29+
default['java']['java_home'] = "/usr/local/openjdk#{java['jdk_version']}"
30+
when "arch"
31+
default['java']['java_home'] = "//usr/lib/jvm/java-#{java['jdk_version']}-openjdk"
2832
else
2933
default['java']['java_home'] = "/usr/lib/jvm/default-java"
3034
end

recipes/openjdk.rb

+32-30
Original file line numberDiff line numberDiff line change
@@ -39,43 +39,45 @@
3939
end
4040
end
4141

42-
ruby_block "update-java-alternatives" do
43-
block do
44-
if platform?("ubuntu", "debian") and version == 6
45-
run_context = Chef::RunContext.new(node, {})
46-
r = Chef::Resource::Execute.new("update-java-alternatives", run_context)
47-
r.command "update-java-alternatives -s java-6-openjdk"
48-
r.returns [0,2]
49-
r.run_action(:create)
50-
else
51-
# have to do this on ubuntu for version 7 because Ubuntu does
52-
# not currently set jdk 7 as the default jvm on installation
53-
require "fileutils"
54-
arch = node['kernel']['machine'] =~ /x86_64/ ? "x86_64" : "i386"
55-
Chef::Log.debug("glob is #{java_home_parent}/java*#{version}*openjdk*")
56-
jdk_home = Dir.glob("#{java_home_parent}/java*#{version}*openjdk{,[-\.]#{arch}}")[0]
57-
Chef::Log.debug("jdk_home is #{jdk_home}")
58-
# delete the symlink if it already exists
59-
if File.exists? java_home
60-
FileUtils.rm_f java_home
61-
end
62-
FileUtils.ln_sf jdk_home, java_home
63-
64-
cmd = Chef::ShellOut.new(
65-
%Q[ update-alternatives --install /usr/bin/java java #{java_home}/bin/java 1;
42+
if platform?("ubuntu","debian","redhat","centos","fedora","scientific","amazon")
43+
ruby_block "update-java-alternatives" do
44+
block do
45+
if platform?("ubuntu", "debian") and version == 6
46+
run_context = Chef::RunContext.new(node, {})
47+
r = Chef::Resource::Execute.new("update-java-alternatives", run_context)
48+
r.command "update-java-alternatives -s java-6-openjdk"
49+
r.returns [0,2]
50+
r.run_action(:create)
51+
else
52+
# have to do this on ubuntu for version 7 because Ubuntu does
53+
# not currently set jdk 7 as the default jvm on installation
54+
require "fileutils"
55+
arch = node['kernel']['machine'] =~ /x86_64/ ? "x86_64" : "i386"
56+
Chef::Log.debug("glob is #{java_home_parent}/java*#{version}*openjdk*")
57+
jdk_home = Dir.glob("#{java_home_parent}/java*#{version}*openjdk{,[-\.]#{arch}}")[0]
58+
Chef::Log.debug("jdk_home is #{jdk_home}")
59+
# delete the symlink if it already exists
60+
if File.exists? java_home
61+
FileUtils.rm_f java_home
62+
end
63+
FileUtils.ln_sf jdk_home, java_home
64+
65+
cmd = Chef::ShellOut.new(
66+
%Q[ update-alternatives --install /usr/bin/java java #{java_home}/bin/java 1;
6667
update-alternatives --set java #{java_home}/bin/java ]
67-
).run_command
68-
unless cmd.exitstatus == 0 or cmd.exitstatus == 2
69-
Chef::Application.fatal!("Failed to update-alternatives for openjdk!")
68+
).run_command
69+
unless cmd.exitstatus == 0 or cmd.exitstatus == 2
70+
Chef::Application.fatal!("Failed to update-alternatives for openjdk!")
71+
end
7072
end
7173
end
74+
action :nothing
7275
end
73-
action :nothing
7476
end
75-
77+
7678
pkgs.each do |pkg|
7779
package pkg do
7880
action :install
79-
notifies :create, "ruby_block[update-java-alternatives]"
81+
notifies :create, "ruby_block[update-java-alternatives]" if platform?("ubuntu","debian","redhat","centos","fedora","scientific","amazon")
8082
end
8183
end

0 commit comments

Comments
 (0)