Skip to content

Commit ad91249

Browse files
bryanwbjtimberman
authored and
jtimberman
committed
use inline Execute resource in place of ShellOut command
1 parent 0e54c91 commit ad91249

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

recipes/openjdk.rb

+18-21
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,26 @@
4141

4242
ruby_block "update-java-alternatives" do
4343
block do
44-
require "fileutils"
45-
arch = node['kernel']['machine'] =~ /x86_64/ ? "x86_64" : "i386"
46-
Chef::Log.debug("glob is #{java_home_parent}/java*#{version}*openjdk*")
47-
jdk_home = Dir.glob("#{java_home_parent}/java*#{version}*openjdk{,-#{arch}}")[0]
48-
Chef::Log.debug("jdk_home is #{jdk_home}")
49-
# delete the symlink if it already exists
50-
if File.exists? java_home
51-
FileUtils.rm_f java_home
52-
end
53-
FileUtils.ln_sf jdk_home, java_home
54-
5544
if platform?("ubuntu", "debian") and version == 6
56-
# specific to Ubuntu, this finds the file which specifies all
57-
# the symlinks to be updated
58-
java_link_name = Dir.glob("#{java_home_parent}/.java*#{version}*openjdk.jinfo")[0]
59-
java_link_name = File.basename(java_link_name).split('.')[1..-2].join('.')
60-
cmd = Chef::ShellOut.new(
61-
"update-java-alternatives -s #{java_link_name}"
62-
).run_command
63-
unless cmd.exitstatus == 0 or cmd.exitstatus == 2
64-
Chef::Application.fatal!("Failed to update-alternatives for openjdk!")
65-
end
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)
6650
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+
6764
cmd = Chef::ShellOut.new(
6865
%Q[ update-alternatives --install /usr/bin/java java #{java_home}/bin/java 1;
6966
update-alternatives --set java #{java_home}/bin/java ]

0 commit comments

Comments
 (0)