Permalink
Browse files

[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
  • Loading branch information...
1 parent 9a4d2a6 commit 5ea097e7cc4ab02e466efc92c23f96e4d0a3e18a @schisamo schisamo committed Mar 25, 2011
View
@@ -3,56 +3,69 @@ Description
Installs a Java. Uses OpenJDK by default but supports installation of the Sun's Java (Debian and Ubuntu platforms only).
+---
Requirements
============
-Platform:
+Platform
+--------
* Debian, Ubuntu (OpenJDK, Sun)
* CentOS, Red Hat, Fedora (OpenJDK)
-The following Opscode cookbooks are dependencies:
+Cookbooks
+---------
* apt
+---
Attributes
==========
-* `node["java"]["install_flavor"]` - Type of JRE you would like installed ("sun" or "openjdk"), default "openjdk".
+* `node["java"]["install_flavor"]` - Flavor of JVM you would like installed (`sun` or `openjdk`), default `openjdk`.
+---
+Recipes
+=======
+
+default
+-------
+
+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.
+
+openjdk
+-------
+
+This recipe installs the `openjdk` flavor of Java.
+
+sun
+---
+
+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.
+
+---
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": {
- }
- }
+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:
-The Sun flavor of Java is only supported on Debian and Ubuntu systems, the recipe will preseed the package and update java alternatives.
+ name "java"
+ description "Install Sun Java."
+ override_attributes(
+ "java" => {
+ "install_flavor" => "source"
+ }
+ )
+ run_list(
+ "recipe[java]"
+ )
License and Author
==================
Author:: Seth Chisamore (<schisamo@opscode.com>)
-Copyright:: 2008-2010, Opscode, Inc
+Copyright:: 2008-2011, Opscode, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -2,10 +2,10 @@ sun-java6-bin shared/accepted-sun-dlj-v1-1 boolean true
sun-java6-jdk shared/accepted-sun-dlj-v1-1 boolean true
sun-java6-jre shared/accepted-sun-dlj-v1-1 boolean true
sun-java6-jre sun-java6-jre/stopthread boolean true
-sun-java6-jre sun-java6-jre/jcepolicy note
-sun-java6-bin shared/error-sun-dlj-v1-1 error
-sun-java6-jdk shared/error-sun-dlj-v1-1 error
-sun-java6-jre shared/error-sun-dlj-v1-1 error
-sun-java6-bin shared/present-sun-dlj-v1-1 note
-sun-java6-jdk shared/present-sun-dlj-v1-1 note
-sun-java6-jre shared/present-sun-dlj-v1-1 note
+sun-java6-jre sun-java6-jre/jcepolicy note
+sun-java6-bin shared/error-sun-dlj-v1-1 error
+sun-java6-jdk shared/error-sun-dlj-v1-1 error
+sun-java6-jre shared/error-sun-dlj-v1-1 error
+sun-java6-bin shared/present-sun-dlj-v1-1 note
+sun-java6-jdk shared/present-sun-dlj-v1-1 note
+sun-java6-jre shared/present-sun-dlj-v1-1 note
View
@@ -1,48 +1,50 @@
{
- "providing": {
- },
+ "name": "java",
+ "description": "Installs Java runtime.",
+ "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 (<schisamo@opscode.com>)\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",
"maintainer": "Opscode, Inc.",
- "replacing": {
- },
- "description": "Installs java via openjdk.",
"maintainer_email": "cookbooks@opscode.com",
- "groupings": {
- },
- "attributes": {
- },
- "recommendations": {
- },
- "dependencies": {
- "apt": [
-
- ]
- },
- "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",
+ "license": "Apache 2.0",
"platforms": {
"debian": [
],
- "fedora": [
+ "ubuntu": [
],
"centos": [
],
- "ubuntu": [
+ "redhat": [
],
- "redhat": [
+ "fedora": [
]
},
- "name": "java",
- "version": "0.10.3",
+ "dependencies": {
+ "apt": [
+
+ ]
+ },
+ "recommendations": {
+ },
+ "suggestions": {
+ },
"conflicting": {
},
- "license": "Apache 2.0",
+ "providing": {
+ },
+ "replacing": {
+ },
+ "attributes": {
+ },
+ "groupings": {
+ },
"recipes": {
- "java": "Installs openjdk to provide Java"
- }
+ "java": "Installs Java runtime",
+ "java::openjdk": "Installs the OpenJDK flavor of Java",
+ "java::sun": "Installs the Sun flavor of Java"
+ },
+ "version": "1.0.0"
}
View
@@ -1,11 +1,16 @@
maintainer "Opscode, Inc."
maintainer_email "cookbooks@opscode.com"
license "Apache 2.0"
-description "Installs java via openjdk."
+description "Installs Java runtime."
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
-version "0.10.3"
+version "1.0"
+
depends "apt"
+
+recipe "java", "Installs Java runtime"
+recipe "java::openjdk", "Installs the OpenJDK flavor of Java"
+recipe "java::sun", "Installs the Sun flavor of Java"
+
%w{ debian ubuntu centos redhat fedora }.each do |os|
supports os
end
-recipe "java", "Installs openjdk to provide Java"
@@ -1,8 +1,9 @@
#
+# Author:: Seth Chisamore (<schisamo@opscode.com>)
# Cookbook Name:: java
# Recipe:: default
#
-# Copyright 2008-2010, Opscode, Inc.
+# Copyright 2008-2011, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -16,48 +17,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-include_recipe "java::#{node["java"]["install_flavor"]}"
-current_java_version_pattern = (node.java.install_flavor == 'sun') ? /Java HotSpot\(TM\)/ : /^OpenJDK/
-
-# 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"), :immediately
-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"), :immediately
- end
- end
-end
-
-node.run_state.delete(:java_pkgs)
+include_recipe "java::#{node['java']['install_flavor']}"
@@ -1,8 +1,9 @@
#
+# Author:: Seth Chisamore (<schisamo@opscode.com>)
# Cookbook Name:: java
# Recipe:: openjdk
#
-# Copyright 2010, Opscode, Inc.
+# Copyright 2010-2011, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -16,12 +17,23 @@
# 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
- },
+pkgs = value_for_platform(
["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"]
+ "default" => ["openjdk-6-jre","openjdk-6-jdk","default-jre"]
)
+
+execute "update-java-alternatives" do
+ command "update-java-alternatives -s java-6-openjdk"
+ returns [0,2]
+ action :nothing
+ only_if do platform?("ubuntu", "debian") end
+end
+
+pkgs.each do |pkg|
+ package pkg do
+ action :install
+ notifies :run, "execute[update-java-alternatives]"
+ end
+end
View
@@ -1,8 +1,9 @@
#
+# Author:: Seth Chisamore (<schisamo@opscode.com>)
# Cookbook Name:: java
# Recipe:: sun
#
-# Copyright 2010, Opscode, Inc.
+# Copyright 2010-2011, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -16,22 +17,49 @@
# 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"]
+pkgs = value_for_platform(
+ ["centos","redhat","fedora"] => {
+ "default" => [""]
},
- "default" => ["sun-java6-jre"]
+ ["debian","ubuntu"] => {
+ "default" => ["sun-java6-jre","sun-java6-jdk"]
+ }
)
-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
+case node['platform']
+when "ubuntu"
+ apt_repository "ubuntu-partner" do
+ uri "http://archive.canonical.com/ubuntu"
+ distribution node['lsb']['codename']
+ components ['partner']
+ action :add
+ end
+ # update-java-alternatives doesn't work with only sun java installed
+ node.set['java']['java_home'] = "/usr/lib/jvm/java-6-sun"
+when "debian"
+ apt_repository "debian-non-free" do
+ uri "http://http.us.debian.org/debian"
+ distribution "stable"
+ components ['main','contrib','non-free']
+ action :add
end
+ # update-java-alternatives doesn't work with only sun java installed
+ node.set['java']['java_home'] = "/usr/lib/jvm/java-6-sun"
else
- Chef::Log.error("Installation of Sun Java packages are only supported on Debian/Ubuntu at this time.")
-end
+ Chef::Log.error("Installation of Sun Java packages not supported on this platform.")
+end
+
+execute "update-java-alternatives" do
+ command "update-java-alternatives -s java-6-sun"
+ returns [0,2]
+ action :nothing
+ only_if do platform?("ubuntu", "debian") end
+end
+
+pkgs.each do |pkg|
+ package pkg do
+ response_file "java.seed" if platform?("ubuntu", "debian")
+ action :install
+ notifies :run, "execute[update-java-alternatives]"
+ end
+end
@@ -1,2 +0,0 @@
-deb http://archive.canonical.com/ubuntu <%= node[:lsb][:codename] %> partner
-deb-src http://archive.canonical.com/ubuntu <%= node[:lsb][:codename] %> partner
Oops, something went wrong.

0 comments on commit 5ea097e

Please sign in to comment.