Skip to content

Commit e5dbbb6

Browse files
committed
[COOK-447,COOK-470] simplified java cookbook
* removed reliance on brittle hotspot attribute * usage pattern follows our other major lanuage cookbooks now * fixed sun java debian support
1 parent 4388aab commit e5dbbb6

8 files changed

Lines changed: 147 additions & 131 deletions

File tree

README.md

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,69 @@ Description
33

44
Installs a Java. Uses OpenJDK by default but supports installation of the Sun's Java (Debian and Ubuntu platforms only).
55

6+
---
67
Requirements
78
============
89

9-
Platform:
10+
Platform
11+
--------
1012

1113
* Debian, Ubuntu (OpenJDK, Sun)
1214
* CentOS, Red Hat, Fedora (OpenJDK)
1315

14-
The following Opscode cookbooks are dependencies:
16+
Cookbooks
17+
---------
1518

1619
* apt
1720

21+
---
1822
Attributes
1923
==========
2024

21-
* `node["java"]["install_flavor"]` - Type of JRE you would like installed ("sun" or "openjdk"), default "openjdk".
25+
* `node["java"]["install_flavor"]` - Flavor of JVM you would like installed (`sun` or `openjdk`), default `openjdk`.
2226

27+
---
28+
Recipes
29+
=======
30+
31+
default
32+
-------
33+
34+
Include the default recipe in a run list, to get `java`. By default the `openjdk` flavor of Java is installed, but this can be changed by using the `install_flavor` attribute.
35+
36+
openjdk
37+
-------
38+
39+
This recipe installs the `openjdk` flavor of Java.
40+
41+
sun
42+
---
43+
44+
This recipe installs the `sun` flavor of Java. The Sun flavor of Java is only supported on Debian and Ubuntu systems, the recipe will preseed the package and update java alternatives.
45+
46+
---
2347
Usage
2448
=====
2549

26-
Simply include the recipe where you want Java installed.
27-
28-
If you would like to use the Sun flavor of Java, create a role and set the `java[install_flavor]` attribute to `'sun'`.
29-
30-
% knife role show java
31-
{
32-
"name": "java",
33-
"chef_type": "role",
34-
"json_class": "Chef::Role",
35-
"default_attributes": {
36-
"java": {
37-
"install_flavor":"sun"
38-
}
39-
},
40-
"description": "",
41-
"run_list": [
42-
"recipe[java]"
43-
],
44-
"override_attributes": {
45-
}
46-
}
50+
Simply include the `php` recipe where ever you would like php installed. To install from source override the `node['java']['install_flavor']` attribute with in a role:
4751

48-
The Sun flavor of Java is only supported on Debian and Ubuntu systems, the recipe will preseed the package and update java alternatives.
52+
name "java"
53+
description "Install Sun Java."
54+
override_attributes(
55+
"java" => {
56+
"install_flavor" => "source"
57+
}
58+
)
59+
run_list(
60+
"recipe[java]"
61+
)
4962

5063
License and Author
5164
==================
5265

5366
Author:: Seth Chisamore (<[email protected]>)
5467

55-
Copyright:: 2008-2010, Opscode, Inc
68+
Copyright:: 2008-2011, Opscode, Inc
5669

5770
Licensed under the Apache License, Version 2.0 (the "License");
5871
you may not use this file except in compliance with the License.

files/default/java.seed

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ sun-java6-bin shared/accepted-sun-dlj-v1-1 boolean true
22
sun-java6-jdk shared/accepted-sun-dlj-v1-1 boolean true
33
sun-java6-jre shared/accepted-sun-dlj-v1-1 boolean true
44
sun-java6-jre sun-java6-jre/stopthread boolean true
5-
sun-java6-jre sun-java6-jre/jcepolicy note
6-
sun-java6-bin shared/error-sun-dlj-v1-1 error
7-
sun-java6-jdk shared/error-sun-dlj-v1-1 error
8-
sun-java6-jre shared/error-sun-dlj-v1-1 error
9-
sun-java6-bin shared/present-sun-dlj-v1-1 note
10-
sun-java6-jdk shared/present-sun-dlj-v1-1 note
11-
sun-java6-jre shared/present-sun-dlj-v1-1 note
5+
sun-java6-jre sun-java6-jre/jcepolicy note
6+
sun-java6-bin shared/error-sun-dlj-v1-1 error
7+
sun-java6-jdk shared/error-sun-dlj-v1-1 error
8+
sun-java6-jre shared/error-sun-dlj-v1-1 error
9+
sun-java6-bin shared/present-sun-dlj-v1-1 note
10+
sun-java6-jdk shared/present-sun-dlj-v1-1 note
11+
sun-java6-jre shared/present-sun-dlj-v1-1 note

