Skip to content

Commit

Permalink
first pass at a combined openjdk and sun java cookbook
Browse files Browse the repository at this point in the history
  • Loading branch information
schisamo committed Oct 29, 2010
1 parent c48813e commit cbd222e
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 84 deletions.
67 changes: 67 additions & 0 deletions java/README.md
@@ -0,0 +1,67 @@
Description
===========

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

Requirements
============

Platform:

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

The following Opscode cookbooks are dependencies:

* apt

Attributes
==========

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

Usage
=====

Simply include the recipe where you want Java installed.

If you would like to use the Sun flavor of Java, create a role and set the `java[install_flavor]` attribute to `'sun'`.

% knife role show java
{
"name": "java",
"chef_type": "role",
"json_class": "Chef::Role",
"default_attributes": {
"java": {
"install_flavor":"sun"
}
},
"description": "",
"run_list": [
"recipe[java]"
],
"override_attributes": {
}
}

The Sun flavor of Java is only supported on Debian and Ubuntu systems, the recipe will preseed the package and update java alternatives.

License and Author
==================

Author:: Seth Chisamore (<schisamo@opscode.com>)

Copyright:: 2008-2010, Opscode, Inc

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
29 changes: 0 additions & 29 deletions java/README.rdoc

This file was deleted.

26 changes: 26 additions & 0 deletions java/attributes/default.rb
@@ -0,0 +1,26 @@
#
# Cookbook Name:: java
# Attributes:: default
#
# Copyright 2010, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

default["java"]["install_flavor"] = "openjdk"

case platform
when "redhat","centos","fedora"
set["java"]["java_home"] = "/usr/lib/jvm/default-java"
else
set["java"]["java_home"] = "/usr/lib/jvm/default-java"
end
81 changes: 42 additions & 39 deletions java/metadata.json
@@ -1,45 +1,48 @@
{
"recommendations": {
},
"attributes": {
},
"maintainer": "Opscode, Inc.",
"suggestions": {
},
"dependencies": {
},
"maintainer_email": "cookbooks@opscode.com",
"conflicting": {
},
"platforms": {
"debian": [
"providing": {
},
"maintainer": "Opscode, Inc.",
"replacing": {
},
"description": "Installs java via openjdk.",
"maintainer_email": "cookbooks@opscode.com",
"groupings": {
},
"attributes": {
},
"recommendations": {
},
"dependencies": {
"apt": [

],
"fedora": [
]
},
"suggestions": {
},
"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 (<schisamo@opscode.com>)\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",
"platforms": {
"debian": [

],
"centos": [
],
"fedora": [

],
"ubuntu": [
],
"centos": [

],
"redhat": [
],
"ubuntu": [

]
},
"license": "Apache 2.0",
"version": "0.10.2",
"providing": {
},
"recipes": {
"java": "Installs openjdk to provide Java"
},
"replacing": {
},
"name": "java",
"description": "Installs java via openjdk.",
"groupings": {
},
"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"
}
],
"redhat": [

]
},
"name": "java",
"version": "0.10.2",
"conflicting": {
},
"license": "Apache 2.0",
"recipes": {
"java": "Installs openjdk to provide Java"
}
}
7 changes: 3 additions & 4 deletions java/metadata.rb
Expand Up @@ -2,11 +2,10 @@
maintainer_email "cookbooks@opscode.com"
license "Apache 2.0"
description "Installs java via openjdk."
long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.10.2"

recipe "java", "Installs openjdk to provide Java"

depends "apt"
%w{ debian ubuntu redhat centos fedora }.each do |os|
supports os
end
recipe "java", "Installs openjdk to provide Java"
55 changes: 43 additions & 12 deletions java/recipes/default.rb
Expand Up @@ -2,7 +2,7 @@
# Cookbook Name:: java
# Recipe:: default
#
# Copyright 2008-2009, Opscode, Inc.
# Copyright 2008-2010, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -16,17 +16,48 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
include_recipe "java::#{node["java"]["install_flavor"]}"

java_pkg = value_for_platform(
[ "ubuntu", "debian" ] => {
"default" => "openjdk-6-jre-headless"
},
[ "redhat", "centos", "fedora" ] => {
"default" => "java-1.6.0-openjdk"
},
"default" => "openjdk-6-jre-headless"
)
current_java_version_pattern = (node.java.install_flavor == 'sun') ? /Java HotSpot\(TM\)/ : /^OpenJDK/

package java_pkg do
action :install
# force ohai to run and pick up new languages.java data
ruby_block "reload_ohai" do
block do
o = Ohai::System.new
o.all_plugins
node.automatic_attrs.merge! o.data
end
action :nothing
end

execute "update-java-alternatives" do
command "update-java-alternatives --jre -s java-6-#{node["java"]["install_flavor"]}"
returns 0
only_if do platform?("ubuntu", "debian") end
action :nothing
notifies :create, resources(:ruby_block => "reload_ohai")
end

node.run_state[:java_pkgs].each do |pkg|
package pkg do
action :install
if platform?("ubuntu", "debian")
if node.java.install_flavor == "sun"
response_file "java.seed"
end
notifies :run, resources(:execute => "update-java-alternatives"), :delayed
end
end
end

# re-run update-java-alternatives if our java flavor changes
if node.languages.attribute?("java")
unless node.languages.java.hotspot.name.match(current_java_version_pattern)
log "Java install_flavor has changed, re-running 'update-java-alternatives'" do
level :info
notifies :run, resources(:execute => "update-java-alternatives"), :delayed
end
end
end

node.run_state.delete(:java_pkgs)
27 changes: 27 additions & 0 deletions java/recipes/openjdk.rb
@@ -0,0 +1,27 @@
#
# Cookbook Name:: java
# Recipe:: openjdk
#
# Copyright 2010, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

node.run_state[:java_pkgs] = value_for_platform(
[ "ubuntu", "debian" ] => {
"default" => ["openjdk-6-jre","default-jre","icedtea6-plugin"] # icedtea6-plugin included to make update-java-alternatives work correctly
},
[ "redhat", "centos", "fedora" ] => {
"default" => ["java-1.6.0-openjdk"]
},
"default" => ["openjdk-6-jre-headless","default-jre-headless","default-jre"]
)
37 changes: 37 additions & 0 deletions java/recipes/sun.rb
@@ -0,0 +1,37 @@
#
# Cookbook Name:: java
# Recipe:: sun
#
# Copyright 2010, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

node.run_state[:java_pkgs] = value_for_platform(
[ "ubuntu", "debian" ] => {
"default" => ["sun-java6-jre","default-jre-headless"]
},
"default" => ["sun-java6-jre"]
)

case node.platform
when "ubuntu"
include_recipe "apt"

template "/etc/apt/sources.list.d/canonical.com.list" do
mode "0644"
source "canonical.com.list.erb"
notifies :run, resources(:execute => "apt-get update"), :immediately
end
else
Chef::Log.error("Installation of Sun Java packages are only supported on Ubuntu at this time.")
end
2 changes: 2 additions & 0 deletions java/templates/ubuntu/canonical.com.list.erb
@@ -0,0 +1,2 @@
deb http://archive.canonical.com/ubuntu <%= node[:lsb][:codename] %> partner
deb-src http://archive.canonical.com/ubuntu <%= node[:lsb][:codename] %> partner

0 comments on commit cbd222e

Please sign in to comment.