diff --git a/.fixtures.yml b/.fixtures.yml index 4bcd6d8..8010459 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -2,7 +2,7 @@ fixtures: repositories: windows_env: "git://github.com/badgerious/puppet-windows-env.git" powershell: "git://github.com/puppetlabs/puppetlabs-powershell.git" - pget: "git://github.com/cyberious/puppet-pget.git" + download_file: "git@github.com:voxpupuli/puppet-download_file.git" stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git" module_data: "git://github.com/ripienaar/puppet-module-data.git" symlinks: diff --git a/.gitignore b/.gitignore index 3881739..afc55c7 100644 --- a/.gitignore +++ b/.gitignore @@ -223,3 +223,5 @@ pip-log.txt #Mr Developer .mr.developer.cfg + +*.lock diff --git a/README.markdown b/README.markdown index 0a5716a..9784299 100644 --- a/README.markdown +++ b/README.markdown @@ -30,25 +30,27 @@ This module can be used to install one or multiple JDK versions from Oracle ### Beginning with windows_java -####Install Oracle JDK Version 8u45 +####Install Oracle JDK Version 8u45 by default ~~~puppet - include 'windows_java' + include '::windows_java' ~~~ - This will install Oracle JDK version 8 update 45 + This will install Oracle JDK version 8 update 45 by default ## Usage ####Install JDK 7u51 and not as default ~~~puppet -windows_java::jdk{'7u51': +class { '::windows_java': + version => '7u51', default => false, } ~~~ ####Install JDK 7u51 non default location ~~~puppet -windows_java::jdk{'7u51': +class { '::windows_java': + version => '7u51', install_path => 'G:\java\jdk7u51', default => false, } @@ -60,15 +62,6 @@ windows_java::jdk{'7u51': #### `windows_java` -* `ensure`: *Optional.* Whether to install or remove the version -* `version`: *Optional.* What version of the jdk to install. Defaults to '8u45' -* `arch`: *Optional.* What architecture you want to install, Valid options are 'x64','i586'. Default is: `$::architecture` -* `default`: *Optional.* Whether to update and set the JAVA_HOME and include in PATH environment variables - -### Types - -#### `windows_java::jdk` - * `ensure`: *Optional.* Whether to install or remove the version * `version`: *Optional.* What version of the jdk to install. Defaults to '8u45' * `arch`: *Optional.* What architecture you want to install, Valid options are 'x64','i586'. Default is: `$::architecture` @@ -79,4 +72,3 @@ windows_java::jdk{'7u51': * `install_path`: *Optional.* The location to install JDK to. * `source`: *Optional.* Alternate source to download from, can be puppet:// http(s):// url * `temp_target`: *Optional.* Temp target for downloading the JDK installer to, defaults to ENV['TEMP'] - diff --git a/manifests/download.pp b/manifests/download.pp deleted file mode 100644 index 3991917..0000000 --- a/manifests/download.pp +++ /dev/null @@ -1,26 +0,0 @@ -define windows_java::download ( - $filename, - $source, - $temp_target, - $cookie_string = $::windows_java::params::cookie_string, -){ - assert_private() - Exec{ - tries => 3, - try_sleep => 30, - timeout => 500, - } - $agent = 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko' - $header_hash = { - 'user-agent' => $agent, - 'Cookie' => $cookie_string - } - debug("Downloading from source ${source} to ${temp_target}") - info("Downloading file ${filename}") - pget{ $name: - source => $source, - target => $temp_target, - targetfilename => $filename, - headerHash => $header_hash, - } -} \ No newline at end of file diff --git a/manifests/init.pp b/manifests/init.pp index 3262071..eae4310 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -29,15 +29,27 @@ # Copyright 2013 Your name here, unless otherwise noted. # class windows_java ( - $ensure = 'present', - $version = '8u45', - $arch = $::architecture, - $default = true, + $ensure = 'present', + $version = '8u45', + $arch = $::architecture, + $build_number_hash = undef, + $cookie_string = undef, + $default = true, + $install_name = undef, + $install_path = undef, + $source = undef, + $temp_target = $::windows_java_temp, ) { - windows_java::jdk{ $name: - ensure => $ensure, - version => $version, - default => $default, - arch => $arch, + windows_java::jdk{ $version: + ensure => $ensure, + version => $version, + arch => $arch, + build_number_hash => $build_number_hash, + cookie_string => $cookie_string, + default => $default, + install_name => $install_name, + install_path => $install_path, + source => $source, + temp_target => $::windows_java_temp, } } diff --git a/manifests/install.pp b/manifests/install.pp index f096e4e..03c2b04 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -1,7 +1,7 @@ define windows_java::install ( $install_path, $source, - $ensure = 'present', + $ensure = 'present', $package_name = $name, ){ $_options = ['/s',{ 'INSTALLDIR' => $install_path }] @@ -9,6 +9,6 @@ ensure => $ensure, provider => windows, source => $source, - install_options => $_options + install_options => $_options, } -} \ No newline at end of file +} diff --git a/manifests/jdk.pp b/manifests/jdk.pp index 6b76eb0..5e7e8a6 100644 --- a/manifests/jdk.pp +++ b/manifests/jdk.pp @@ -43,7 +43,7 @@ # # Copyright 2013 Your name here, unless otherwise noted. # -define windows_java::jdk ( +define windows_java::jdk ( $ensure = 'present', $version = $name, $arch = $::architecture, @@ -53,8 +53,11 @@ $install_name = undef, $install_path = undef, $source = undef, - $temp_target = $::windows_java_temp,) { - include windows_java::params + $temp_target = $::windows_java_temp, +) { + + validate_legacy(Boolean, 'validate_bool', $default) + include ::windows_java::params $_splitversion = split($version,'[uU]') $_major = $_splitversion[0] @@ -73,18 +76,18 @@ } if $install_name == undef { - $_installBase = "${::windows_java::params::jdk_base_install_name} ${_major}" - $_installUpdate = $_update ?{ + $_install_base = "${::windows_java::params::jdk_base_install_name} ${_major}" + $_install_update = $_update ?{ /\d+/ => " Update ${_update}", default => '', } - $_installArch = $_arch_version ? { + $_install_arch = $_arch_version ? { 'x64' => ' (64-bit)', default => '', } - $_installName = "${_installBase}${_installUpdate}${_installArch}" + $_install_name = "${_install_base}${_install_update}${_install_arch}" } else { - $_installName = $install_name + $_install_name = $install_name } if has_key($_build_hash, $version) { @@ -105,40 +108,39 @@ $_remote_source = $source $_filename = filename($_remote_source) } - ## - # Install Paths - # - ## + if $::architecture == 'x86_64' and $_arch_version == 'i586'{ $_base_install_path = 'C:\Program Files (x86)\Java' } else{ $_base_install_path = 'C:\Program Files\Java' } - $_installPath = $install_path ? { + $_install_path = $install_path ? { undef => "${_base_install_path}\\jdk1.${_major}.0_${_update}", default => $install_path, } - $_tempLocation = "${temp_target}\\${_filename}" + $_temp_location = "${temp_target}\\${_filename}" - windows_java::download { "Download-${_filename}": - source => $_remote_source, - filename => $_filename, - temp_target => $temp_target, - }-> - windows_java::install{ $_installName: + download_file { "download-${_filename}": + url => $_remote_source, + destination_directory => $temp_target, + destination_file => $_filename, + cookies => [$::windows_java::params::cookie_string], + } + -> windows_java::install{ $_install_name: ensure => $ensure, - source => $_tempLocation, - install_path => $_installPath, + source => $_temp_location, + install_path => $_install_path, } - validate_bool($default) + if($default == true){ - class{ 'windows_java::java_home': - install_path => $_installPath, - require => Windows_java::Install[$_installName] } + class{ '::windows_java::java_home': + install_path => $_install_path, + require => Windows_java::Install[$_install_name], + } } } else{ - package{ $_installName: + package{ $_install_name: ensure => $ensure, provider => windows, } diff --git a/manifests/params.pp b/manifests/params.pp index 759b1bb..8f1c4e3 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,9 +1,8 @@ class windows_java::params { $jdk_base_install_name = 'Java SE Development Kit' - $cookie_string = 'oraclelicense=accept-securebackup-cookie;gpw_e24=http://edelivery.oracle.com' - $root_url = 'http://download.oracle.com/otn-pub/java/jdk' - - $build_numbers_hash = { + $cookie_string = 'oraclelicense=accept-securebackup-cookie;gpw_e24=http://edelivery.oracle.com' + $root_url = 'http://download.oracle.com/otn-pub/java/jdk' + $build_numbers_hash = { '8u45' => 'b15', '8u40' => 'b26', '8u31' => 'b13', @@ -22,4 +21,4 @@ '7u45' => 'b18', '7u25' => 'b17', } -} \ No newline at end of file +} diff --git a/metadata.json b/metadata.json index 693518f..6b47a16 100644 --- a/metadata.json +++ b/metadata.json @@ -36,12 +36,12 @@ ], "dependencies": [ { - "name": "badgerious/windows_env", - "version_requirement": ">= 2.0.2" + "name": "puppet/windows_env", + "version_requirement": ">= 2.3.0" }, { - "name": "cyberious/pget", - "version_requirement": ">= 1.0.0 < 2.0.0" + "name": "puppet/download_file", + "version_requirement": ">= 2.0.0 < 4.0.0" }, { "name": "puppetlabs/stdlib", diff --git a/spec/classes/windows_java_spec.rb b/spec/classes/windows_java_spec.rb index 6616185..440c430 100644 --- a/spec/classes/windows_java_spec.rb +++ b/spec/classes/windows_java_spec.rb @@ -1,26 +1,42 @@ require 'spec_helper' require 'rspec-puppet' +provider_class = Puppet::Type.type(:package).provider(:windows) + describe 'windows_java' do + before :each do + Puppet::Type.type(:package).stubs(:defaultprovider).returns(provider_class) + end let(:title) { 'install jdk' } let(:facts) { {:operatingsystem => 'windows', :architecture => 'x64', :windows_java_temp => 'C:\temp'} } - let(:params) { {:version => '8u45'} } - it { - should contain_windows_java__download('Download-jdk-8u45-windows-x64.exe').with( - { - 'source' => 'http://download.oracle.com/otn-pub/java/jdk/8u45-b15/jdk-8u45-windows-x64.exe', - 'filename' => 'jdk-8u45-windows-x64.exe', - 'temp_target' => 'C:\temp' - }) + let(:params) { + { + 'ensure' => 'present', + 'version' => '8u45', + 'build_number_hash' => { '8u45' => 'b15' }, + 'default' => true, + 'source' => 'http://download.oracle.com/otn-pub/java/jdk/8u45-b15/jdk-8u45-windows-x64.exe' + } } it { - should contain_package( - 'Java SE Development Kit 8 Update 45 (64-bit)').with( - { - 'ensure' => 'present' - }) + is_expected.to contain_windows_java__jdk('8u45').with( + { + 'ensure' => 'present', + 'version' => '8u45', + 'arch' => 'x64', + 'build_number_hash' => { '8u45' => 'b15' }, + 'default' => true, + 'source' => 'http://download.oracle.com/otn-pub/java/jdk/8u45-b15/jdk-8u45-windows-x64.exe', + 'temp_target' => 'C:\temp' + } + ) } it { - should contain_windows_env('JAVA_HOME').with_value('C:\Program Files\Java\jdk1.8.0_45') + is_expected.to contain_package('Java SE Development Kit 8 Update 45 (64-bit)').with( + { + 'ensure' => 'present' + } + ) } -end \ No newline at end of file + it { should contain_windows_env('JAVA_HOME').with_value('C:\Program Files\Java\jdk1.8.0_45') } +end diff --git a/spec/defines/jdk_spec.rb b/spec/defines/jdk_spec.rb index 1a3a44d..bce8df1 100644 --- a/spec/defines/jdk_spec.rb +++ b/spec/defines/jdk_spec.rb @@ -1,56 +1,70 @@ require 'spec_helper' +provider_class = Puppet::Type.type(:package).provider(:windows) + describe 'windows_java::jdk' do + before :each do + Puppet::Type.type(:package).stubs(:defaultprovider).returns(provider_class) + end let(:title) { '7u51' } let(:facts) { {:operatingsystem => 'windows', :architecture => 'x86_64', :windows_java_temp => 'C:\temp'} } + describe 'when deploying with defaults' do let(:title) { '7u51' } describe 'defaults' do it { - should contain_windows_java__download('Download-jdk-7u51-windows-x64.exe').with( - { - 'source' => 'http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-windows-x64.exe', - 'filename' => 'jdk-7u51-windows-x64.exe', - 'temp_target' => 'C:\\temp' - }) + should contain_download_file('download-jdk-7u51-windows-x64.exe').with( + { + 'url' => 'http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-windows-x64.exe', + 'destination_directory' => 'C:\\temp', + 'destination_file' => 'jdk-7u51-windows-x64.exe', + 'cookies' => ['oraclelicense=accept-securebackup-cookie;gpw_e24=http://edelivery.oracle.com'] + } + ) } it { should contain_windows_java__install('Java SE Development Kit 7 Update 51 (64-bit)').with( - { - 'ensure' => 'present', - 'source' => 'C:\temp\jdk-7u51-windows-x64.exe', - - } - ) + { + 'ensure' => 'present', + 'source' => 'C:\temp\jdk-7u51-windows-x64.exe', + } + ) } it { should contain_windows_env('JAVA_HOME').with_value('C:\\Program Files\\Java\\jdk1.7.0_51') } end end + describe 'install_name' do let(:params) { {:install_name => 'Custom Install Name'} } it { should contain_package('Custom Install Name').with_ensure('present') } end + describe 'source' do let(:params) { {:source => 'http://mynetwork.net/jdk-7u51-x64.exe'} } it { - should contain_windows_java__download('Download-jdk-7u51-x64.exe').with( - { - 'source' => 'http://mynetwork.net/jdk-7u51-x64.exe', - 'filename' => 'jdk-7u51-x64.exe' - } - ) + should contain_download_file('download-jdk-7u51-x64.exe').with( + { + 'url' => 'http://mynetwork.net/jdk-7u51-x64.exe', + 'destination_directory' => 'C:\\temp', + 'destination_file' => 'jdk-7u51-x64.exe', + 'cookies' => ['oraclelicense=accept-securebackup-cookie;gpw_e24=http://edelivery.oracle.com'] + } + ) } end + describe 'version' do let(:title) { 'be meaningless' } let(:params) { {:version => '8u45'} } it { - should contain_windows_java__download('Download-jdk-8u45-windows-x64.exe').with( - { - 'source' => 'http://download.oracle.com/otn-pub/java/jdk/8u45-b15/jdk-8u45-windows-x64.exe', - 'filename' => 'jdk-8u45-windows-x64.exe', - 'temp_target' => 'C:\\temp' - }) + should contain_download_file('download-jdk-8u45-windows-x64.exe').with( + { + 'url' => 'http://download.oracle.com/otn-pub/java/jdk/8u45-b15/jdk-8u45-windows-x64.exe', + 'destination_directory' => 'C:\\temp', + 'destination_file' => 'jdk-8u45-windows-x64.exe', + 'cookies' => ['oraclelicense=accept-securebackup-cookie;gpw_e24=http://edelivery.oracle.com'] + } + ) } it { should contain_package('Java SE Development Kit 8 Update 45 (64-bit)').with_ensure('present') } it { should contain_windows_env('JAVA_HOME').with_value('C:\\Program Files\\Java\\jdk1.8.0_45') } @@ -60,12 +74,14 @@ let(:title) { '9u10' } let(:params) { {:build_number_hash => {'9u10' => 'b12', '9u5' => 'b2'}} } it { - should contain_windows_java__download('Download-jdk-9u10-windows-x64.exe').with( - { - 'source' => 'http://download.oracle.com/otn-pub/java/jdk/9u10-b12/jdk-9u10-windows-x64.exe', - 'filename' => 'jdk-9u10-windows-x64.exe', - 'temp_target' => 'C:\\temp' - }) + should contain_download_file('download-jdk-9u10-windows-x64.exe').with( + { + 'url' => 'http://download.oracle.com/otn-pub/java/jdk/9u10-b12/jdk-9u10-windows-x64.exe', + 'destination_directory' => 'C:\\temp', + 'destination_file' => 'jdk-9u10-windows-x64.exe', + 'cookies' => ['oraclelicense=accept-securebackup-cookie;gpw_e24=http://edelivery.oracle.com'] + } + ) } it { should contain_package('Java SE Development Kit 9 Update 10 (64-bit)').with_ensure('present') } it { should contain_windows_env('JAVA_HOME').with_value('C:\\Program Files\\Java\\jdk1.9.0_10') } @@ -76,17 +92,18 @@ describe arch do let(:params) { {:arch => arch} } it { - should contain_windows_java__download('Download-jdk-7u51-windows-i586.exe').with( - { - 'source' => 'http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-windows-i586.exe', - 'filename' => 'jdk-7u51-windows-i586.exe', - 'temp_target' => 'C:\\temp' - }) + should contain_download_file('download-jdk-7u51-windows-i586.exe').with( + { + 'url' => 'http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-windows-i586.exe', + 'destination_directory' => 'C:\\temp', + 'destination_file' => 'jdk-7u51-windows-i586.exe', + 'cookies' => ['oraclelicense=accept-securebackup-cookie;gpw_e24=http://edelivery.oracle.com'] + } + ) } it { should contain_package('Java SE Development Kit 7 Update 51').with_ensure('present') } it { should contain_windows_env('JAVA_HOME').with_value('C:\\Program Files (x86)\\Java\\jdk1.7.0_51') } end } end - end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 9279d4a..b8cf751 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -40,7 +40,7 @@ on host, "chmod 644 geotrustglobal.pem" on host, "cmd /c certutil -v -addstore Root `cygpath -w geotrustglobal.pem`" end - ['puppetlabs-stdlib', 'badgerious-windows_env', 'cyberious-pget'].each { |dep_module| + ['puppetlabs-stdlib', 'badgerious-windows_env', 'puppet-download_file'].each { |dep_module| on host, puppet("module install #{dep_module}"), {:acceptable_exit_codes => [0, 1]} } end