diff --git a/CHANGELOG b/CHANGELOG index e3eddad..05ff1e0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +2013-06-18 Sharif Nassar - 0.4.0 +* Add support for Debian alternatives, and more than one JDK/JRE per platform. + 2013-04-04 Reid Vandewiele - 0.3.0 * Refactor, introduce params pattern diff --git a/Modulefile b/Modulefile index 08a2b0e..532893d 100644 --- a/Modulefile +++ b/Modulefile @@ -1,5 +1,5 @@ name 'puppetlabs-java' -version '0.3.0' +version '0.4.0' source 'git://github.com/puppetlabs/puppetlabs-java' author 'puppetlabs' license 'Apache' diff --git a/manifests/config.pp b/manifests/config.pp new file mode 100644 index 0000000..adb1fcb --- /dev/null +++ b/manifests/config.pp @@ -0,0 +1,17 @@ +# On Debian systems, if alternatives are set, manually assign them. +class java::config ( ) { + case $::osfamily { + Debian: { + if $java::use_java_alternative != undef and $java::use_java_alternative_path != undef { + exec { 'update-java-alternatives': + path => '/usr/bin:/usr/sbin:/bin:/sbin', + command => "update-java-alternatives --set ${java::use_java_alternative} --jre", + unless => "test /etc/alternatives/java -ef '${java::use_java_alternative_path}'", + } + } + } + default: { + # Do nothing. + } + } +} diff --git a/manifests/init.pp b/manifests/init.pp index cc8981b..6579f49 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -5,7 +5,10 @@ # Parameters: # # [*distribution*] -# The java distribution to install. Can be one of "jdk" or "jre". +# The java distribution to install. Can be one of "jdk" or "jre", +# or other platform-specific options where there are multiple +# implementations available (eg: OpenJDK vs Oracle JDK). +# # # [*version*] # The version of java to install. By default, this module simply ensures @@ -15,6 +18,19 @@ # The name of the java package. This is configurable in case a non-standard # java package is desired. # +# [*java_alternative*] +# The name of the java alternative to use on Debian systems. +# "update-java-alternatives -l" will show which choices are available. +# If you specify a particular package, you will almost always also +# want to specify which java_alternative to choose. If you set +# this, you also need to set the path below. +# +# [*java_alternative_path*] +# The path to the "java" command on Debian systems. Since the +# alternatives system makes it difficult to verify which +# alternative is actually enabled, this is required to ensure the +# correct JVM is enabled. +# # Actions: # # Requires: @@ -22,22 +38,22 @@ # Sample Usage: # class java( - $distribution = 'jdk', - $version = 'present', - $package = undef, + $distribution = 'jdk', + $version = 'present', + $package = undef, + $java_alternative = undef, + $java_alternative_path = undef ) { include java::params validate_re($version, 'present|installed|latest|^[._0-9a-zA-Z:-]+$') - case $distribution { - default: { fail('distribution must be one of jdk, jre') } - 'jdk': { - $default_package_name = $java::params::jdk_package - } - 'jre': { - $default_package_name = $java::params::jre_package - } + if has_key($java::params::java, $distribution) { + $default_package_name = $java::params::java[$distribution]['package'] + $default_alternative = $java::params::java[$distribution]['alternative'] + $default_alternative_path = $java::params::java[$distribution]['alternative_path'] + } else { + fail("Java distribution ${distribution} is not supported.") } $use_java_package_name = $package ? { @@ -45,9 +61,34 @@ class java( undef => $default_package_name, } + ## If $java_alternative is set, use that. + ## Elsif the DEFAULT package is being used, then use $default_alternative. + ## Else undef + $use_java_alternative = $java_alternative ? { + default => $java_alternative, + undef => $use_java_package_name ? { + $default_package_name => $default_alternative, + default => undef, + } + } + + ## Same logic as $java_alternative above. + $use_java_alternative_path = $java_alternative_path ? { + default => $java_alternative_path, + undef => $use_java_package_name ? { + $default_package_name => $default_alternative_path, + default => undef, + } + } + + anchor { 'java::begin:': } + -> package { 'java': ensure => $version, name => $use_java_package_name, } + -> + class { 'java::config': } + -> anchor { 'java::end': } } diff --git a/manifests/params.pp b/manifests/params.pp index 09981db..2610ad1 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,8 +1,15 @@ # Class: java::params # -# This class sets the value of two variables, jdk_package and jre_package, -# appropriate for the client system in question. +# This class builds a hash of JDK/JRE packages and (for Debian) +# alternatives. For wheezy/precise, we provide Oracle JDK/JRE +# options, even though those are not in the package repositories. # +# For more info on how to package Oracle JDK/JRE, see the Debian wiki: +# http://wiki.debian.org/JavaPackage +# +# Because the alternatives system makes it very difficult to tell +# which Java alternative is enabled, we hard code the path to bin/java +# for the config class to test if it is enabled. class java::params { case $::osfamily { @@ -11,7 +18,11 @@ class java::params { case $::operatingsystem { default: { fail("unsupported os ${::operatingsystem}") } 'RedHat', 'CentOS': { - if (versioncmp($::operatingsystemrelease, '6.3') < 0) { + if (versioncmp($::operatingsystemrelease, '5.0') < 0) { + $jdk_package = 'java-1.6.0-sun-devel' + $jre_package = 'java-1.6.0-sun' + } + elsif (versioncmp($::operatingsystemrelease, '6.3') < 0) { $jdk_package = 'java-1.6.0-openjdk-devel' $jre_package = 'java-1.6.0-openjdk' } @@ -25,28 +36,75 @@ class java::params { $jre_package = 'java' } } + $java = { + 'jdk' => { 'package' => $jdk_package, }, + 'jre' => { 'package' => $jre_package, }, + } } 'Debian': { case $::lsbdistcodename { default: { fail("unsupported release ${::lsbdistcodename}") } - 'squeeze', 'lucid': { - $jdk_package = 'openjdk-6-jdk' - $jre_package = 'openjdk-6-jre-headless' + 'lenny', 'squeeze', 'lucid': { + $java = { + 'jdk' => { + 'package' => 'openjdk-6-jdk', + 'alternative' => 'java-6-openjdk', + 'alternative_path' => '/usr/lib/jvm/java-6-openjdk/jre/bin/java', + }, + 'jre' => { + 'package' => 'openjdk-6-jre-headless', + 'alternative' => 'java-6-openjdk', + 'alternative_path' => '/usr/lib/jvm/java-6-openjdk/jre/bin/java', + }, + 'sun-jre' => { + 'package' => 'sun-java6-jre', + 'alternative' => 'java-6-sun', + 'alternative_path' => '/usr/lib/jvm/java-6-sun/jre/bin/java', + }, + 'sun-jdk' => { + 'package' => 'sun-java6-jdk', + 'alternative' => 'java-6-sun', + 'alternative_path' => '/usr/lib/jvm/java-6-sun/jre/bin/java', + }, + } } 'wheezy', 'precise','quantal','raring': { - $jdk_package = 'openjdk-7-jdk' - $jre_package = 'openjdk-7-jre-headless' + $java = { + 'jdk' => { + 'package' => 'openjdk-7-jdk', + 'alternative' => "java-1.7.0-openjdk-${::architecture}", + 'alternative_path' => "/usr/lib/jvm/java-1.7.0-openjdk-${::architecture}/bin/java", + }, + 'jre' => { + 'package' => 'openjdk-7-jre-headless', + 'alternative' => "java-1.7.0-openjdk-${::architecture}", + 'alternative_path' => "/usr/lib/jvm/java-1.7.0-openjdk-${::architecture}/bin/java", + }, + 'oracle-jre' => { + 'package' => 'oracle-j2re1.7', + 'alternative' => 'j2re1.7-oracle', + 'alternative_path' => '/usr/lib/jvm/j2re1.7-oracle/bin/java', + }, + 'oracle-jdk' => { + 'package' => 'oracle-j2sdk1.7', + 'alternative' => 'j2sdk1.7-oracle', + 'alternative_path' => '/usr/lib/jvm/j2sdk1.7-oracle/jre/bin/java', + }, + } } } } 'Solaris': { - $jdk_package = 'developer/java/jdk-7' - $jre_package = 'runtime/java/jre-7' + $java = { + 'jdk' => { 'package' => 'developer/java/jdk-7', }, + 'jre' => { 'package' => 'runtime/java/jre-7', }, + } } 'Suse': { - $jdk_package = 'java-1_6_0-ibm-devel' - $jre_package = 'java-1_6_0-ibm' + $java = { + 'jdk' => { 'package' => 'java-1_6_0-ibm-devel', }, + 'jre' => { 'package' => 'java-1_6_0-ibm', }, + } } } - } diff --git a/spec/classes/java_spec.rb b/spec/classes/java_spec.rb index 5e802c9..33d8f54 100644 --- a/spec/classes/java_spec.rb +++ b/spec/classes/java_spec.rb @@ -21,11 +21,46 @@ describe 'java', :type => :class do let(:facts) { {:osfamily => 'RedHat', :operatingsystem => 'Centos', :operatingsystemrelease => '5.3'} } let(:params) { { 'package' => 'jdk' } } it { should contain_package('java').with_name('jdk') } + it { should_not contain_exec('update-java-alternatives') } end - + context 'select default for Centos 5.3' do let(:facts) { {:osfamily => 'RedHat', :operatingsystem => 'Centos', :operatingsystemrelease => '5.3'} } it { should contain_package('java').with_name('java-1.6.0-openjdk-devel') } + it { should_not contain_exec('update-java-alternatives') } + end + + context 'select default for Debian Wheezy' do + let(:facts) { {:osfamily => 'Debian', :operatingsystem => 'Debian', :lsbdistcodename => 'wheezy', :operatingsystemrelease => '7.1', :architecture => 'amd64',} } + it { should contain_package('java').with_name('openjdk-7-jdk') } + it { should contain_exec('update-java-alternatives').with_command('update-java-alternatives --set java-1.7.0-openjdk-amd64 --jre') } + end + + context 'select Oracle JRE for Debian Wheezy' do + let(:facts) { {:osfamily => 'Debian', :operatingsystem => 'Debian', :lsbdistcodename => 'wheezy', :operatingsystemrelease => '7.1', } } + let(:params) { { 'distribution' => 'oracle-jre' } } + it { should contain_package('java').with_name('oracle-j2re1.7') } + it { should contain_exec('update-java-alternatives').with_command('update-java-alternatives --set j2re1.7-oracle --jre') } + end + + context 'select default for Debian Squeeze' do + let(:facts) { {:osfamily => 'Debian', :operatingsystem => 'Debian', :lsbdistcodename => 'squeeze', :operatingsystemrelease => '6.0.5'} } + it { should contain_package('java').with_name('openjdk-6-jdk') } + it { should contain_exec('update-java-alternatives').with_command('update-java-alternatives --set java-6-openjdk --jre') } + end + + context 'select Oracle JRE for Debian Squeeze' do + let(:facts) { {:osfamily => 'Debian', :operatingsystem => 'Debian', :lsbdistcodename => 'squeeze', :operatingsystemrelease => '6.0.5'} } + let(:params) { { 'distribution' => 'sun-jre', } } + it { should contain_package('java').with_name('sun-java6-jre') } + it { should contain_exec('update-java-alternatives').with_command('update-java-alternatives --set java-6-sun --jre') } + end + + context 'select random alternative for Debian Wheezy' do + let(:facts) { {:osfamily => 'Debian', :operatingsystem => 'Debian', :lsbdistcodename => 'wheezy', :operatingsystemrelease => '7.1'} } + let(:params) { { 'java_alternative' => 'bananafish' } } + it { should contain_package('java').with_name('openjdk-7-jdk') } + it { should contain_exec('update-java-alternatives').with_command('update-java-alternatives --set bananafish --jre') } end end