Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[COOK-858] - account for freebsd and archlinux

* Add java_home attribute for both platforms
* Only perform update-alternatives on debian/redhat families
  • Loading branch information...
commit cf960ba59d543a27b46472acfd3989b085b1819d 1 parent 3fadd9e
@jtimberman jtimberman authored
Showing with 36 additions and 30 deletions.
  1. +4 −0 attributes/default.rb
  2. +32 −30 recipes/openjdk.rb
View
4 attributes/default.rb
@@ -25,6 +25,10 @@
case platform
when "centos","redhat","fedora"
default['java']['java_home'] = "/usr/lib/jvm/java"
+when "freebsd"
+ default['java']['java_home'] = "/usr/local/openjdk#{java['jdk_version']}"
+when "arch"
+ default['java']['java_home'] = "//usr/lib/jvm/java-#{java['jdk_version']}-openjdk"
else
default['java']['java_home'] = "/usr/lib/jvm/default-java"
end
View
62 recipes/openjdk.rb
@@ -39,43 +39,45 @@
end
end
-ruby_block "update-java-alternatives" do
- block do
- if platform?("ubuntu", "debian") and version == 6
- run_context = Chef::RunContext.new(node, {})
- r = Chef::Resource::Execute.new("update-java-alternatives", run_context)
- r.command "update-java-alternatives -s java-6-openjdk"
- r.returns [0,2]
- r.run_action(:create)
- else
- # have to do this on ubuntu for version 7 because Ubuntu does
- # not currently set jdk 7 as the default jvm on installation
- require "fileutils"
- arch = node['kernel']['machine'] =~ /x86_64/ ? "x86_64" : "i386"
- Chef::Log.debug("glob is #{java_home_parent}/java*#{version}*openjdk*")
- jdk_home = Dir.glob("#{java_home_parent}/java*#{version}*openjdk{,[-\.]#{arch}}")[0]
- Chef::Log.debug("jdk_home is #{jdk_home}")
- # delete the symlink if it already exists
- if File.exists? java_home
- FileUtils.rm_f java_home
- end
- FileUtils.ln_sf jdk_home, java_home
-
- cmd = Chef::ShellOut.new(
- %Q[ update-alternatives --install /usr/bin/java java #{java_home}/bin/java 1;
+if platform?("ubuntu","debian","redhat","centos","fedora","scientific","amazon")
+ ruby_block "update-java-alternatives" do
+ block do
+ if platform?("ubuntu", "debian") and version == 6
+ run_context = Chef::RunContext.new(node, {})
+ r = Chef::Resource::Execute.new("update-java-alternatives", run_context)
+ r.command "update-java-alternatives -s java-6-openjdk"
+ r.returns [0,2]
+ r.run_action(:create)
+ else
+ # have to do this on ubuntu for version 7 because Ubuntu does
+ # not currently set jdk 7 as the default jvm on installation
+ require "fileutils"
+ arch = node['kernel']['machine'] =~ /x86_64/ ? "x86_64" : "i386"
+ Chef::Log.debug("glob is #{java_home_parent}/java*#{version}*openjdk*")
+ jdk_home = Dir.glob("#{java_home_parent}/java*#{version}*openjdk{,[-\.]#{arch}}")[0]
+ Chef::Log.debug("jdk_home is #{jdk_home}")
+ # delete the symlink if it already exists
+ if File.exists? java_home
+ FileUtils.rm_f java_home
+ end
+ FileUtils.ln_sf jdk_home, java_home
+
+ cmd = Chef::ShellOut.new(
+ %Q[ update-alternatives --install /usr/bin/java java #{java_home}/bin/java 1;
update-alternatives --set java #{java_home}/bin/java ]
- ).run_command
- unless cmd.exitstatus == 0 or cmd.exitstatus == 2
- Chef::Application.fatal!("Failed to update-alternatives for openjdk!")
+ ).run_command
+ unless cmd.exitstatus == 0 or cmd.exitstatus == 2
+ Chef::Application.fatal!("Failed to update-alternatives for openjdk!")
+ end
end
end
+ action :nothing
end
- action :nothing
end
-
+
pkgs.each do |pkg|
package pkg do
action :install
- notifies :create, "ruby_block[update-java-alternatives]"
+ notifies :create, "ruby_block[update-java-alternatives]" if platform?("ubuntu","debian","redhat","centos","fedora","scientific","amazon")
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.