Skip to content

Commit 86df17f

Browse files
committed
first pass at a combined openjdk and sun java cookbook
1 parent 5569d80 commit 86df17f

9 files changed

Lines changed: 247 additions & 84 deletions

File tree

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
Description
2+
===========
3+
4+
Installs a Java. Uses OpenJDK by default but supports installation of the Sun's Java (Debian and Ubuntu platforms only).
5+
6+
Requirements
7+
============
8+
9+
Platform:
10+
11+
* Debian, Ubuntu (OpenJDK, Sun)
12+
* Red Hat, CentOS, Fedora (OpenJDK)
13+
14+
The following Opscode cookbooks are dependencies:
15+
16+
* apt
17+
18+
Attributes
19+
==========
20+
21+
* `node["java"]["install_flavor"]` - Type of JRE you would like installed ("sun" or "openjdk"), default "openjdk".
22+
23+
Usage
24+
=====
25+
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+
}
47+
48+
The Sun flavor of Java is only supported on Debian and Ubuntu systems, the recipe will preseed the package and update java alternatives.
49+
50+
License and Author
51+
==================
52+
53+
Author:: Seth Chisamore (<[email protected]>)
54+
55+
Copyright:: 2008-2010, Opscode, Inc
56+
57+
Licensed under the Apache License, Version 2.0 (the "License");
58+
you may not use this file except in compliance with the License.
59+
You may obtain a copy of the License at
60+
61+
http://www.apache.org/licenses/LICENSE-2.0
62+
63+
Unless required by applicable law or agreed to in writing, software
64+
distributed under the License is distributed on an "AS IS" BASIS,
65+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
66+
See the License for the specific language governing permissions and
67+
limitations under the License.

README.rdoc

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

attributes/default.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# Cookbook Name:: java
3+
# Attributes:: default
4+
#
5+
# Copyright 2010, Opscode, Inc.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
default["java"]["install_flavor"] = "openjdk"
20+
21+
case platform
22+
when "redhat","centos","fedora"
23+
set["java"]["java_home"] = "/usr/lib/jvm/default-java"
24+
else
25+
set["java"]["java_home"] = "/usr/lib/jvm/default-java"
26+
end

