diff --git a/data/common.yaml b/data/common.yaml index f9ed0a6..a5aea4a 100644 --- a/data/common.yaml +++ b/data/common.yaml @@ -41,12 +41,12 @@ sonarqube::user_system: true sonarqube::version: ~ sonarqube::helper_dir: '/tmp' -sonarqube::runner::download_url: 'http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist' -sonarqube::runner::installroot: '/usr/local' -sonarqube::runner::jdbc: +sonarqube::scanner::download_url: 'https://binaries.sonarsource.com/Distribution/sonar-scanner-cli' +sonarqube::scanner::installroot: '/usr/local' +sonarqube::scanner::jdbc: url: 'jdbc:h2:tcp://localhost:9092/sonar' username: 'sonar' password: 'sonar' -sonarqube::runner::distribution_name: 'sonar-runner' -sonarqube::runner::sonarqube_server: 'http://sonar.local:9000/' -sonarqube::runner::version: ~ +sonarqube::scanner::distribution_name: 'sonar-scanner' +sonarqube::scanner::sonarqube_server: 'http://sonar.local:9000/' +sonarqube::scanner::version: ~ diff --git a/manifests/config.pp b/manifests/config.pp index ff973f2..3cc65c0 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -1,13 +1,15 @@ # @summary Configure SonarQube # @api private class sonarqube::config { + require('sonarqube::install') + File { owner => $sonarqube::user, group => $sonarqube::group, } # Create configuration files - if $sonarqube::config != undef { + if $sonarqube::config !~ Undef { # Create config from scratch, do not use the template. file { "${sonarqube::installdir}/conf/sonar.properties": source => $sonarqube::config, diff --git a/manifests/init.pp b/manifests/init.pp index 52e899f..245d2e4 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -129,46 +129,46 @@ # class sonarqube ( # required parameters - String $arch, - String $context_path, + String[1] $arch, + String[1] $context_path, Hash $crowd, - String $download_url, - String $edition, - String $group, + String[1] $download_url, + String[1] $edition, + String[1] $group, Hash $http_proxy, Hash $https, - String $home, + String[1] $home, Stdlib::Absolutepath $installroot, Hash $jdbc, Hash $ldap, Stdlib::Absolutepath $log_folder, - String $distribution_name, + String[1] $distribution_name, Hash $pam, Stdlib::Absolutepath $plugin_tmpdir, - Integer $port, - Integer $portajp, + Variant[Stdlib::Port, Integer[-1, 0]] $port, + Variant[Stdlib::Port, Integer[-1, 0]] $portajp, Boolean $profile, - String $search_host, - Integer $search_port, - String $service, + String[1] $search_host, + Variant[Stdlib::Port, Integer[-1, 0]] $search_port, + String[1] $service, Boolean $manage_service, Stdlib::Absolutepath $download_dir, Boolean $updatecenter, - String $pidfile, - String $user, + String[1] $pidfile, + String[1] $user, Boolean $user_system, - String $version, + String[1] $version, Stdlib::Absolutepath $helper_dir, # optional parameters - Optional[String] $ce_java_opts = undef, + Optional[String[1]] $ce_java_opts = undef, Optional[Integer] $ce_workercount = undef, - Optional[String] $config = undef, - Optional[String] $host = undef, - Optional[String] $search_java_opts = undef, - Optional[String] $search_java_additional_opts = undef, + Optional[String[1]] $config = undef, + Optional[String[1]] $host = undef, + Optional[String[1]] $search_java_opts = undef, + Optional[String[1]] $search_java_additional_opts = undef, Optional[Hash] $sso = undef, - Optional[String] $web_java_opts = undef, - Optional[String] $system_passcode = undef, + Optional[String[1]] $web_java_opts = undef, + Optional[String[1]] $system_passcode = undef, ) { Exec { path => '/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin', @@ -185,7 +185,5 @@ $tmpzip = "${sonarqube::download_dir}/${sonarqube::distribution_name}-${sonarqube::version}.zip" $script = "${installdir}/bin/${sonarqube::arch}/sonar.sh" - class { 'sonarqube::install': } - -> class { 'sonarqube::config': } - -> class { 'sonarqube::service': } + include(['sonarqube::install', 'sonarqube::config', 'sonarqube::service']) } diff --git a/manifests/install.pp b/manifests/install.pp index c9a2404..6605b00 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -12,12 +12,7 @@ $source_url = "${sonarqube::download_url}/${sonarqube::distribution_name}-${sonarqube::edition}-${sonarqube::version}.zip" } - if ! defined(Package[unzip]) { - stdlib::ensure_packages(['unzip'], { - ensure => present, - before => Exec['install sonarqube distribution'] - }) - } + stdlib::ensure_packages('unzip') # Create user and group user { $sonarqube::user: @@ -26,42 +21,62 @@ managehome => false, system => $sonarqube::user_system, } - -> group { $sonarqube::group: + group { $sonarqube::group: ensure => present, system => $sonarqube::user_system, } # Download distribution archive - -> archive { 'download sonarqube distribution': + archive { 'download sonarqube distribution': ensure => present, path => $sonarqube::tmpzip, source => $source_url, } # Create folder structure - -> file { $sonarqube::home: + file { $sonarqube::home: ensure => directory, mode => '0700', } - -> file { "${sonarqube::installroot}/${sonarqube::distribution_name}-${sonarqube::version}": + file { "${sonarqube::installroot}/${sonarqube::distribution_name}-${sonarqube::version}": ensure => directory, } - -> file { $sonarqube::installdir: - ensure => link, - target => "${sonarqube::installroot}/${sonarqube::distribution_name}-${sonarqube::version}", - notify => Class['sonarqube::service'], + file { $sonarqube::installdir: + ensure => link, + target => "${sonarqube::installroot}/${sonarqube::distribution_name}-${sonarqube::version}", + require => File["${sonarqube::installroot}/${sonarqube::distribution_name}-${sonarqube::version}"], + notify => Class['sonarqube::service'], + } + + sonarqube::move_to_home { 'data': + require => File[$sonarqube::home], + } + + sonarqube::move_to_home { 'extras': + require => File[$sonarqube::home], + } + + sonarqube::move_to_home { 'extensions': + require => File[$sonarqube::home], + } + + sonarqube::move_to_home { 'logs': + require => File[$sonarqube::home], } - -> sonarqube::move_to_home { 'data': } - -> sonarqube::move_to_home { 'extras': } - -> sonarqube::move_to_home { 'extensions': } - -> sonarqube::move_to_home { 'logs': } # Uncompress (new) sonar version - -> exec { 'install sonarqube distribution': - command => "unzip -o ${sonarqube::tmpzip} -d ${sonarqube::installroot} && chown -R \ - ${sonarqube::user}:${sonarqube::group} ${sonarqube::installroot}/${sonarqube::distribution_name}-${sonarqube::version} && chown -R ${sonarqube::user}:${sonarqube::group} ${sonarqube::home}", # lint:ignore:140chars + exec { 'install sonarqube distribution': + command => "unzip -o ${sonarqube::tmpzip} -d ${sonarqube::installroot}", creates => "${sonarqube::installroot}/${sonarqube::distribution_name}-${sonarqube::version}/bin", - notify => Class['sonarqube::service'], + require => [Package['unzip'], Archive['download sonarqube distribution']], + notify => [Class['sonarqube::service'], Exec['sonarqube distribution permissions']], + } + + exec { 'sonarqube distribution permissions': + command => "chown -R ${sonarqube::user}:${sonarqube::group} ${sonarqube::installroot}/${sonarqube::distribution_name}-${sonarqube::version} ${sonarqube::home}", # lint:ignore:140chars + refreshonly => true, + require => [User[$sonarqube::user], Group[$sonarqube::group], File[$sonarqube::home]], + notify => Class['sonarqube::service'], } # Setup helper scripts to ensure that old versions of sonar and plugins @@ -73,15 +88,19 @@ file { "${sonarqube::helper_dir}/cleanup-old-plugin-versions.sh": content => epp("${module_name}/cleanup-old-plugin-versions.sh.epp"), mode => '0755', + require => File[$sonarqube::helper_dir], } - -> file { "${sonarqube::helper_dir}/cleanup-old-sonarqube-versions.sh": + file { "${sonarqube::helper_dir}/cleanup-old-sonarqube-versions.sh": content => epp("${module_name}/cleanup-old-sonarqube-versions.sh.epp"), mode => '0755', + require => File[$sonarqube::helper_dir], } - -> exec { 'remove-old-versions-of-sonarqube': + + exec { 'remove-old-versions-of-sonarqube': command => "${sonarqube::helper_dir}/cleanup-old-sonarqube-versions.sh ${sonarqube::installroot} ${sonarqube::version}", path => '/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin', refreshonly => true, + require => File["${sonarqube::helper_dir}/cleanup-old-sonarqube-versions.sh"], subscribe => File["${sonarqube::installroot}/${sonarqube::distribution_name}-${sonarqube::version}"], } diff --git a/manifests/move_to_home.pp b/manifests/move_to_home.pp index 82331a2..1c86d56 100644 --- a/manifests/move_to_home.pp +++ b/manifests/move_to_home.pp @@ -8,8 +8,10 @@ file { "${home}/${name}": ensure => directory, } - -> file { "${sonarqube::installdir}/${name}": - ensure => link, - target => "${home}/${name}", + file { "${sonarqube::installdir}/${name}": + ensure => link, + force => true, + target => "${home}/${name}", + require => File["${home}/${name}"], } } diff --git a/manifests/plugin.pp b/manifests/plugin.pp index 5622e20..6ed0cc0 100644 --- a/manifests/plugin.pp +++ b/manifests/plugin.pp @@ -28,13 +28,13 @@ # and purge old plugin versions. # define sonarqube::plugin ( - String $version, - String $artifactid = $name, + String[1] $version, + String[1] $artifactid = $name, Enum['present','absent'] $ensure = present, Boolean $legacy = false, - String $groupid = 'org.codehaus.sonar-plugins', - Optional[String] $ghid = undef, - Optional[String] $url = undef, + String[1] $groupid = 'org.codehaus.sonar-plugins', + Optional[String[1]] $ghid = undef, + Optional[String[1]] $url = undef, ) { include 'sonarqube' @@ -44,20 +44,19 @@ # Install plugin if $ensure == present { - if $url { + if $url !~ Undef { # Use direct download URL for installation archive { "download plugin ${plugin_name}": ensure => present, path => $plugin_tmp, source => $url, - before => File[$plugin], notify => [ File[$plugin], Exec["remove old versions of ${artifactid}"], ], } - } elsif $ghid { + } elsif $ghid !~ Undef { # Use GitHub project URL for installation # Compose GitHub download URL. If the project does not use this @@ -68,13 +67,12 @@ ensure => present, path => $plugin_tmp, source => $_ghurl, - before => File[$plugin], notify => [ File[$plugin], Exec["remove old versions of ${artifactid}"], ], } - } elsif ($legacy == false) and $version { + } elsif !$legacy { # Install from SonarSource # NOTE: This feature is deprecated since SonarQube 8.5, see: # https://community.sonarsource.com/t/sonarqube-v8-5-and-beyond-where-did-all-the-plugins-go/32792 @@ -87,20 +85,18 @@ ensure => present, path => $plugin_tmp, source => $_sonarurl, - before => File[$plugin], notify => [ File[$plugin], Exec["remove old versions of ${artifactid}"], ], } - } elsif ($legacy == true) and $version { + } elsif $legacy { # Legacy method: install using Maven. May not work with recent versions. maven { "/tmp/${plugin_name}": groupid => $groupid, artifactid => $artifactid, version => $version, - before => File[$plugin], require => File[$sonarqube::plugin_dir], notify => [ File[$plugin], @@ -114,13 +110,16 @@ # Copy plugin from tmp location to plugin directory. file { $plugin: ensure => $ensure, - source => "/tmp/${plugin_name}", + source => $plugin_tmp, owner => $sonarqube::user, group => $sonarqube::group, - notify => Class['sonarqube::service'], + notify => [ + Class['sonarqube::service'], + Exec["remove old versions of ${artifactid}"], + ], } # Cleanup old version of this plugin - ~> exec { "remove old versions of ${artifactid}": + exec { "remove old versions of ${artifactid}": command => "${sonarqube::helper_dir}/cleanup-old-plugin-versions.sh ${sonarqube::plugin_dir} ${artifactid} ${version}", path => ['/bin', '/sbin', '/usr/bin', '/usr/sbin', '/usr/local/bin', '/usr/local/sbin'], refreshonly => true, diff --git a/manifests/runner/config.pp b/manifests/runner/config.pp deleted file mode 100644 index 40faf1d..0000000 --- a/manifests/runner/config.pp +++ /dev/null @@ -1,12 +0,0 @@ -# @summary Configuration of SonarQube Runner -# @api private -class sonarqube::runner::config { - assert_private() - - require('sonarqube::runner::install') - - # Sonar Runner configuration file - file { "${sonarqube::runner::installroot}/${sonarqube::runner::distribution_name}-${sonarqube::runner::version}/conf/sonar-runner.properties": # lint:ignore:140chars - content => epp("${module_name}/sonar-runner.properties.epp"), - } -} diff --git a/manifests/runner/install.pp b/manifests/runner/install.pp deleted file mode 100644 index fe36a2a..0000000 --- a/manifests/runner/install.pp +++ /dev/null @@ -1,45 +0,0 @@ -# @summary Installation of SonarQube Runner -# @api private -class sonarqube::runner::install { - assert_private() - - if ! defined(Package[unzip]) { - package { 'unzip': - ensure => present, - before => Exec['unzip-sonar-runner'], - } - } - - $tmpzip = "/usr/local/src/${sonarqube::runner::distribution_name}-dist-${sonarqube::runner::version}.zip" - - archive { 'download-sonar-runner': - ensure => present, - path => $tmpzip, - source => "${sonarqube::runner::download_url}/${sonarqube::runner::version}/sonar-runner-dist-${sonarqube::runner::version}.zip", - } - - -> file { "${sonarqube::runner::installroot}/${sonarqube::runner::distribution_name}-${sonarqube::runner::version}": - ensure => directory, - } - - -> file { "${sonarqube::runner::installroot}/${sonarqube::runner::distribution_name}": - ensure => link, - target => "${sonarqube::runner::installroot}/${sonarqube::runner::distribution_name}-${sonarqube::runner::version}", - } - - -> exec { 'unzip-sonar-runner': - command => "unzip -o ${tmpzip} -d ${sonarqube::runner::installroot}", - creates => "${sonarqube::runner::installroot}/sonar-runner-${sonarqube::runner::version}/bin", - require => [Package['unzip'], Archive['download-sonar-runner']], - } - - # Sonar settings for terminal sessions. - file { '/etc/profile.d/sonarhome.sh': - content => "export SONAR_RUNNER_HOME=${sonarqube::runner::installroot}/${sonarqube::runner::distribution_name}-${sonarqube::runner::version}", # lint:ignore:140chars - } - - file { '/usr/bin/sonar-runner': - ensure => link, - target => "${sonarqube::runner::installroot}/${sonarqube::runner::distribution_name}-${sonarqube::runner::version}/bin/sonar-runner", - } -} diff --git a/manifests/runner.pp b/manifests/scanner.pp similarity index 71% rename from manifests/runner.pp rename to manifests/scanner.pp index 6a16565..a14dbaf 100644 --- a/manifests/runner.pp +++ b/manifests/scanner.pp @@ -1,4 +1,4 @@ -# @summary Install and configure SonarQube Runner +# @summary Install and configure SonarQube Scanner # # @param distribution_name # Specifies the basename of the installation archive. @@ -19,17 +19,17 @@ # @param version # Specifies the version that should be installed/updated. # -class sonarqube::runner ( - String $download_url, +class sonarqube::scanner ( + String[1] $download_url, Stdlib::Absolutepath $installroot, Hash $jdbc, - String $distribution_name, - String $sonarqube_server, - String $version, + String[1] $distribution_name, + String[1] $sonarqube_server, + String[1] $version, ) { Exec { path => '/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin', } - include(['sonarqube::runner::install', 'sonarqube::runner::config']) + include(['sonarqube::scanner::install', 'sonarqube::scanner::config']) } diff --git a/manifests/scanner/config.pp b/manifests/scanner/config.pp new file mode 100644 index 0000000..774e1f6 --- /dev/null +++ b/manifests/scanner/config.pp @@ -0,0 +1,12 @@ +# @summary Configuration of SonarQube Scanner +# @api private +class sonarqube::scanner::config { + assert_private() + + require('sonarqube::scanner::install') + + # Sonar Scanner configuration file + file { "${sonarqube::scanner::installroot}/${sonarqube::scanner::distribution_name}-${sonarqube::scanner::version}/conf/sonar-scanner.properties": # lint:ignore:140chars + content => epp("${module_name}/sonar-scanner.properties.epp"), + } +} diff --git a/manifests/scanner/install.pp b/manifests/scanner/install.pp new file mode 100644 index 0000000..52d82be --- /dev/null +++ b/manifests/scanner/install.pp @@ -0,0 +1,42 @@ +# @summary Installation of SonarQube Scanner +# @api private +class sonarqube::scanner::install { + assert_private() + + stdlib::ensure_packages('unzip') + + $tmpzip = "/usr/local/src/${sonarqube::scanner::distribution_name}-cli-${sonarqube::scanner::version}.zip" + + archive { 'download-sonar-scanner': + ensure => present, + path => $tmpzip, + source => "${sonarqube::scanner::download_url}/sonar-scanner-cli-${sonarqube::scanner::version}.zip", + } + + file { "${sonarqube::scanner::installroot}/${sonarqube::scanner::distribution_name}-${sonarqube::scanner::version}": + ensure => directory, + } + + file { "${sonarqube::scanner::installroot}/${sonarqube::scanner::distribution_name}": + ensure => link, + target => "${sonarqube::scanner::installroot}/${sonarqube::scanner::distribution_name}-${sonarqube::scanner::version}", + require => File["${sonarqube::scanner::installroot}/${sonarqube::scanner::distribution_name}-${sonarqube::scanner::version}"], + } + + exec { 'unzip-sonar-scanner': + command => "unzip -o ${tmpzip} -d ${sonarqube::scanner::installroot}", + creates => "${sonarqube::scanner::installroot}/sonar-scanner-${sonarqube::scanner::version}/bin", + require => [Package['unzip'], Archive['download-sonar-scanner'], File["${sonarqube::scanner::installroot}/${sonarqube::scanner::distribution_name}-${sonarqube::scanner::version}"]], # lint:ignore:140chars + } + + file { '/usr/bin/sonar-scanner': + ensure => link, + target => "${sonarqube::scanner::installroot}/${sonarqube::scanner::distribution_name}-${sonarqube::scanner::version}/bin/sonar-scanner", # lint:ignore:140chars + require => Exec['unzip-sonar-scanner'], + } + + # Sonar settings for terminal sessions. + file { '/etc/profile.d/sonarhome.sh': + content => "export SONAR_SCANNER_HOME=${sonarqube::scanner::installroot}/${sonarqube::scanner::distribution_name}-${sonarqube::scanner::version}", # lint:ignore:140chars + } +} diff --git a/manifests/service.pp b/manifests/service.pp index 1441e3b..5ffc2f1 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -1,6 +1,8 @@ # @summary Setup SonarQube service # @api private class sonarqube::service { + require(['sonarqube::install', 'sonarqube::config']) + File { owner => $sonarqube::user, group => $sonarqube::group, @@ -23,7 +25,7 @@ match => '^PIDDIR=', multiple => true, } - -> file_line { 'set RUN_AS_USER in startup script': + file_line { 'set RUN_AS_USER in startup script': ensure => present, path => $sonarqube::script, line => "RUN_AS_USER=${sonarqube::user}", @@ -31,6 +33,7 @@ # insert after PIDDIR of no match is found after => '^PIDDIR=', multiple => true, + require => File_line['set PIDDIR in startup script'], } } @@ -41,16 +44,17 @@ } # Add systemd service configuration - -> file { "/etc/systemd/system/${sonarqube::service}.service": + file { "/etc/systemd/system/${sonarqube::service}.service": ensure => file, owner => root, group => root, mode => '0644', content => epp("${module_name}/sonar.service.epp"), + notify => Service[$sonarqube::service], } # Enable systemd service - -> service { $sonarqube::service: + service { $sonarqube::service: ensure => running, hasrestart => true, hasstatus => true, diff --git a/spec/acceptance/plugin_spec.rb b/spec/acceptance/plugin_spec.rb index c3450dd..2da24ac 100644 --- a/spec/acceptance/plugin_spec.rb +++ b/spec/acceptance/plugin_spec.rb @@ -1,10 +1,11 @@ require 'spec_helper_acceptance' describe 'sonarqube::plugin define' do - sonar_version = '9.8.0.63668' + sonar_version = '9.9.4.87374' sonar_user = 'sonar' sonar_group = 'sonar' - plugin_dir = '/var/local/sonar/extensions/plugins' + defaut_plugin_dir = '/var/local/sonar/lib/extensions' + custom_plugin_dir = '/var/local/sonar/extensions/plugins' before(:all) do apply_manifest(%( @@ -14,42 +15,44 @@ $target_path = '/usr/java' } - java::adopt { 'jdk11': - ensure => 'present', - java => 'jdk', - version_major => '11.0.6', - version_minor => '10', + java::adoptium { 'jdk17': + version_major => '17', + version_minor => '0', + version_patch => '9', + version_build => '9', } - -> file { '/usr/bin/java': - ensure => link, - target => "${target_path}/jdk-11.0.6+10/bin/java", + file { '/usr/bin/java': + ensure => link, + target => "${target_path}/jdk-17.0.9+9/bin/java", + require => Java::Adoptium['jdk17'], } ), catch_failures: true) end - describe 'removing a plugin' do - plugin_name = 'sonar-groovy-plugin' - plugin_version = '1.4' + describe 'removing a default plugin' do + plugin_name = 'sonar-csharp-plugin' + plugin_version = '8.51.0.59060' let(:pp) do <<-MANIFEST class { 'sonarqube': version => "#{sonar_version}" } - ~> sonarqube::plugin { #{plugin_name}: - ensure => 'absent', - version => "#{plugin_version}", + sonarqube::plugin { #{plugin_name}: + ensure => 'absent', + version => "#{plugin_version}", + subscribe => Class['sonarqube'], } MANIFEST end it { apply_manifest(pp, catch_failures: true) } - it { expect(file("#{plugin_dir}/#{plugin_name}-#{plugin_version}.jar")).not_to be_file } + it { expect(file("#{default_plugin_dir}/#{plugin_name}-#{plugin_version}.jar")).not_to be_file } end describe 'installing a plugin from github' do plugin_name = 'checkstyle-sonar-plugin' - plugin_version = '4.31' + plugin_version = '10.12.5' ghid = 'checkstyle/sonar-checkstyle' let(:pp) do @@ -57,22 +60,23 @@ class { 'sonarqube': class { 'sonarqube': version => "#{sonar_version}" } - ~> sonarqube::plugin { #{plugin_name}: - version => "#{plugin_version}", - ghid => "#{ghid}", + sonarqube::plugin { #{plugin_name}: + version => "#{plugin_version}", + ghid => "#{ghid}", + subscribe => Class['sonarqube'], } MANIFEST end it { apply_manifest(pp, catch_failures: true) } - it { expect(file("#{plugin_dir}/#{plugin_name}-#{plugin_version}.jar")).to be_file } - it { expect(file("#{plugin_dir}/#{plugin_name}-#{plugin_version}.jar")).to be_owned_by sonar_user } - it { expect(file("#{plugin_dir}/#{plugin_name}-#{plugin_version}.jar")).to be_grouped_into sonar_group } + it { expect(file("#{custom_plugin_dir}/#{plugin_name}-#{plugin_version}.jar")).to be_file } + it { expect(file("#{custom_plugin_dir}/#{plugin_name}-#{plugin_version}.jar")).to be_owned_by sonar_user } + it { expect(file("#{custom_plugin_dir}/#{plugin_name}-#{plugin_version}.jar")).to be_grouped_into sonar_group } end describe 'installing a plugin from a URL' do plugin_name = 'sonar-detekt' - plugin_version = '2.0.0' + plugin_version = '2.5.0' plugin_url = "https://github.com/detekt/sonar-kotlin/releases/download/#{plugin_version}/#{plugin_name}-#{plugin_version}.jar" let(:pp) do @@ -80,16 +84,17 @@ class { 'sonarqube': class { 'sonarqube': version => "#{sonar_version}" } - ~> sonarqube::plugin { #{plugin_name}: - version => "#{plugin_version}", - url => "#{plugin_url}", + sonarqube::plugin { #{plugin_name}: + version => "#{plugin_version}", + url => "#{plugin_url}", + subscribe => Class['sonarqube'], } MANIFEST end it { apply_manifest(pp, catch_failures: true) } - it { expect(file("#{plugin_dir}/#{plugin_name}-#{plugin_version}.jar")).to be_file } - it { expect(file("#{plugin_dir}/#{plugin_name}-#{plugin_version}.jar")).to be_owned_by sonar_user } - it { expect(file("#{plugin_dir}/#{plugin_name}-#{plugin_version}.jar")).to be_grouped_into sonar_group } + it { expect(file("#{custom_plugin_dir}/#{plugin_name}-#{plugin_version}.jar")).to be_file } + it { expect(file("#{custom_plugin_dir}/#{plugin_name}-#{plugin_version}.jar")).to be_owned_by sonar_user } + it { expect(file("#{custom_plugin_dir}/#{plugin_name}-#{plugin_version}.jar")).to be_grouped_into sonar_group } end end diff --git a/spec/acceptance/sonarqube_spec.rb b/spec/acceptance/sonarqube_spec.rb index f1482a5..f113972 100644 --- a/spec/acceptance/sonarqube_spec.rb +++ b/spec/acceptance/sonarqube_spec.rb @@ -14,15 +14,16 @@ $target_path = '/usr/java' } - java::adopt { 'jdk11': - ensure => 'present', - java => 'jdk', - version_major => '11.0.6', - version_minor => '10', + java::adoptium { 'jdk17': + version_major => '17', + version_minor => '0', + version_patch => '9', + version_build => '9', } - -> file { '/usr/bin/java': - ensure => link, - target => "${target_path}/jdk-11.0.6+10/bin/java", + file { '/usr/bin/java': + ensure => link, + target => "${target_path}/jdk-17.0.9+9/bin/java", + require => Java::Adoptium['jdk17'], } ), catch_failures: true) end @@ -53,7 +54,7 @@ end context 'when installing latest version' do - let(:version) { '9.8.0.63668' } + let(:version) { '9.9.4.87374' } it_behaves_like :sonar_common end diff --git a/spec/classes/runner_spec.rb b/spec/classes/runner_spec.rb deleted file mode 100644 index 50f5a7c..0000000 --- a/spec/classes/runner_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'spec_helper' - -describe 'sonarqube::runner' do - let(:runner_version) { '2.4' } - - context 'when installing with default config' do - let(:params) { { version: runner_version.to_s } } - - it { is_expected.to create_class('sonarqube::runner::install') } - it { is_expected.to contain_archive('download-sonar-runner').with_source('http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip') } - it { is_expected.to contain_file('/usr/local/sonar-runner') } - end - - context 'when running with default config' do - let(:params) { { version: runner_version.to_s } } - - it { is_expected.to create_class('sonarqube::runner::config') } - it { is_expected.to contain_file('/usr/local/sonar-runner-2.4/conf/sonar-runner.properties') } - end -end diff --git a/spec/classes/scanner_spec.rb b/spec/classes/scanner_spec.rb new file mode 100644 index 0000000..3218000 --- /dev/null +++ b/spec/classes/scanner_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe 'sonarqube::scanner' do + let(:scanner_version) { '5.0.1.3006' } + + context 'when installing with default config' do + let(:params) { { version: scanner_version.to_s } } + + it { is_expected.to create_class('sonarqube::scanner::install') } + it { is_expected.to contain_archive('download-sonar-scanner').with_source("https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-#{scanner_version}.zip") } + it { is_expected.to contain_file("/usr/local/sonar-scanner-#{scanner_version}") } + end + + context 'when running with default config' do + let(:params) { { version: scanner_version.to_s } } + + it { is_expected.to create_class('sonarqube::scanner::config') } + it { is_expected.to contain_file("/usr/local/sonar-scanner-#{scanner_version}/conf/sonar-scanner.properties") } + end +end diff --git a/spec/classes/sonarqube_spec.rb b/spec/classes/sonarqube_spec.rb index 6f60af2..5e3b414 100644 --- a/spec/classes/sonarqube_spec.rb +++ b/spec/classes/sonarqube_spec.rb @@ -2,8 +2,8 @@ describe 'sonarqube' do let(:sonar_properties) { '/usr/local/sonar/conf/sonar.properties' } - let(:sonar_version) { '8.9.9.56886' } - let(:sonar_version_latest) { '9.8.0.63668' } + let(:sonar_version) { '9.9.4.87374' } + let(:sonar_version_latest) { '10.4.1.88267' } context 'when installing LTS version', :compile do let(:params) { { version: sonar_version.to_s } } @@ -15,13 +15,8 @@ it { is_expected.to contain_archive('download sonarqube distribution').with_source("https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-#{sonar_version}.zip") } it { - is_expected.to contain_file_line('set PIDDIR in startup script').with( - match: '^PIDDIR=', - ) - } - it { - is_expected.to contain_file_line('set RUN_AS_USER in startup script').with( - match: '^RUN_AS_USER=', + is_expected.to contain_file_line('set PIDFILE in startup script').with( + match: '^PIDFILE=', ) } end @@ -43,7 +38,7 @@ end context 'when crowd configuration is supplied', :compile do - let :params do + let(:params) do { version: sonar_version.to_s, crowd: @@ -76,7 +71,7 @@ end context 'when unzip package is already defined', :compile do - let :pre_condition do + let(:pre_condition) do "package { 'unzip': ensure => installed }" end let(:params) { { version: sonar_version.to_s } } @@ -85,7 +80,7 @@ end context 'when ldap local users configuration is supplied', :compile do - let :params do + let(:params) do { version: sonar_version.to_s, ldap: @@ -104,7 +99,7 @@ end context 'when ldap local users configuration is supplied as array', :compile do - let :params do + let(:params) do { version: sonar_version.to_s, ldap: @@ -123,7 +118,7 @@ end context 'when no ldap local users configuration is supplied', :compile do - let :params do + let(:params) do { version: sonar_version.to_s, ldap: diff --git a/spec/default_facts.yml b/spec/default_facts.yml index 3346c39..9f172f0 100644 --- a/spec/default_facts.yml +++ b/spec/default_facts.yml @@ -2,8 +2,4 @@ # # Facts specified here will override the values provided by rspec-puppet-facts. --- -networking: - ip: "172.16.254.254" - ip6: "FE80:0000:0000:0000:AAAA:AAAA:AAAA" - mac: "AA:AA:AA:AA:AA:AA" is_pe: false diff --git a/spec/defines/sonarqube_plugin_spec.rb b/spec/defines/sonarqube_plugin_spec.rb index fc82191..10f1af6 100644 --- a/spec/defines/sonarqube_plugin_spec.rb +++ b/spec/defines/sonarqube_plugin_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' describe 'sonarqube::plugin', type: :define do - let(:sonar_version) { '8.9.9.56886' } + let(:sonar_version) { '9.9.4.87374' } on_supported_os.each do |os, _facts| context "on #{os}" do context 'when removing a plugin' do - plugin_name = 'sonar-kotlin-plugin' - plugin_version = '1.7.0.883' + plugin_name = 'sonar-csharp-plugin' + plugin_version = '8.51.0.59060' let(:title) { plugin_name } let(:params) do @@ -30,7 +30,7 @@ class { sonarqube: context 'when installing a plugin from sonarsource' do plugin_name = 'sonar-kotlin-plugin' - plugin_version = '1.7.0.883' + plugin_version = '2.20.0.4382' let(:title) { plugin_name } let(:params) do @@ -51,8 +51,8 @@ class { sonarqube: end context 'when installing a plugin from github' do - plugin_name = 'sonar-checkstyle-plugin' - plugin_version = '4.31' + plugin_name = 'checkstyle-sonar-plugin' + plugin_version = '10.12.5' ghid = 'checkstyle/sonar-checkstyle' let(:title) { plugin_name } @@ -76,7 +76,7 @@ class { sonarqube: context 'when installing a plugin from a URL' do plugin_name = 'sonar-detekt' - plugin_version = '2.0.0' + plugin_version = '2.5.0' plugin_url = "https://github.com/detekt/sonar-kotlin/releases/download/#{plugin_version}/#{plugin_name}-#{plugin_version}.jar" let(:title) { plugin_name } diff --git a/templates/sonar-runner.properties.epp b/templates/sonar-scanner.properties.epp similarity index 62% rename from templates/sonar-runner.properties.epp rename to templates/sonar-scanner.properties.epp index d9d28b9..59472b8 100644 --- a/templates/sonar-runner.properties.epp +++ b/templates/sonar-scanner.properties.epp @@ -6,13 +6,13 @@ #No information about specific project should appear here #----- Default SonarQube server -sonar.host.url=<%= $sonarqube::runner::sonarqube_server %> +sonar.host.url=<%= $sonarqube::scanner::sonarqube_server %> -<% if !empty($sonarqube::runner::jdbc) { -%> +<% if !empty($sonarqube::scanner::jdbc) { -%> #----- Database -sonar.jdbc.url=<%= $sonarqube::runner::jdbc['url'] %> -sonar.jdbc.username=<%= $sonarqube::runner::jdbc['username'] %> -sonar.jdbc.password=<%= $sonarqube::runner::jdbc['password'] %> +sonar.jdbc.url=<%= $sonarqube::scanner::jdbc['url'] %> +sonar.jdbc.username=<%= $sonarqube::scanner::jdbc['username'] %> +sonar.jdbc.password=<%= $sonarqube::scanner::jdbc['password'] %> <% } -%> #----- Default source code encoding