From db30eb9e2d4e439c1b5aebb4e5d43ced66db4b68 Mon Sep 17 00:00:00 2001 From: Michael Baker Date: Wed, 15 Nov 2017 22:36:10 +0800 Subject: [PATCH 1/5] Adding support for Ubuntu (#243) * Translate amd64 * Fix the path creation on exec --- manifests/oracle.pp | 22 +++++++++++++- spec/defines/oracle_spec.rb | 57 +++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/manifests/oracle.pp b/manifests/oracle.pp index e3aa912a..460e1abb 100644 --- a/manifests/oracle.pp +++ b/manifests/oracle.pp @@ -166,6 +166,11 @@ } else { $package_type = 'rpm' } + $creates_path = "/usr/java/${install_path}" + } + 'Debian' : { + $package_type = 'tar.gz' + $creates_path = "/usr/lib/jvm/${install_path}" } default : { fail ("unsupported platform ${$facts['os']['name']}") } @@ -173,7 +178,6 @@ $os = 'linux' $destination_dir = '/tmp/' - $creates_path = "/usr/java/${install_path}" } default : { fail ( "unsupported platform ${$facts['kernel']}" ) } @@ -183,6 +187,7 @@ case $facts['os']['architecture'] { 'i386' : { $arch = 'i586' } 'x86_64' : { $arch = 'x64' } + 'amd64' : { $arch = 'x64' } default : { fail ("unsupported platform ${$facts['os']['architecture']}") } @@ -205,6 +210,9 @@ 'rpm' : { $package_name = "${java_se}-${release_major}-${os}-${arch}.rpm" } + 'tar.gz' : { + $package_name = "${java_se}-${release_major}-${os}-${arch}.tar.gz" + } default : { $package_name = "${java_se}-${release_major}-${os}-${arch}.rpm" } @@ -235,6 +243,9 @@ 'rpm' : { $install_command = "rpm --force -iv ${destination}" } + 'tar.gz' : { + $install_command = "tar -zxf ${destination} -C /usr/lib/jvm" + } default : { $install_command = "rpm -iv ${destination}" } @@ -260,6 +271,15 @@ creates => $creates_path, require => Archive[$destination] } + case $facts['os']['family'] { + 'Debian' : { + file{'/usr/lib/jvm': + ensure => directory, + before => Exec["Install Oracle java_se ${java_se} ${version}"] + } + } + default : { } + } } default : { fail ("unsupported platform ${$facts['kernel']}") diff --git a/spec/defines/oracle_spec.rb b/spec/defines/oracle_spec.rb index 9e05ee77..d7cd817e 100644 --- a/spec/defines/oracle_spec.rb +++ b/spec/defines/oracle_spec.rb @@ -130,6 +130,63 @@ end end + context 'On Ubuntu 64-bit' do + let(:facts) { {:kernel => 'Linux', :os => { :family => 'Debian', :architecture => 'amd64', :name => 'Ubuntu', :release => { :full => '16.04' } } } } + + context 'Oracle Java SE 6 JDK' do + let(:params) { {:ensure => 'present', :version => '6', :java_se => 'jdk'} } + let :title do 'jdk6' end + it { is_expected.to contain_archive('/tmp/jdk-6u45-linux-x64.tar.gz')} + it { is_expected.to contain_exec('Install Oracle java_se jdk 6').with_command('tar -zxf /tmp/jdk-6u45-linux-x64.tar.gz -C /usr/lib/jvm') } + it { is_expected.to contain_exec('Install Oracle java_se jdk 6').that_requires('Archive[/tmp/jdk-6u45-linux-x64.tar.gz]') } + end + + context 'Oracle Java SE 7 JDK' do + let(:params) { {:ensure => 'present', :version => '7', :java_se => 'jdk'} } + let :title do 'jdk7' end + it { is_expected.to contain_archive('/tmp/jdk-7u80-linux-x64.tar.gz')} + it { is_expected.to contain_exec('Install Oracle java_se jdk 7').with_command('tar -zxf /tmp/jdk-7u80-linux-x64.tar.gz -C /usr/lib/jvm') } + it { is_expected.to contain_exec('Install Oracle java_se jdk 7').that_requires('Archive[/tmp/jdk-7u80-linux-x64.tar.gz]') } + end + + context 'Oracle Java SE 8 JDK' do + let(:params) { {:ensure => 'present', :version => '8', :java_se => 'jdk'} } + let :title do 'jdk8' end + it { is_expected.to contain_archive('/tmp/jdk-8u131-linux-x64.tar.gz')} + it { is_expected.to contain_exec('Install Oracle java_se jdk 8').with_command('tar -zxf /tmp/jdk-8u131-linux-x64.tar.gz -C /usr/lib/jvm') } + it { is_expected.to contain_exec('Install Oracle java_se jdk 8').that_requires('Archive[/tmp/jdk-8u131-linux-x64.tar.gz]') } + end + + context 'Oracle Java SE 6 JRE' do + let(:params) { {:ensure => 'present', :version => '6', :java_se => 'jre'} } + let :title do 'jre6' end + it { is_expected.to contain_archive('/tmp/jre-6u45-linux-x64.tar.gz')} + it { is_expected.to contain_exec('Install Oracle java_se jre 6').with_command('tar -zxf /tmp/jre-6u45-linux-x64.tar.gz -C /usr/lib/jvm') } + it { is_expected.to contain_exec('Install Oracle java_se jre 6').that_requires('Archive[/tmp/jre-6u45-linux-x64.tar.gz]') } + end + + context 'Oracle Java SE 7 JRE' do + let(:params) { {:ensure => 'present', :version => '7', :java_se => 'jre'} } + let :title do 'jre7' end + it { is_expected.to contain_archive('/tmp/jre-7u80-linux-x64.tar.gz')} + it { is_expected.to contain_exec('Install Oracle java_se jre 7').with_command('tar -zxf /tmp/jre-7u80-linux-x64.tar.gz -C /usr/lib/jvm') } + it { is_expected.to contain_exec('Install Oracle java_se jre 7').that_requires('Archive[/tmp/jre-7u80-linux-x64.tar.gz]') } + end + + context 'select Oracle Java SE 8 JRE' do + let(:params) { {:ensure => 'present', :version => '8', :java_se => 'jre'} } + let :title do 'jre8' end + it { is_expected.to contain_archive('/tmp/jre-8u131-linux-x64.tar.gz')} + it { is_expected.to contain_exec('Install Oracle java_se jre 8').with_command('tar -zxf /tmp/jre-8u131-linux-x64.tar.gz -C /usr/lib/jvm') } + it { is_expected.to contain_exec('Install Oracle java_se jre 8').that_requires('Archive[/tmp/jre-8u131-linux-x64.tar.gz]') } + end + + context 'Pass URL to url parameter' do + let(:params) { {:ensure => 'present', :version_major => '8u131', :version_minor => 'b11', :java_se => 'jdk', :url => 'http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz'} } + let :title do 'jdk8' end + it { is_expected.to contain_archive('/tmp/jdk-8u131-linux-x64.tar.gz')} + end + end describe 'incompatible OSes' do [ { From bdfc567c1872f621acebf94057016c8fb49b8e59 Mon Sep 17 00:00:00 2001 From: Sebastian Reitenbach Date: Mon, 25 Sep 2017 12:05:00 +0200 Subject: [PATCH 2/5] OpenBSD doesn't have /etc/environment, therefore there is no need to fiddle with it. The default case statement, "do nothing" is all fine here. Facter::Util::Resolution.with_env is long time gone since Facter > 2.x. That was even longer before introduced by me. Remove that OpenBSD special case in the java_version fact, and assume that $PATH is properly set in order to find the 'java' binary. Additionally confine the java_default_home and java_libjvm_path to OpenBSD kernel as well. Add some flesh to the java_default_home fact to allow it to find the java binary. --- lib/facter/java_default_home.rb | 15 +++++++++++---- lib/facter/java_libjvm_path.rb | 2 +- lib/facter/java_version.rb | 16 +--------------- manifests/config.pp | 2 +- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/lib/facter/java_default_home.rb b/lib/facter/java_default_home.rb index 330f037e..04ae9234 100644 --- a/lib/facter/java_default_home.rb +++ b/lib/facter/java_default_home.rb @@ -11,13 +11,20 @@ # Notes: # None Facter.add(:java_default_home) do - confine :kernel => 'Linux' + confine :kernel => [ 'Linux', 'OpenBSD' ] setcode do if Facter::Util::Resolution.which('readlink') - java_bin = Facter::Util::Resolution.exec('readlink -e /usr/bin/java').strip + java_bin = Facter::Util::Resolution.exec('readlink -e /usr/bin/java').to_s.strip if java_bin.empty? - nil - elsif java_bin =~ %r(/jre/) + java_bin = Facter::Util::Resolution.exec('readlink -e /usr/local/bin/java').to_s.strip + if java_bin.empty? + java_bin = Facter::Util::Resolution.which('java').to_s.strip + if java_bin.empty? + nil + end + end + end + if java_bin =~ %r(/jre/) java_default_home = File.dirname(File.dirname(File.dirname(java_bin))) else java_default_home = File.dirname(File.dirname(java_bin)) diff --git a/lib/facter/java_libjvm_path.rb b/lib/facter/java_libjvm_path.rb index 14fd78ca..792d494c 100644 --- a/lib/facter/java_libjvm_path.rb +++ b/lib/facter/java_libjvm_path.rb @@ -11,7 +11,7 @@ # Notes: # None Facter.add(:java_libjvm_path) do - confine :kernel => "Linux" + confine :kernel => [ "Linux", "OpenBSD" ] setcode do java_default_home = Facter.value(:java_default_home) java_libjvm_file = Dir.glob("#{java_default_home}/jre/lib/**/libjvm.so") diff --git a/lib/facter/java_version.rb b/lib/facter/java_version.rb index e7040e5f..4392bfe0 100644 --- a/lib/facter/java_version.rb +++ b/lib/facter/java_version.rb @@ -21,21 +21,7 @@ # Additionally, facter versions prior to 2.0.1 only support # positive matches, so this needs to be done manually in setcode. setcode do - unless [ 'openbsd', 'darwin' ].include? Facter.value(:operatingsystem).downcase - version = nil - if Facter::Util::Resolution.which('java') - Facter::Util::Resolution.exec('java -Xmx12m -version 2>&1').lines.each { |line| version = $~[1] if /^.+ version \"(.+)\"$/ =~ line } - end - version - end - end -end - -Facter.add(:java_version) do - confine :operatingsystem => 'OpenBSD' - has_weight 100 - setcode do - Facter::Util::Resolution.with_env("PATH" => '/usr/local/jdk-1.7.0/jre/bin:/usr/local/jre-1.7.0/bin') do + unless [ 'darwin' ].include? Facter.value(:operatingsystem).downcase version = nil if Facter::Util::Resolution.which('java') Facter::Util::Resolution.exec('java -Xmx12m -version 2>&1').lines.each { |line| version = $~[1] if /^.+ version \"(.+)\"$/ =~ line } diff --git a/manifests/config.pp b/manifests/config.pp index 5c7f3fd8..6237a8b7 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -44,7 +44,7 @@ } } } - 'OpenBSD', 'FreeBSD', 'Suse': { + 'FreeBSD', 'Suse': { if $java::use_java_home != undef { file_line { 'java-home-environment': path => '/etc/environment', From e50eb646143f674ac97adcdf88ed38214b9d114f Mon Sep 17 00:00:00 2001 From: Sebastian Reitenbach Date: Tue, 26 Sep 2017 23:35:15 +0200 Subject: [PATCH 3/5] do not use unportable readlink utility to find the java_default_home, use Ruby in a more portable fashion. adapt tests as well --- lib/facter/java_default_home.rb | 21 ++++----- spec/classes/java_spec.rb | 2 +- spec/unit/facter/java_default_home_spec.rb | 54 ++++++++++------------ spec/unit/facter/java_version_spec.rb | 4 +- 4 files changed, 36 insertions(+), 45 deletions(-) diff --git a/lib/facter/java_default_home.rb b/lib/facter/java_default_home.rb index 04ae9234..cc47a4de 100644 --- a/lib/facter/java_default_home.rb +++ b/lib/facter/java_default_home.rb @@ -3,27 +3,22 @@ # Purpose: get absolute path of java system home # # Resolution: -# Uses `readlink` to resolve the path of `/usr/bin/java` then returns subsubdir +# Find the real java binary, and return the subsubdir # # Caveats: -# Requires readlink +# java binary has to be found in $PATH # # Notes: # None Facter.add(:java_default_home) do confine :kernel => [ 'Linux', 'OpenBSD' ] setcode do - if Facter::Util::Resolution.which('readlink') - java_bin = Facter::Util::Resolution.exec('readlink -e /usr/bin/java').to_s.strip - if java_bin.empty? - java_bin = Facter::Util::Resolution.exec('readlink -e /usr/local/bin/java').to_s.strip - if java_bin.empty? - java_bin = Facter::Util::Resolution.which('java').to_s.strip - if java_bin.empty? - nil - end - end - end + java_bin = Facter::Util::Resolution.which('java').to_s.strip + if java_bin.empty? + nil + else + # We might have found a symlink instead of the real binary + java_bin = File.realpath(java_bin) if java_bin =~ %r(/jre/) java_default_home = File.dirname(File.dirname(File.dirname(java_bin))) else diff --git a/spec/classes/java_spec.rb b/spec/classes/java_spec.rb index 00a4e3f2..47bfbd0a 100644 --- a/spec/classes/java_spec.rb +++ b/spec/classes/java_spec.rb @@ -236,7 +236,7 @@ context 'select jdk for OpenBSD' do let(:facts) { {:osfamily => 'OpenBSD', :architecture => 'x86_64'} } it { is_expected.to contain_package('java').with_name('jdk') } - it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/local/jdk/') } + it { is_expected.to_not contain_file_line('java-home-environment') } end context 'select jre for OpenBSD' do diff --git a/spec/unit/facter/java_default_home_spec.rb b/spec/unit/facter/java_default_home_spec.rb index 41be89e4..a5fce079 100644 --- a/spec/unit/facter/java_default_home_spec.rb +++ b/spec/unit/facter/java_default_home_spec.rb @@ -1,47 +1,43 @@ require "spec_helper" describe Facter::Util::Fact do - before { - Facter.clear - Facter.fact(:kernel).stubs(:value).returns('Linux') - } describe "java_default_home" do - context 'returns java home path when readlink present' do - context 'when java is in HOME/jre/bin/java' do + before(:each) { + Facter.clear + Facter.fact(:kernel).stubs(:value).returns('Linux') + } + + context 'returns java home path when java found in PATH' do + context "when java is in /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java" do + it do - java_path_output = <<-EOS -/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java - EOS - Facter::Util::Resolution.expects(:which).with("readlink").returns(true) - Facter::Util::Resolution.expects(:exec).with("readlink -e /usr/bin/java").returns(java_path_output) - expect(Facter.value(:java_default_home)).to eql "/usr/lib/jvm/java-7-openjdk-amd64" + File.delete('./java') if File.exist?('./java') + File.symlink('/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java', './java') + Facter::Util::Resolution.expects(:which).with("java").returns("./java") + expect(File.readlink('./java')).to eq('/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java') + expect(Facter.value(:java_default_home)).to eql '/usr/lib/jvm/java-7-openjdk-amd64' + File.delete('./java') if File.exist?('./java') end end - context 'when java is in HOME/bin/java' do + + context "when java is in /usr/lib/jvm/oracle-java8-jre-amd64/bin/java" do + it do - java_path_output = <<-EOS -/usr/lib/jvm/oracle-java8-jre-amd64/bin/java - EOS - Facter::Util::Resolution.expects(:which).with("readlink").returns(true) - Facter::Util::Resolution.expects(:exec).with("readlink -e /usr/bin/java").returns(java_path_output) - expect(Facter.value(:java_default_home)).to eql "/usr/lib/jvm/oracle-java8-jre-amd64" + File.delete('./java') if File.exist?('./java') + File.symlink('/usr/lib/jvm/oracle-java8-jre-amd64/bin/java', './java') + Facter::Util::Resolution.expects(:which).with("java").returns("./java") + expect(File.readlink('./java')).to eq('/usr/lib/jvm/oracle-java8-jre-amd64/bin/java') + expect(Facter.value(:java_default_home)).to eql '/usr/lib/jvm/oracle-java8-jre-amd64' + File.delete('./java') if File.exist?('./java') end end end - context 'returns nil when readlink is present but java is not' do - it do - java_path_output = "" - Facter::Util::Resolution.expects(:which).with("readlink").returns(true) - Facter::Util::Resolution.expects(:exec).with("readlink -e /usr/bin/java").returns(java_path_output) - expect(Facter.value(:java_default_home)).to be_nil - end - end - context 'returns nil when readlink not present' do + context 'returns nil when java not present' do it do Facter::Util::Resolution.stubs(:exec) - Facter::Util::Resolution.expects(:which).with("readlink").at_least(1).returns(false) + Facter::Util::Resolution.expects(:which).with("java").at_least(1).returns(false) expect(Facter.value(:java_default_home)).to be_nil end end diff --git a/spec/unit/facter/java_version_spec.rb b/spec/unit/facter/java_version_spec.rb index 02af6560..961bd2df 100644 --- a/spec/unit/facter/java_version_spec.rb +++ b/spec/unit/facter/java_version_spec.rb @@ -7,7 +7,7 @@ describe "java_version" do context 'returns java version when java present' do - context 'on OpenBSD', :with_env => true do + context 'on OpenBSD' do before do Facter.fact(:operatingsystem).stubs(:value).returns("OpenBSD") end @@ -61,7 +61,7 @@ end context 'returns nil when java not present' do - context 'on OpenBSD', :with_env => true do + context 'on OpenBSD' do before do Facter.fact(:operatingsystem).stubs(:value).returns("OpenBSD") end From e1df6498c799e1fef77a0cf0850028eb7269527a Mon Sep 17 00:00:00 2001 From: Will Meek Date: Wed, 15 Nov 2017 12:14:26 +0000 Subject: [PATCH 4/5] Fix facter unit test when using realpath --- lib/facter/java_default_home.rb | 9 +++---- spec/unit/facter/java_default_home_spec.rb | 31 +++++++++++++--------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/lib/facter/java_default_home.rb b/lib/facter/java_default_home.rb index cc47a4de..c6b653d9 100644 --- a/lib/facter/java_default_home.rb +++ b/lib/facter/java_default_home.rb @@ -17,12 +17,11 @@ if java_bin.empty? nil else - # We might have found a symlink instead of the real binary - java_bin = File.realpath(java_bin) - if java_bin =~ %r(/jre/) - java_default_home = File.dirname(File.dirname(File.dirname(java_bin))) + java_path = File.realpath(java_bin) + if java_path =~ %r(/jre/) + java_default_home = File.dirname(File.dirname(File.dirname(java_path))) else - java_default_home = File.dirname(File.dirname(java_bin)) + java_default_home = File.dirname(File.dirname(java_path)) end end end diff --git a/spec/unit/facter/java_default_home_spec.rb b/spec/unit/facter/java_default_home_spec.rb index a5fce079..a111fef9 100644 --- a/spec/unit/facter/java_default_home_spec.rb +++ b/spec/unit/facter/java_default_home_spec.rb @@ -1,5 +1,14 @@ require "spec_helper" +def unlink_and_delete(filename) + if File.symlink?(filename) + File.unlink(filename) + end + if File.exist?(filename) + File.delete(filename) + end +end + describe Facter::Util::Fact do describe "java_default_home" do @@ -10,26 +19,24 @@ context 'returns java home path when java found in PATH' do context "when java is in /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java" do - it do - File.delete('./java') if File.exist?('./java') - File.symlink('/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java', './java') - Facter::Util::Resolution.expects(:which).with("java").returns("./java") - expect(File.readlink('./java')).to eq('/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java') + unlink_and_delete('./java_test') + File.symlink('/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java', './java_test') + Facter::Util::Resolution.expects(:which).with("java").returns("./java_test") + File.expects(:realpath).with('./java_test').returns('/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java') expect(Facter.value(:java_default_home)).to eql '/usr/lib/jvm/java-7-openjdk-amd64' - File.delete('./java') if File.exist?('./java') + unlink_and_delete('./java_test') end end context "when java is in /usr/lib/jvm/oracle-java8-jre-amd64/bin/java" do - it do - File.delete('./java') if File.exist?('./java') - File.symlink('/usr/lib/jvm/oracle-java8-jre-amd64/bin/java', './java') - Facter::Util::Resolution.expects(:which).with("java").returns("./java") - expect(File.readlink('./java')).to eq('/usr/lib/jvm/oracle-java8-jre-amd64/bin/java') + unlink_and_delete('./java_test') + File.symlink('/usr/lib/jvm/oracle-java8-jre-amd64/bin/java', './java_test') + Facter::Util::Resolution.expects(:which).with("java").returns("./java_test") + File.expects(:realpath).with('./java_test').returns('/usr/lib/jvm/oracle-java8-jre-amd64/bin/java') expect(Facter.value(:java_default_home)).to eql '/usr/lib/jvm/oracle-java8-jre-amd64' - File.delete('./java') if File.exist?('./java') + unlink_and_delete('./java_test') end end end From d0c9b41d9de36d39505a54c6570aad85744dbf3e Mon Sep 17 00:00:00 2001 From: Will Meek Date: Thu, 16 Nov 2017 13:59:42 +0000 Subject: [PATCH 5/5] Release prep for 2.2.0 --- CHANGELOG.md | 14 ++++++++++++++ metadata.json | 5 +++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54e9cfc9..fc9f60e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +## Supported Release [2.2.0] +### Summary +This release is a maintenance release that includes a roll up of minor changes. + +#### Added +- Addition of Ubuntu for Oracle Java. +- Addition of Debian 9 in supported versions. +- Addition of OpenBSD case and use `realpath` rather than `readlink` in Java Default Home Facter fact. + +#### Removed +- Removal of OpenBSD as a special case and deprecated `with_env` in Java Version Facter Facter fact. + ## Supported Release 2.1.1 ### Summary This release is a maintenance release that includes a roll up of minor changes. @@ -256,3 +268,5 @@ Jeff McCune ## 2011-05-24 - Version 0.0.1 Jeff McCune * Initial release + +[2.2.0]:https://github.com/puppetlabs/puppetlabs-java/compare/2.1.1...2.2.0 \ No newline at end of file diff --git a/metadata.json b/metadata.json index 838bf5bc..fddf306c 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "puppetlabs-java", - "version": "2.1.1", + "version": "2.2.0", "author": "puppetlabs", "summary": "Installs the correct Java package on various platforms.", "license": "Apache-2.0", @@ -50,7 +50,8 @@ "operatingsystem": "Debian", "operatingsystemrelease": [ "7", - "8" + "8", + "9" ] }, {