Skip to content

Commit 850dd10

Browse files
committed
[COOK-3704] Fix alternatives when the package is already installed
The current Java cookbook uses a conditional notification on the package installation to notify the java alternatives to update. This actually makes it impossible to switch between java versions, because the default java being set is dependent on the package installation, not the value of the alternative. This patch removes the notification and checks the current value of the alternative to see if it should be updated. This ensure that the correct Java is used, even if the package was already installed.
1 parent 63e3908 commit 850dd10

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

recipes/openjdk.rb

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,6 @@
2121

2222
java_location = Opscode::OpenJDK.new(node).java_location
2323

24-
include_recipe 'java::set_java_home'
25-
26-
if platform_family?('debian', 'rhel', 'fedora')
27-
28-
bash 'update-java-alternatives' do
29-
code <<-EOH.gsub(/^\s+/, '')
30-
update-alternatives --install /usr/bin/java java #{java_location} 1061 && \
31-
update-alternatives --set java #{java_location}
32-
EOH
33-
action :nothing
34-
end
35-
36-
end
37-
3824
if platform_requires_license_acceptance?
3925
file "/opt/local/.dlj_license_accepted" do
4026
owner "root"
@@ -46,10 +32,19 @@
4632
end
4733

4834
node['java']['openjdk_packages'].each do |pkg|
49-
package pkg do
50-
action :install
51-
if pkg == node['java']['openjdk_packages'].last
52-
notifies :run, 'bash[update-java-alternatives]', :immediately if platform_family?('debian', 'rhel', 'fedora')
53-
end
35+
package pkg
36+
end
37+
38+
if platform_family?('debian', 'rhel', 'fedora')
39+
bash 'update-java-alternatives' do
40+
code <<-EOH.gsub(/^\s+/, '')
41+
update-alternatives --install /usr/bin/java java #{java_location} 1061 && \
42+
update-alternatives --set java #{java_location}
43+
EOH
44+
only_if "update-alternatives --display java | grep '#{java_location} - priority 1061'"
5445
end
5546
end
47+
48+
# We must include this recipe AFTER updating the alternatives or else JAVA_HOME
49+
# will not point to the correct java.
50+
include_recipe 'java::set_java_home'

0 commit comments

Comments
 (0)