metadata.json

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,50 @@
11
{
2-
"providing": {
3-
},
2+
"name": "java",
3+
"description": "Installs Java runtime.",
4+
"long_description": "Description\n===========\n\nInstalls a Java. Uses OpenJDK by default but supports installation of the Sun's Java (Debian and Ubuntu platforms only).\n\n---\nRequirements\n============\n\nPlatform\n--------\n\n* Debian, Ubuntu (OpenJDK, Sun)\n* CentOS, Red Hat, Fedora (OpenJDK)\n\nCookbooks\n---------\n\n* apt\n\n---\nAttributes\n==========\n\n* `node[\"java\"][\"install_flavor\"]` - Flavor of JVM you would like installed (`sun` or `openjdk`), default `openjdk`.\n\n---\nRecipes\n=======\n\ndefault\n-------\n\nInclude the default recipe in a run list, to get `java`. By default the `openjdk` flavor of Java is installed, but this can be changed by using the `install_flavor` attribute.\n\nopenjdk\n-------\n\nThis recipe installs the `openjdk` flavor of Java.\n\nsun\n---\n\nThis recipe installs the `sun` flavor of Java. The Sun flavor of Java is only supported on Debian and Ubuntu systems, the recipe will preseed the package and update java alternatives.\n\n---\nUsage\n=====\n\nSimply include the `php` recipe where ever you would like php installed. To install from source override the `node['java']['install_flavor']` attribute with in a role:\n\n name \"java\"\n description \"Install Sun Java.\"\n override_attributes(\n \"java\" => {\n \"install_flavor\" => \"source\"\n }\n )\n run_list(\n \"recipe[java]\"\n )\n\nLicense and Author\n==================\n\nAuthor:: Seth Chisamore (<[email protected]>)\n\nCopyright:: 2008-2011, Opscode, Inc\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n",
45
"maintainer": "Opscode, Inc.",
5-
"replacing": {
6-
},
7-
"description": "Installs java via openjdk.",
86
"maintainer_email": "[email protected]",
9-
"groupings": {
10-
},
11-
"attributes": {
12-
},
13-
"recommendations": {
14-
},
15-
"dependencies": {
16-
"apt": [
17-
18-
]
19-
},
20-
"suggestions": {
21-
},
22-
"long_description": "Description\n===========\n\nInstalls a Java. Uses OpenJDK by default but supports installation of the Sun's Java (Debian and Ubuntu platforms only).\n\nRequirements\n============\n\nPlatform: \n\n* Debian, Ubuntu (OpenJDK, Sun)\n* CentOS, Red Hat, Fedora (OpenJDK)\n\nThe following Opscode cookbooks are dependencies:\n\n* apt\n\nAttributes\n==========\n\n* `node[\"java\"][\"install_flavor\"]` - Type of JRE you would like installed (\"sun\" or \"openjdk\"), default \"openjdk\".\n\nUsage\n=====\n\nSimply include the recipe where you want Java installed.\n\nIf you would like to use the Sun flavor of Java, create a role and set the `java[install_flavor]` attribute to `'sun'`. \n\n % knife role show java\n {\n \"name\": \"java\",\n \"chef_type\": \"role\",\n \"json_class\": \"Chef::Role\",\n \"default_attributes\": {\n \"java\": {\n \"install_flavor\":\"sun\"\n }\n },\n \"description\": \"\",\n \"run_list\": [\n \"recipe[java]\"\n ],\n \"override_attributes\": {\n }\n }\n\nThe Sun flavor of Java is only supported on Debian and Ubuntu systems, the recipe will preseed the package and update java alternatives.\n\nLicense and Author\n==================\n\nAuthor:: Seth Chisamore (<[email protected]>)\n\nCopyright:: 2008-2010, Opscode, Inc\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n",
7+
"license": "Apache 2.0",
238
"platforms": {
249
"debian": [
2510

2611
],
27-
"fedora": [
12+
"ubuntu": [
2813

2914
],
3015
"centos": [
3116

3217
],
33-
"ubuntu": [
18+
"redhat": [
3419

3520
],
36-
"redhat": [
21+
"fedora": [
3722

3823
]
3924
},
40-
"name": "java",
41-
"version": "0.10.3",
25+
"dependencies": {
26+
"apt": [
27+
28+
]
29+
},
30+
"recommendations": {
31+
},
32+
"suggestions": {
33+
},
4234
"conflicting": {
4335
},
44-
"license": "Apache 2.0",
36+
"providing": {
37+
},
38+
"replacing": {
39+
},
40+
"attributes": {
41+
},
42+
"groupings": {
43+
},
4544
"recipes": {
46-
"java": "Installs openjdk to provide Java"
47-
}
45+
"java": "Installs Java runtime",
46+
"java::openjdk": "Installs the OpenJDK flavor of Java",
47+
"java::sun": "Installs the Sun flavor of Java"
48+
},
49+
"version": "1.0.0"
4850
}

metadata.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
maintainer "Opscode, Inc."
22
maintainer_email "[email protected]"
33
license "Apache 2.0"
4-
description "Installs java via openjdk."
4+
description "Installs Java runtime."
55
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
6-
version "0.10.3"
6+
version "1.0"
7+
78
depends "apt"
9+
10+
recipe "java", "Installs Java runtime"
11+
recipe "java::openjdk", "Installs the OpenJDK flavor of Java"
12+
recipe "java::sun", "Installs the Sun flavor of Java"
13+
814
%w{ debian ubuntu centos redhat fedora }.each do |os|
915
supports os
1016
end
11-
recipe "java", "Installs openjdk to provide Java"

recipes/default.rb

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#
2+
# Author:: Seth Chisamore (<[email protected]>)
23
# Cookbook Name:: java
34
# Recipe:: default
45
#
5-
# Copyright 2008-2010, Opscode, Inc.
6+
# Copyright 2008-2011, Opscode, Inc.
67
#
78
# Licensed under the Apache License, Version 2.0 (the "License");
89
# you may not use this file except in compliance with the License.
@@ -16,48 +17,5 @@
1617
# See the License for the specific language governing permissions and
1718
# limitations under the License.
1819
#
19-
include_recipe "java::#{node["java"]["install_flavor"]}"
2020

21-
current_java_version_pattern = (node.java.install_flavor == 'sun') ? /Java HotSpot\(TM\)/ : /^OpenJDK/
22-
23-
# force ohai to run and pick up new languages.java data
24-
ruby_block "reload_ohai" do
25-
block do
26-
o = Ohai::System.new
27-
o.all_plugins
28-
node.automatic_attrs.merge! o.data
29-
end
30-
action :nothing
31-
end
32-
33-
execute "update-java-alternatives" do
34-
command "update-java-alternatives --jre -s java-6-#{node["java"]["install_flavor"]}"
35-
returns 0
36-
only_if do platform?("ubuntu", "debian") end
37-
action :nothing
38-
notifies :create, resources(:ruby_block => "reload_ohai"), :immediately
39-
end
40-
41-
node.run_state[:java_pkgs].each do |pkg|
42-
package pkg do
43-
action :install
44-
if platform?("ubuntu", "debian")
45-
if node.java.install_flavor == "sun"
46-
response_file "java.seed"
47-
end
48-
notifies :run, resources(:execute => "update-java-alternatives"), :delayed
49-
end
50-
end
51-
end
52-
53-
# re-run update-java-alternatives if our java flavor changes
54-
if node.languages.attribute?("java")
55-
unless node.languages.java.hotspot.name.match(current_java_version_pattern)
56-
log "Java install_flavor has changed, re-running 'update-java-alternatives'" do
57-
level :info
58-
notifies :run, resources(:execute => "update-java-alternatives"), :immediately
59-
end
60-
end
61-
end
62-
63-
node.run_state.delete(:java_pkgs)
21+
include_recipe "java::#{node['java']['install_flavor']}"

recipes/openjdk.rb

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#
2+
# Author:: Seth Chisamore (<[email protected]>)
23
# Cookbook Name:: java
34
# Recipe:: openjdk
45
#
5-
# Copyright 2010, Opscode, Inc.
6+
# Copyright 2010-2011, Opscode, Inc.
67
#
78
# Licensed under the Apache License, Version 2.0 (the "License");
89
# you may not use this file except in compliance with the License.
@@ -16,12 +17,23 @@
1617
# See the License for the specific language governing permissions and
1718
# limitations under the License.
1819

19-
node.run_state[:java_pkgs] = value_for_platform(
20-
["debian","ubuntu"] => {
21-
"default" => ["openjdk-6-jre","default-jre","icedtea6-plugin"] # icedtea6-plugin included to make update-java-alternatives work correctly
22-
},
20+
pkgs = value_for_platform(
2321
["centos","redhat","fedora"] => {
2422
"default" => ["java-1.6.0-openjdk","java-1.6.0-openjdk-devel"]
2523
},
26-
"default" => ["openjdk-6-jre-headless","default-jre-headless","default-jre"]
24+
"default" => ["openjdk-6-jre","openjdk-6-jdk","default-jre"]
2725
)
26+
27+
execute "update-java-alternatives" do
28+
command "update-java-alternatives -s java-6-openjdk"
29+
returns [0,2]
30+
action :nothing
31+
only_if do platform?("ubuntu", "debian") end
32+
end
33+
34+
pkgs.each do |pkg|
35+
package pkg do
36+
action :install
37+
notifies :run, "execute[update-java-alternatives]"
38+
end
39+
end

recipes/sun.rb

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#
2+
# Author:: Seth Chisamore (<[email protected]>)
23
# Cookbook Name:: java
34
# Recipe:: sun
45
#
5-
# Copyright 2010, Opscode, Inc.
6+
# Copyright 2010-2011, Opscode, Inc.
67
#
78
# Licensed under the Apache License, Version 2.0 (the "License");
89
# you may not use this file except in compliance with the License.
@@ -16,22 +17,49 @@
1617
# See the License for the specific language governing permissions and
1718
# limitations under the License.
1819

19-
node.run_state[:java_pkgs] = value_for_platform(
20-
["debian","ubuntu"] => {
21-
"default" => ["sun-java6-jre","default-jre-headless"]
20+
pkgs = value_for_platform(
21+
["centos","redhat","fedora"] => {
22+
"default" => [""]
2223
},
23-
"default" => ["sun-java6-jre"]
24+
["debian","ubuntu"] => {
25+
"default" => ["sun-java6-jre","sun-java6-jdk"]
26+
}
2427
)
2528

26-
case node.platform
27-
when "debian","ubuntu"
28-
include_recipe "apt"
29-
30-
template "/etc/apt/sources.list.d/canonical.com.list" do
31-
mode "0644"
32-
source "canonical.com.list.erb"
33-
notifies :run, resources(:execute => "apt-get update"), :immediately
29+
case node['platform']
30+
when "ubuntu"
31+
apt_repository "ubuntu-partner" do
32+
uri "http://archive.canonical.com/ubuntu"
33+
distribution node['lsb']['codename']
34+
components ['partner']
35+
action :add
36+
end
37+
# update-java-alternatives doesn't work with only sun java installed
38+
node.set['java']['java_home'] = "/usr/lib/jvm/java-6-sun"
39+
when "debian"
40+
apt_repository "debian-non-free" do
41+
uri "http://http.us.debian.org/debian"
42+
distribution "stable"
43+
components ['main','contrib','non-free']
44+
action :add
3445
end
46+
# update-java-alternatives doesn't work with only sun java installed
47+
node.set['java']['java_home'] = "/usr/lib/jvm/java-6-sun"
3548
else
36-
Chef::Log.error("Installation of Sun Java packages are only supported on Debian/Ubuntu at this time.")
37-
end
49+
Chef::Log.error("Installation of Sun Java packages not supported on this platform.")
50+
end
51+
52+
execute "update-java-alternatives" do
53+
command "update-java-alternatives -s java-6-sun"
54+
returns [0,2]
55+
action :nothing
56+
only_if do platform?("ubuntu", "debian") end
57+
end
58+
59+
pkgs.each do |pkg|
60+
package pkg do
61+
response_file "java.seed" if platform?("ubuntu", "debian")
62+
action :install
63+
notifies :run, "execute[update-java-alternatives]"
64+
end
65+
end

templates/ubuntu/canonical.com.list.erb

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)