diff --git a/Gemfile b/Gemfile index d62760b..551efc7 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'https://rubygems.org' group :rake do gem 'puppet', :require => false - gem 'rspec-puppet', '>=1.0.0', :require => false + gem 'rspec-puppet', '>=1.0.0', :git => 'https://github.com/rodjek/rspec-puppet.git', :require => false gem 'rspec-its', :require => false gem 'rake', :require => false gem 'puppet-lint', :require => false diff --git a/Gemfile.lock b/Gemfile.lock index d404e1b..c7f7337 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,16 +1,14 @@ +GIT + remote: https://github.com/rodjek/rspec-puppet.git + revision: 6ac97993fa972a15851a73d55fe3d1c0a85172b5 + specs: + rspec-puppet (1.0.1) + rspec + GEM remote: https://rubygems.org/ specs: CFPropertyList (2.2.8) - activemodel (4.0.5) - activesupport (= 4.0.5) - builder (~> 3.1.0) - activesupport (4.0.5) - i18n (~> 0.6, >= 0.6.9) - minitest (~> 4.2) - multi_json (~> 1.3) - thread_safe (~> 0.1) - tzinfo (~> 0.3.37) addressable (2.3.6) archive-tar-minitar (0.5.2) autoparse (0.3.3) @@ -20,11 +18,14 @@ GEM aws-sdk (1.42.0) json (~> 1.4) nokogiri (>= 1.4.4) - beaker (1.13.0) + beaker (1.20.1) aws-sdk (= 1.42.0) blimpy (~> 0.6) + docker-api fission (~> 0.4) + fog (~> 1.22.1) google-api-client (~> 0.7.1) + hocon (~> 0.0.4) inifile (~> 2.0) json (~> 1.8) mime-types (~> 1.25) @@ -33,7 +34,7 @@ GEM nokogiri (~> 1.5.10) rbvmomi (= 1.8.1) unf (~> 0.1) - beaker-rspec (2.2.5) + beaker-rspec (3.0.0) beaker (~> 1.10) rspec serverspec (~> 1.0) @@ -42,15 +43,15 @@ GEM fog minitar thor - builder (3.1.4) + builder (3.2.2) diff-lcs (1.2.5) - docker-api (1.10.11) + docker-api (1.15.0) archive-tar-minitar - excon (>= 0.28) + excon (>= 0.38.0) json - excon (0.37.0) + excon (0.41.0) extlib (0.9.16) - facter (2.0.2) + facter (2.3.0) CFPropertyList (~> 2.2.6) faraday (0.9.0) multipart-post (>= 1.2, < 3) @@ -62,12 +63,13 @@ GEM fog-json ipaddress (~> 0.5) nokogiri (~> 1.5, >= 1.5.11) - fog-brightbox (0.0.2) - fog-core + fog-brightbox (0.6.1) + fog-core (~> 1.22) fog-json - fog-core (1.22.0) + inflecto + fog-core (1.25.0) builder - excon (~> 0.33) + excon (~> 0.38) formatador (~> 0.2) mime-types net-scp (~> 1.1) @@ -86,29 +88,24 @@ GEM retriable (>= 1.4) signet (>= 0.5.0) uuidtools (>= 2.1.0) - her (0.7.2) - activemodel (>= 3.0.0, < 4.2) - activesupport (>= 3.0.0, < 4.2) - faraday (>= 0.8, < 1.0) - multi_json (~> 1.7) hiera (1.3.4) json_pure highline (1.6.21) - i18n (0.6.9) + hocon (0.0.6) + inflecto (0.0.2) inifile (2.0.2) ipaddress (0.8.0) json (1.8.1) json_pure (1.8.1) jwt (1.0.0) - launchy (2.4.2) + launchy (2.4.3) addressable (~> 2.3) librarian (0.1.2) highline thor (~> 0.15) - librarian-puppet (1.1.1) + librarian-puppet (1.0.1) json librarian (>= 0.1.2) - puppet_forge metaclass (0.0.4) mime-types (1.25.1) minitar (0.5.4) @@ -120,22 +117,22 @@ GEM net-scp (1.2.1) net-ssh (>= 2.6.5) net-ssh (2.9.1) + netrc (0.8.0) nokogiri (1.5.11) - puppet (3.6.2) + puppet (3.7.3) facter (> 1.6, < 3) hiera (~> 1.0) json_pure - rgen (~> 0.6.5) - puppet-blacksmith (2.1.0) - nokogiri + puppet-blacksmith (3.0.3) puppet (>= 2.7.16) rest-client - puppet-lint (0.3.2) - puppet_forge (1.0.2) - her (~> 0.6) - puppetlabs_spec_helper (0.5.2) + puppet-lint (1.1.0) + puppet-syntax (1.3.0) + rake + puppetlabs_spec_helper (0.8.2) mocha puppet-lint + puppet-syntax rake rspec rspec-puppet @@ -144,43 +141,39 @@ GEM builder nokogiri (>= 1.4.1) trollop - rest-client (1.6.7) - mime-types (>= 1.16) + rest-client (1.7.2) + mime-types (>= 1.16, < 3.0) + netrc (~> 0.7) retriable (1.4.1) - rgen (0.6.6) rspec (2.99.0) rspec-core (~> 2.99.0) rspec-expectations (~> 2.99.0) rspec-mocks (~> 2.99.0) - rspec-core (2.99.1) - rspec-expectations (2.99.1) + rspec-core (2.99.2) + rspec-expectations (2.99.2) diff-lcs (>= 1.1.3, < 2.0) rspec-its (1.0.1) rspec-core (>= 2.99.0.beta1) rspec-expectations (>= 2.99.0.beta1) - rspec-mocks (2.99.1) - rspec-puppet (1.0.1) - rspec - serverspec (1.9.0) + rspec-mocks (2.99.2) + serverspec (1.16.0) highline net-ssh - rspec (~> 2.13) + rspec (~> 2.99) rspec-its - specinfra (~> 1.18) + specinfra (~> 1.27) signet (0.5.1) addressable (>= 2.2.3) faraday (>= 0.9.0.rc5) jwt (>= 0.1.5) multi_json (>= 1.0.0) - specinfra (1.18.2) + specinfra (1.27.5) thor (0.19.1) - thread_safe (0.3.4) trollop (2.0) - tzinfo (0.3.39) unf (0.1.4) unf_ext unf_ext (0.0.6) - uuidtools (2.1.4) + uuidtools (2.1.5) PLATFORMS ruby @@ -197,4 +190,4 @@ DEPENDENCIES puppetlabs_spec_helper rake rspec-its - rspec-puppet (>= 1.0.0) + rspec-puppet (>= 1.0.0)! diff --git a/Modulefile b/Modulefile index 05b8223..2c759e6 100644 --- a/Modulefile +++ b/Modulefile @@ -7,4 +7,3 @@ project_page 'http://github.com/maestrodev/puppet-maven' source 'http://github.com/maestrodev/puppet-maven' summary 'Apache Maven module for Puppet' description 'A Puppet module to download artifacts from Maven repositories' -dependency 'maestrodev/wget', '>=1.0.0' diff --git a/Puppetfile b/Puppetfile index 8f3a226..4dba770 100644 --- a/Puppetfile +++ b/Puppetfile @@ -1,3 +1,2 @@ forge 'http://forge.puppetlabs.com' -mod 'maestrodev/wget', '>=1.0.0' diff --git a/Puppetfile.lock b/Puppetfile.lock index 4b21f01..51949ef 100644 --- a/Puppetfile.lock +++ b/Puppetfile.lock @@ -1,8 +1,2 @@ -FORGE - remote: http://forge.puppetlabs.com - specs: - maestrodev/wget (1.1.0) - DEPENDENCIES - maestrodev/wget (>= 1.0.0) diff --git a/manifests/maven.pp b/manifests/maven.pp index d0b0127..33fa3e0 100644 --- a/manifests/maven.pp +++ b/manifests/maven.pp @@ -20,6 +20,15 @@ # - $version: # Maven version. # +# - $manage_symlink: +# If symlink should be managed +# +# - $system_package: +# Name of system package to install. False to install with wget / tar +# +# - $symlink_target: +# Optional alternative path to mvn cmd +# # Requires: # Java package installed. # @@ -30,48 +39,58 @@ # class maven::maven( $version = '3.0.5', + $manage_symlink = true, + $system_package = false, + $symlink_target = undef, $repo = { #url => 'http://repo1.maven.org/maven2', #username => '', #password => '', } ) { - $archive = "/tmp/apache-maven-${version}-bin.tar.gz" - - # Avoid redownloading when tmp tar.gz is deleted - if $::maven_version != $version { - - # we could use puppet-stdlib function !empty(repo) but avoiding adding a new - # dependency for now + if $system_package { + package { $system_package: + ensure => $version + } -> + File <| title == '/usr/bin/mvn' |> + } else { if "x${repo['url']}x" != 'xx' { - wget::authfetch { 'fetch-maven': - source => "${repo['url']}/org/apache/maven/apache-maven/$version/apache-maven-${version}-bin.tar.gz", - destination => $archive, - user => $repo['username'], - password => $repo['password'], - before => Exec['maven-untar'], - } + $repo_url = "${repo['url']}/org/apache/maven/apache-maven/${version}/apache-maven-${version}-bin.tar.gz" } else { - wget::fetch { 'fetch-maven': - source => "http://archive.apache.org/dist/maven/binaries/apache-maven-${version}-bin.tar.gz", - destination => $archive, - before => Exec['maven-untar'], + $repo_url = "http://archive.apache.org/dist/maven/binaries/apache-maven-${version}-bin.tar.gz" + } + if !defined(Package['wget']) { + package { 'wget': + ensure => present } } - exec { 'maven-untar': - command => "tar xf /tmp/apache-maven-${version}-bin.tar.gz", + if "x${repo['username']}x" != 'xx' and "x${repo['password']}x" != 'xx' { + $wget_login = "--user=\"${repo['username']}\" --password=\"${repo['password']}\" " + } else { + $wget_login = '' + } + exec { 'install_maven': + command => "wget -O - ${wget_login}${repo_url} | tar zxf -", cwd => '/opt', + path => ['/usr/local/bin', '/usr/bin', '/bin'], creates => "/opt/apache-maven-${version}", - path => ['/bin','/usr/bin'], - } + require => Package['wget'] + } -> + File <| title == '/usr/bin/mvn' |> + } + if $manage_symlink { + $symlink_target_real = $symlink_target ? { + undef => "/opt/apache-maven-${version}/bin/mvn", + default => $symlink_target + } file { '/usr/bin/mvn': ensure => link, - target => "/opt/apache-maven-${version}/bin/mvn", - require => Exec['maven-untar'], + target => $symlink_target_real } -> file { '/usr/local/bin/mvn': ensure => absent, } } + } diff --git a/spec/classes/maven_spec.rb b/spec/classes/maven_spec.rb index 0a50af7..4e8bc04 100644 --- a/spec/classes/maven_spec.rb +++ b/spec/classes/maven_spec.rb @@ -4,12 +4,12 @@ let(:title) { 'maven' } context "when downloading maven", :compile do - it do should contain_wget__fetch('fetch-maven').with( - 'source' => 'http://archive.apache.org/dist/maven/binaries/apache-maven-3.0.5-bin.tar.gz', - 'user' => nil, - 'password' => nil + it do should contain_exec('install_maven').with( + 'command' => 'wget -O - http://archive.apache.org/dist/maven/binaries/apache-maven-3.0.5-bin.tar.gz | tar zxf -' ) end - it { should contain_exec('maven-untar') } + it 'should fetch maven before managing symlink' do + should contain_exec('install_maven').that_comes_before('File[/usr/bin/mvn]') + end end context "when downloading maven from another repo", :compile do @@ -21,25 +21,53 @@ } } it 'should fetch maven with username and password' do - should contain_wget__authfetch('fetch-maven').with( - 'source' => 'http://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.0.5/apache-maven-3.0.5-bin.tar.gz', - 'user' => 'u', - 'password' => 'p') + should contain_exec('install_maven').with( + 'command' => 'wget -O - --user="u" --password="p" http://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.0.5/apache-maven-3.0.5-bin.tar.gz | tar zxf -' + ) + end + end + + context "when installing maven from os package repository", :compile do + let(:params) { { + :system_package => 'maven-package', + :version => 'present' + } } + + it 'should contain package resource' do + should contain_package('maven-package').with( + :ensure => 'present' + ) + end + + it 'should not fetch maven from tar gz' do + should_not contain_exec('install_maven') + end + + it 'should install package before symlink' do + should contain_package('maven-package').that_comes_before('File[/usr/bin/mvn]') end end - context "when maven was already installed" do + context "when not managing symlink", :compile do + let(:params) { { + :manage_symlink => false + } } - context "in the same version", :compile do - let(:facts) {{ :maven_version => '3.0.5' }} - it { should_not contain_wget__fetch('fetch-maven') } - it { should_not contain_exec('maven-untar') } + it 'should not manage symlink' do + should_not contain_file('/usr/bin/mvn') + should_not contain_file('/usr/local/bin/mvn') end + end + + context "when managing custom symlink", :compile do + let(:params) { { + :symlink_target => '/custom/bin/mvn' + } } - context "in a different version", :compile do - let(:facts) {{ :maven_version => '3.0.4' }} - it { should contain_wget__fetch('fetch-maven') } - it { should contain_exec('maven-untar') } + it 'should manage symlink target' do + should contain_file('/usr/bin/mvn').with( + :target => '/custom/bin/mvn' + ) end end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 7a2c344..b9dded3 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -21,7 +21,6 @@ end hosts.each do |host| - on host, puppet('module','install','maestrodev-wget','-v 1.0.0'), { :acceptable_exit_codes => [0,1] } on host, puppet('module','install','puppetlabs-java','-v 1.0.1'), { :acceptable_exit_codes => [0,1] } end puppet_module_install(:source => proj_root, :module_name => 'maven')