Skip to content

Commit

Permalink
Merge branch 'COOK-382'
Browse files Browse the repository at this point in the history
* COOK-382:
  deprecated java_sun cookbook
  final tweaks for combined jdk cookbook
  first pass at a combined openjdk and sun java cookbook
  • Loading branch information
schisamo committed Oct 29, 2010
2 parents c48813e + c7e5a7c commit 7325fa1
Show file tree
Hide file tree
Showing 14 changed files with 291 additions and 164 deletions.
67 changes: 67 additions & 0 deletions java/README.md
Original file line number Diff line number Diff line change
@@ -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)
* CentOS, Red Hat, 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
Original file line number Diff line number Diff line change
@@ -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 "centos","redhat","fedora"
set["java"]["java_home"] = "/usr/lib/jvm/java"
else
set["java"]["java_home"] = "/usr/lib/jvm/default-java"
end
81 changes: 42 additions & 39 deletions java/metadata.json
Original file line number Diff line number Diff line change
@@ -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* 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 (<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"
}
}
9 changes: 4 additions & 5 deletions java/metadata.rb
Original file line number Diff line number Diff line change
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"

%w{ debian ubuntu redhat centos fedora }.each do |os|
depends "apt"
%w{ debian ubuntu centos redhat fedora }.each do |os|
supports os
end
recipe "java", "Installs openjdk to provide Java"
55 changes: 43 additions & 12 deletions java/recipes/default.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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(
["debian","ubuntu"] => {
"default" => ["openjdk-6-jre","default-jre","icedtea6-plugin"] # icedtea6-plugin included to make update-java-alternatives work correctly
},
["centos","redhat","fedora"] => {
"default" => ["java-1.6.0-openjdk","java-1.6.0-openjdk-devel"]
},
"default" => ["openjdk-6-jre-headless","default-jre-headless","default-jre"]
)
37 changes: 37 additions & 0 deletions java/recipes/sun.rb
Original file line number Diff line number Diff line change
@@ -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(
["debian","ubuntu"] => {
"default" => ["sun-java6-jre","default-jre-headless"]
},
"default" => ["sun-java6-jre"]
)

case node.platform
when "debian","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 Debian/Ubuntu at this time.")
end
8 changes: 4 additions & 4 deletions java_sun/README.rdoc
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
= DESCRIPTION:

Installs Sun Java.
THIS COOKBOOK HAS BEEN DEPRECATED. Please use the `java` cookbook with the proper `install_flavor` attribute set.

The default recipe in this cookbook simply points to the `java::default` recipe with the proper `node["java"]["install_flavor"]` attribute set to `sun`

= REQUIREMENTS:

Platform: Ubuntu, Debian.

Enable the 'multiverse' repository on Ubuntu, 'non-free' on Debian, or edit the default recipe to point at the Java package for your platform.

= USAGE:

Simply include the recipe where you want Java installed. Note the respository requirement above to get the right package. On Debian and Ubuntu systems, the recipe will preseed the package and update java alternaties.
Simply include the recipe where you want Sun Java installed.

= LICENSE and AUTHOR:

Expand Down
Loading

0 comments on commit 7325fa1

Please sign in to comment.