Permalink
Browse files

Merge pull request #236 from gildegoma/revamp-java-and-add-oraclejdk8

Revamp Java cookbook and add support for Oracle JDK8 (EA Edition)
  • Loading branch information...
2 parents a0b9473 + cbc6aad commit 268819328e9d104ebfe542aca189e597361c5131 @michaelklishin michaelklishin committed Oct 22, 2013
@@ -1,102 +0,0 @@
-Description
-===========
-
-Installs a Java. Uses OpenJDK by default but supports installation of the Sun's Java.
-
----
-Requirements
-============
-
-Platform
---------
-
-* Debian, Ubuntu
-* CentOS, Red Hat, Fedora
-
-Cookbooks
----------
-
-* apt
-
----
-Attributes
-==========
-
-* `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.
-
-On Debian and Ubuntu systems the recipe will add the correct apt repository (`non-free` on Debian or `partner` on Ubuntu), pre-seed the package and update java alternatives.
-
-On Red Hat flavored Linux (RHEL, CentOS, Fedora), the installation of the Sun flavor of Java is slightly more complicated as the `rpm` package is not readily available in any public Yum repository. The Sun JDK `rpm` package can be downloaded directly from Sun but comes wrapped as a compressed bin file. After the file has been downloaded, decompressed and license accepted the `rpm` package (names something like `jdk-6u25-ea-linux-amd64.rpm`) can be retrieved by this recipe using the `remote_file` or `cookbook_file` resources. The recipe will choose the correct resource based on the existence (or non-existence) of the `node['sun']['rpm_url']` attribute. See below for an example role using this attribute in the proper way. If you would like to deliver the `rpm` package file as part of this cookbook place the `rpm` package file in the `files/default` directory and the cookbook will retrieve the file during installation.
-
----
-Usage
-=====
-
-Simply include the `java` recipe where ever you would like Java installed.
-
-To install Sun flavored Java on Debian or Ubuntu override the `node['java']['install_flavor']` attribute with in role:
-
- name "java"
- description "Install Sun Java on Ubuntu"
- override_attributes(
- "java" => {
- "install_flavor" => "sun"
- }
- )
- run_list(
- "recipe[java]"
- )
-
-On RedHat flavored Linux be sure to set the `rpm_url` and `rpm_checksum` attributes if you placed the `rpm` file on a remote server:
-
- name "java"
- description "Install Sun Java on CentOS"
- override_attributes(
- "java" => {
- "install_flavor" => "sun",
- "version" => "6u25",
- "rpm_url" => "https://mycompany.s3.amazonaws.com/sun_jdk",
- "rpm_checksum" => "c473e3026f991e617710bad98f926435959303fe084a5a31140ad5ad75d7bf13"
- }
- )
- run_list(
- "recipe[java]"
- )
-
-License and Author
-==================
-
-Author:: Seth Chisamore (<schisamo@opscode.com>)
-
-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.
-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.
@@ -1,43 +1,24 @@
+
+arch = kernel['machine'] =~ /x86_64/ ? "amd64" : "i386"
+default['java']['arch'] = arch
+
+default['java']['jvm_base_dir'] = '/usr/lib/jvm'
+
+default['java']['default_version'] = 'oraclejdk7'
+default['java']['alternate_versions'] = [] # to be overidden for JVM or Ruby VMs, e.g. with: %w(openjdk6 openjdk7 oraclejdk8)
+
+
+default['java']['openjdk6']['jvm_name'] = "java-1.6.0-openjdk-#{node['java']['arch']}"
+
+default['java']['openjdk7']['jvm_name'] = "java-1.7.0-openjdk-#{node['java']['arch']}"
+
+default['java']['oraclejdk7']['jvm_name'] = 'java-7-oracle'
+default['java']['oraclejdk7']['install_jce_unlimited'] = true
+
+default['java']['oraclejdk8']['jvm_name'] = 'java-8-oracle'
+
#
-# Author:: Seth Chisamore (<schisamo@opscode.com>)
-# Cookbook Name:: java
-# Attributes:: default
-#
-# Copyright 2010, Opscode, Inc.
-# Copyright 2011-2013, Travis CI Development Team <contact@travis-ci.org>.
-#
-# 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
+# Still have to set the default JAVA_HOME as 'java.java_home' attribute,
+# since other cookbooks externally refer to this value (e.g. travis_build_environment)
#
-# 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.
-
-case platform
-when "centos","redhat","fedora"
- default['java']['version'] = "6u25"
- default['java']['arch'] = kernel['machine'] =~ /x86_64/ ? "amd64" : "i586"
- set['java']['java_home'] = "/usr/lib/jvm/java"
-else
- arch = kernel['machine'] =~ /x86_64/ ? "amd64" : "i386"
- default['java']['arch'] = arch
- set['java']['java_home'] = "/usr/lib/jvm/java-7-openjdk-#{arch}/"
-end
-
-default[:java][:multi] = {
- :versions => ["openjdk6", "openjdk7", "oraclejdk7"]
-}
-
-default[:java][:oraclejdk7] = {
- :java_home => "/usr/lib/jvm/java-7-oracle",
- :install_jce_unlimited => true
-}
-
-default[:java][:oraclejdk8] = {
- :java_home => "/usr/lib/jvm/java-8-oracle"
-}
+default['java']['java_home'] = File.join(node['java']['jvm_base_dir'], node['java'][node['java']['default_version']]['jvm_name'])
@@ -1,14 +0,0 @@
-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
-
-oracle-java7-installer shared/accepted-oracle-license-v1-1 boolean true
-oracle-java8-installer shared/accepted-oracle-license-v1-1 boolean true
@@ -1,44 +0,0 @@
-name=java-7-oracle
-alias=java-7-oracle
-priority=1065
-section=main
-
-hl java /usr/lib/jvm/java-7-oracle/jre/bin/java
-hl keytool /usr/lib/jvm/java-7-oracle/jre/bin/keytool
-hl pack200 /usr/lib/jvm/java-7-oracle/jre/bin/pack200
-hl rmid /usr/lib/jvm/java-7-oracle/jre/bin/rmid
-hl rmiregistry /usr/lib/jvm/java-7-oracle/jre/bin/rmiregistry
-hl unpack200 /usr/lib/jvm/java-7-oracle/jre/bin/unpack200
-hl orbd /usr/lib/jvm/java-7-oracle/jre/bin/orbd
-hl servertool /usr/lib/jvm/java-7-oracle/jre/bin/servertool
-hl tnameserv /usr/lib/jvm/java-7-oracle/jre/bin/tnameserv
-hl jexec /usr/lib/jvm/java-7-oracle/jre/lib/jexec
-jre policytool /usr/lib/jvm/java-7-oracle/jre/bin/policytool
-jdk appletviewer /usr/lib/jvm/java-7-oracle/bin/appletviewer
-jdk apt /usr/lib/jvm/java-7-oracle/bin/apt
-jdk extcheck /usr/lib/jvm/java-7-oracle/bin/extcheck
-jdk idlj /usr/lib/jvm/java-7-oracle/bin/idlj
-jdk jar /usr/lib/jvm/java-7-oracle/bin/jar
-jdk jarsigner /usr/lib/jvm/java-7-oracle/bin/jarsigner
-jdk javac /usr/lib/jvm/java-7-oracle/bin/javac
-jdk javadoc /usr/lib/jvm/java-7-oracle/bin/javadoc
-jdk javah /usr/lib/jvm/java-7-oracle/bin/javah
-jdk javap /usr/lib/jvm/java-7-oracle/bin/javap
-jdk jconsole /usr/lib/jvm/java-7-oracle/bin/jconsole
-jdk jdb /usr/lib/jvm/java-7-oracle/bin/jdb
-jdk jhat /usr/lib/jvm/java-7-oracle/bin/jhat
-jdk jinfo /usr/lib/jvm/java-7-oracle/bin/jinfo
-jdk jmap /usr/lib/jvm/java-7-oracle/bin/jmap
-jdk jps /usr/lib/jvm/java-7-oracle/bin/jps
-jdk jrunscript /usr/lib/jvm/java-7-oracle/bin/jrunscript
-jdk jsadebugd /usr/lib/jvm/java-7-oracle/bin/jsadebugd
-jdk jstack /usr/lib/jvm/java-7-oracle/bin/jstack
-jdk jstat /usr/lib/jvm/java-7-oracle/bin/jstat
-jdk jstatd /usr/lib/jvm/java-7-oracle/bin/jstatd
-jdk native2ascii /usr/lib/jvm/java-7-oracle/bin/native2ascii
-jdk rmic /usr/lib/jvm/java-7-oracle/bin/rmic
-jdk schemagen /usr/lib/jvm/java-7-oracle/bin/schemagen
-jdk serialver /usr/lib/jvm/java-7-oracle/bin/serialver
-jdk wsgen /usr/lib/jvm/java-7-oracle/bin/wsgen
-jdk wsimport /usr/lib/jvm/java-7-oracle/bin/wsimport
-jdk xjc /usr/lib/jvm/java-7-oracle/bin/xjc
@@ -1,44 +0,0 @@
-name=java-8-oracle
-alias=java-8-oracle
-priority=1065
-section=main
-
-hl java /usr/lib/jvm/java-8-oracle/jre/bin/java
-hl keytool /usr/lib/jvm/java-8-oracle/jre/bin/keytool
-hl pack200 /usr/lib/jvm/java-8-oracle/jre/bin/pack200
-hl rmid /usr/lib/jvm/java-8-oracle/jre/bin/rmid
-hl rmiregistry /usr/lib/jvm/java-8-oracle/jre/bin/rmiregistry
-hl unpack200 /usr/lib/jvm/java-8-oracle/jre/bin/unpack200
-hl orbd /usr/lib/jvm/java-8-oracle/jre/bin/orbd
-hl servertool /usr/lib/jvm/java-8-oracle/jre/bin/servertool
-hl tnameserv /usr/lib/jvm/java-8-oracle/jre/bin/tnameserv
-hl jexec /usr/lib/jvm/java-8-oracle/jre/lib/jexec
-jre policytool /usr/lib/jvm/java-8-oracle/jre/bin/policytool
-jdk appletviewer /usr/lib/jvm/java-8-oracle/bin/appletviewer
-jdk apt /usr/lib/jvm/java-8-oracle/bin/apt
-jdk extcheck /usr/lib/jvm/java-8-oracle/bin/extcheck
-jdk idlj /usr/lib/jvm/java-8-oracle/bin/idlj
-jdk jar /usr/lib/jvm/java-8-oracle/bin/jar
-jdk jarsigner /usr/lib/jvm/java-8-oracle/bin/jarsigner
-jdk javac /usr/lib/jvm/java-8-oracle/bin/javac
-jdk javadoc /usr/lib/jvm/java-8-oracle/bin/javadoc
-jdk javah /usr/lib/jvm/java-8-oracle/bin/javah
-jdk javap /usr/lib/jvm/java-8-oracle/bin/javap
-jdk jconsole /usr/lib/jvm/java-8-oracle/bin/jconsole
-jdk jdb /usr/lib/jvm/java-8-oracle/bin/jdb
-jdk jhat /usr/lib/jvm/java-8-oracle/bin/jhat
-jdk jinfo /usr/lib/jvm/java-8-oracle/bin/jinfo
-jdk jmap /usr/lib/jvm/java-8-oracle/bin/jmap
-jdk jps /usr/lib/jvm/java-8-oracle/bin/jps
-jdk jrunscript /usr/lib/jvm/java-8-oracle/bin/jrunscript
-jdk jsadebugd /usr/lib/jvm/java-8-oracle/bin/jsadebugd
-jdk jstack /usr/lib/jvm/java-8-oracle/bin/jstack
-jdk jstat /usr/lib/jvm/java-8-oracle/bin/jstat
-jdk jstatd /usr/lib/jvm/java-8-oracle/bin/jstatd
-jdk native2ascii /usr/lib/jvm/java-8-oracle/bin/native2ascii
-jdk rmic /usr/lib/jvm/java-8-oracle/bin/rmic
-jdk schemagen /usr/lib/jvm/java-8-oracle/bin/schemagen
-jdk serialver /usr/lib/jvm/java-8-oracle/bin/serialver
-jdk wsgen /usr/lib/jvm/java-8-oracle/bin/wsgen
-jdk wsimport /usr/lib/jvm/java-8-oracle/bin/wsimport
-jdk xjc /usr/lib/jvm/java-8-oracle/bin/xjc
@@ -1,48 +0,0 @@
-#!/bin/sh
-#
-# Downloads and installs the startssl CA certs into the global java keystore
-# Author: Klaus Reimer <k@ailis.de>
-#
-
-# Check if JAVA_HOME is set
-if [ "$JAVA_HOME" = "" ]
-then
- JAVA_HOME="/usr/lib/jvm/java-7-oracle"
-fi
-
-# Check if cacerts file is present
-if [ ! -f $JAVA_HOME/jre/lib/security/cacerts ]
-then
- echo "ERROR: \$JAVA_HOME/jre/lib/security/cacerts not found. JAVA_HOME set correctly?"
- exit 1
-fi
-
-# Download the startssl certs
-echo "Downloading certs..."
-wget --continue http://www.startssl.com/certs/ca.crt
-wget --continue http://www.startssl.com/certs/sub.class1.server.ca.crt
-wget --continue http://www.startssl.com/certs/sub.class2.server.ca.crt
-wget --continue http://www.startssl.com/certs/sub.class3.server.ca.crt
-wget --continue http://www.startssl.com/certs/sub.class4.server.ca.crt
-
-# Install certs into global keystore
-echo "Adding certs to cacerts keystore (sudo password required)..."
-sudo keytool -import -trustcacerts -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit -noprompt -alias startcom.ca -file ca.crt
-sudo keytool -import -trustcacerts -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit -noprompt -alias startcom.ca.sub.class1 -file sub.class1.server.ca.crt
-sudo keytool -import -trustcacerts -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit -noprompt -alias startcom.ca.sub.class2 -file sub.class2.server.ca.crt
-sudo keytool -import -trustcacerts -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit -noprompt -alias startcom.ca.sub.class3 -file sub.class3.server.ca.crt
-sudo keytool -import -trustcacerts -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit -noprompt -alias startcom.ca.sub.class4 -file sub.class4.server.ca.crt
-
-# If jsse is installed then also put the certs into jssecacerts keystore
-if [ -f $JAVA_HOME/jre/lib/security/jssecacerts ]
-then
- echo "Adding certs to jssecacerts keystore (sudo password required)..."
- sudo keytool -import -trustcacerts -keystore $JAVA_HOME/jre/lib/security/jssecacerts -storepass changeit -noprompt -alias startcom.ca -file ca.crt
- sudo keytool -import -trustcacerts -keystore $JAVA_HOME/jre/lib/security/jssecacerts -storepass changeit -noprompt -alias startcom.ca.sub.class1 -file sub.class1.server.ca.crt
- sudo keytool -import -trustcacerts -keystore $JAVA_HOME/jre/lib/security/jssecacerts -storepass changeit -noprompt -alias startcom.ca.sub.class2 -file sub.class2.server.ca.crt
- sudo keytool -import -trustcacerts -keystore $JAVA_HOME/jre/lib/security/jssecacerts -storepass changeit -noprompt -alias startcom.ca.sub.class3 -file sub.class3.server.ca.crt
- sudo keytool -import -trustcacerts -keystore $JAVA_HOME/jre/lib/security/jssecacerts -storepass changeit -noprompt -alias startcom.ca.sub.class4 -file sub.class4.server.ca.crt
-fi
-
-# Remove downloaded certs
-rm -f ca.crt sub.class1.server.ca.crt sub.class2.server.ca.crt sub.class3.server.ca.crt sub.class4.server.ca.crt
@@ -1,19 +1,17 @@
name "java"
-maintainer "Opscode, Inc."
-maintainer_email "cookbooks@opscode.com"
+maintainer "Travis CI Team"
+maintainer_email "contact@travis-ci.org"
license "Apache 2.0"
-description "Installs Java runtime."
-long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
-version "1.1"
+description "Installs different Java Development Kits (JDK)"
+version "2.0.0"
-%w{ debian ubuntu centos redhat fedora }.each do |os|
- supports os
-end
+supports 'ubuntu', '>= 12.04'
%w{ apt timezone }.each do |cb|
depends cb
end
-recipe "java", "Installs Java runtime"
-recipe "java::openjdk", "Installs the OpenJDK flavor of Java"
-recipe "java::sun", "Installs the Sun flavor of Java"
+recipe "java::default", "Installs a default JDK"
+
+# 'multi' is part of 'default' recipe, and should no *more* be included directly.
+recipe "java::multi", "Installs a alternative JDK versions"
@@ -19,12 +19,45 @@
# limitations under the License.
#
-include_recipe "java::oraclejdk7"
+#
+# WARNING:
+# All recipes of this cookbook are (currently) specifically designed for Ubuntu
+# Please keep this in mind.
+#
+
+
+#
+# Install the default JDK
+#
+Chef::Log.info("Installing Java #{node['java']['default_version']}.")
+include_recipe "java::#{node['java']['default_version']}"
+default_jvm = node['java'][node['java']['default_version']]['jvm_name']
+
+#
+# Install more JDKs, if requested.
+#
+if not node['java']['alternate_versions'].to_a.empty?
+ # Note: 'multi' recipe is conditionally included to avoid the execution of
+ # openjdk6/tzdata workaround in single-jdk mode.
+ # This might change...
+ include_recipe "java::multi"
+end
+#
+# Ensure that default JDK is configured as default
+#
+execute "Set #{default_jvm} as default alternative" do
+ command "update-java-alternatives -s #{default_jvm}"
+end
template "/etc/profile.d/java_home.sh" do
owner "root"
group "root"
mode 0644
source "etc/profile.d/java_home.sh.erb"
+
+ # Could be changed to following, if node.java.java_home attribute is removed one day...
+ # variables({
+ # :java_home => File.join(node['java']['jvm_base_dir'], default_jvm)
+ # })
end
Oops, something went wrong.

0 comments on commit 2688193

Please sign in to comment.