@@ -87,15 +87,15 @@ class SonarQubeServiceSpec extends PipelineSpockTestBase {
8787 logger. debugMode >> false
8888 def service = new SonarQubeService (steps, logger, " env" )
8989 def optionsWithPrivateToken = [
90- properties : [' sonar.projectKey' : ' key' , ' sonar.projectName' : ' name' ],
90+ properties : [' sonar.projectKey' : ' key' , ' sonar.projectName' : ' name' , ' sonar.filesize.limit ' : ' 2 ' ],
9191 gitCommit : " abcdef123456" ,
9292 pullRequestInfo : [:],
9393 sonarQubeEdition : " community" ,
9494 exclusions : " test/**" ,
9595 privateToken : " my-private-token"
9696 ]
9797 def optionsWithoutPrivateToken = [
98- properties : [' sonar.projectKey' : ' key' , ' sonar.projectName' : ' name' ],
98+ properties : [' sonar.projectKey' : ' key' , ' sonar.projectName' : ' name' , ' sonar.filesize.limit ' : ' 2 ' ],
9999 gitCommit : " abcdef123456" ,
100100 pullRequestInfo : [:],
101101 sonarQubeEdition : " community" ,
@@ -109,8 +109,8 @@ class SonarQubeServiceSpec extends PipelineSpockTestBase {
109109
110110 then :
111111 2 * steps. sh(label : ' Set Java 21 for SonarQube scan' , script : " source use-j21.sh" )
112- 1 * steps. sh(label : ' Run SonarQube scan' , script : { it. contains(" /opt/sonar-scanner/bin/sonar-scanner" ) && it. contains(" -Dsonar.projectKey=key" ) && it. contains(" -Dsonar.projectName=name" ) && it. contains(" -Dsonar.exclusions=test/**" ) && it. contains(" -Dsonar.auth.token=my-private-token" ) })
113- 1 * steps. sh(label : ' Run SonarQube scan' , script : { it. contains(" /opt/sonar-scanner/bin/sonar-scanner" ) && it. contains(" -Dsonar.projectKey=key" ) && it. contains(" -Dsonar.projectName=name" ) && it. contains(" -Dsonar.exclusions=test/**" ) && it. contains(" -Dsonar.auth.token=public-token" ) })
112+ 1 * steps. sh(label : ' Run SonarQube scan' , script : { it. contains(" /opt/sonar-scanner/bin/sonar-scanner" ) && it. contains(" -Dsonar.projectKey=key" ) && it. contains(" -Dsonar.projectName=name" ) && it. contains(" -Dsonar.filesize.limit=2 " ) && it . contains( " -Dsonar. exclusions=test/**" ) && it. contains(" -Dsonar.auth.token=my-private-token" ) })
113+ 1 * steps. sh(label : ' Run SonarQube scan' , script : { it. contains(" /opt/sonar-scanner/bin/sonar-scanner" ) && it. contains(" -Dsonar.projectKey=key" ) && it. contains(" -Dsonar.projectName=name" ) && it. contains(" -Dsonar.filesize.limit=2 " ) && it . contains( " -Dsonar. exclusions=test/**" ) && it. contains(" -Dsonar.auth.token=public-token" ) })
114114 }
115115
116116 def " generateReport calls script.sh with correct params and uses correct token" () {
@@ -209,6 +209,38 @@ class SonarQubeServiceSpec extends PipelineSpockTestBase {
209209 service. generateAndStoreSonarQubeToken(" credId" , " namespace" , " secretName" ) == " "
210210 }
211211
212+ def " scan includes sonar.filesize.limit parameter from properties" () {
213+ given :
214+ def steps = GroovyMock (util.PipelineSteps )
215+ steps. tool(' SonarScanner' ) >> ' /opt/sonar-scanner'
216+ steps. withSonarQubeEnv(_, _) >> { String env , Closure block -> block() }
217+ steps. getSONAR_HOST_URL() >> ' https://sonarqube.example.com'
218+ steps. getSONAR_AUTH_TOKEN() >> ' public-token'
219+ steps. sh(_) >> { Map args ->
220+ if (args. returnStatus) {
221+ return 1
222+ }
223+ return null
224+ }
225+ def logger = Mock (org.ods.util.ILogger )
226+ logger. debugMode >> false
227+ def service = new SonarQubeService (steps, logger, " env" )
228+ def options = [
229+ properties : [' sonar.projectKey' : ' key' , ' sonar.projectName' : ' name' , ' sonar.filesize.limit' : ' 5' ],
230+ gitCommit : " abcdef123456" ,
231+ pullRequestInfo : [:],
232+ sonarQubeEdition : " community" ,
233+ exclusions : " " ,
234+ privateToken : " "
235+ ]
236+
237+ when :
238+ service. scan(options)
239+
240+ then :
241+ 1 * steps. sh(label : ' Run SonarQube scan' , script : { it. contains(" -Dsonar.filesize.limit=5" ) })
242+ }
243+
212244 def " getScannerBinary returns tool path if which fails" () {
213245 given :
214246 def steps = GroovyMock (util.PipelineSteps )
0 commit comments