metadata.json

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,48 @@
11
{
2-
"recommendations": {
3-
},
4-
"attributes": {
5-
},
6-
"maintainer": "Opscode, Inc.",
7-
"suggestions": {
8-
},
9-
"dependencies": {
10-
},
11-
"maintainer_email": "[email protected]",
12-
"conflicting": {
13-
},
14-
"platforms": {
15-
"debian": [
2+
"providing": {
3+
},
4+
"maintainer": "Opscode, Inc.",
5+
"replacing": {
6+
},
7+
"description": "Installs java via openjdk.",
8+
"maintainer_email": "[email protected]",
9+
"groupings": {
10+
},
11+
"attributes": {
12+
},
13+
"recommendations": {
14+
},
15+
"dependencies": {
16+
"apt": [
1617

17-
],
18-
"fedora": [
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* Red Hat, CentOS, 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",
23+
"platforms": {
24+
"debian": [
1925

20-
],
21-
"centos": [
26+
],
27+
"fedora": [
2228

23-
],
24-
"ubuntu": [
29+
],
30+
"centos": [
2531

26-
],
27-
"redhat": [
32+
],
33+
"ubuntu": [
2834

29-
]
30-
},
31-
"license": "Apache 2.0",
32-
"version": "0.10.2",
33-
"providing": {
34-
},
35-
"recipes": {
36-
"java": "Installs openjdk to provide Java"
37-
},
38-
"replacing": {
39-
},
40-
"name": "java",
41-
"description": "Installs java via openjdk.",
42-
"groupings": {
43-
},
44-
"long_description": "= DESCRIPTION:\n\nInstalls Java and Ant. Uses OpenJDK, Sun's Java is deprecated in Ubuntu and may not be available in the future.\n\n= REQUIREMENTS:\n\nPlatform: Ubuntu, Debian, Red Hat, CentOS, Fedora.\n\nEnable the 'multiverse' repository on Ubuntu, 'non-free' on Debian or EPEL on RH/Cent/Fedora to get the Java package, or edit the default recipe to point at the Java package for your platform.\n\n= USAGE:\n\nSimply include the recipe where you want Java installed. Note the repository requirement above to get the right package. On Debian and Ubuntu systems, the recipe will preseed the package and update java alternaties.\n\n= LICENSE and AUTHOR:\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"
45-
}
35+
],
36+
"redhat": [
37+
38+
]
39+
},
40+
"name": "java",
41+
"version": "0.10.2",
42+
"conflicting": {
43+
},
44+
"license": "Apache 2.0",
45+
"recipes": {
46+
"java": "Installs openjdk to provide Java"
47+
}
48+
}

metadata.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
maintainer_email "[email protected]"
33
license "Apache 2.0"
44
description "Installs java via openjdk."
5-
long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
5+
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
66
version "0.10.2"
7-
8-
recipe "java", "Installs openjdk to provide Java"
9-
7+
depends "apt"
108
%w{ debian ubuntu redhat centos fedora }.each do |os|
119
supports os
1210
end
11+
recipe "java", "Installs openjdk to provide Java"

recipes/default.rb

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Cookbook Name:: java
33
# Recipe:: default
44
#
5-
# Copyright 2008-2009, Opscode, Inc.
5+
# Copyright 2008-2010, Opscode, Inc.
66
#
77
# Licensed under the Apache License, Version 2.0 (the "License");
88
# you may not use this file except in compliance with the License.
@@ -16,17 +16,48 @@
1616
# See the License for the specific language governing permissions and
1717
# limitations under the License.
1818
#
19+
include_recipe "java::#{node["java"]["install_flavor"]}"
1920

20-
java_pkg = value_for_platform(
21-
[ "ubuntu", "debian" ] => {
22-
"default" => "openjdk-6-jre-headless"
23-
},
24-
[ "redhat", "centos", "fedora" ] => {
25-
"default" => "java-1.6.0-openjdk"
26-
},
27-
"default" => "openjdk-6-jre-headless"
28-
)
21+
current_java_version_pattern = (node.java.install_flavor == 'sun') ? /Java HotSpot\(TM\)/ : /^OpenJDK/
2922

30-
package java_pkg do
31-
action :install
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
3231
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")
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"), :delayed
59+
end
60+
end
61+
end
62+
63+
node.run_state.delete(:java_pkgs)

recipes/openjdk.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#
2+
# Cookbook Name:: java
3+
# Recipe:: openjdk
4+
#
5+
# Copyright 2010, Opscode, Inc.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
node.run_state[:java_pkgs] = value_for_platform(
20+
[ "ubuntu", "debian" ] => {
21+
"default" => ["openjdk-6-jre","default-jre","icedtea6-plugin"] # icedtea6-plugin included to make update-java-alternatives work correctly
22+
},
23+
[ "redhat", "centos", "fedora" ] => {
24+
"default" => ["java-1.6.0-openjdk"]
25+
},
26+
"default" => ["openjdk-6-jre-headless","default-jre-headless","default-jre"]
27+
)

recipes/sun.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#
2+
# Cookbook Name:: java
3+
# Recipe:: sun
4+
#
5+
# Copyright 2010, Opscode, Inc.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
node.run_state[:java_pkgs] = value_for_platform(
20+
[ "ubuntu", "debian" ] => {
21+
"default" => ["sun-java6-jre","default-jre-headless"]
22+
},
23+
"default" => ["sun-java6-jre"]
24+
)
25+
26+
case node.platform
27+
when "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
34+
end
35+
else
36+
Chef::Log.error("Installation of Sun Java packages are only supported on Ubuntu at this time.")
37+
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
deb http://archive.canonical.com/ubuntu <%= node[:lsb][:codename] %> partner
2+
deb-src http://archive.canonical.com/ubuntu <%= node[:lsb][:codename] %> partner

0 commit comments

Comments
 (0)