Skip to content

Commit

Permalink
SQ-10: test with SonarScanner 6.1.0.4477
Browse files Browse the repository at this point in the history
SonarScanner 6.x is a major refactoring of SonarSource. The parameters, default values and especially the output in the LOG file has changed. Because our CI/CD test evaluates the texts in the LOG file, the Pyhton scripts had to be adapted accordingly.

There was a braking change in scanner parameter sonar.host.url:
- For SonarScanner CLI from v6.0, .NET from v7.0, and NPM from v4.0:  https://sonarcloud.io
- For older versions of the SonarScanner CLI, .NET, and NPM:  http://localhost:9000

got the message below:

```
06:50:43.753 INFO  Scanner configuration file: /home/runner/work/sonar-cxx/sonar-cxx/test/sonar-scanner-6.1.0.4477/conf/sonar-scanner.properties
06:50:43.756 INFO  Project root configuration file: /home/runner/work/sonar-cxx/sonar-cxx/integration-tests/testdata/boosttest_project/sonar-project.properties
06:50:43.769 INFO  SonarScanner CLI 6.1.0.4477
06:50:43.772 INFO  Java 17.0.12 Eclipse Adoptium (64-bit)
06:50:43.772 INFO  Linux 6.5.0-1025-azure amd64
06:50:43.779 DEBUG Scanner max available memory: 3 GB
06:50:43.797 DEBUG uname -m returned 'x86_64'
06:50:43.798 DEBUG Create: /home/runner/.sonar/cache
06:50:43.799 INFO  User cache: /home/runner/.sonar/cache
06:50:43.799 DEBUG Create: /home/runner/.sonar/cache/_tmp
06:50:44.107 DEBUG Loaded [413] system trusted certificates
06:50:44.253 INFO  JRE provisioning: os[linux], arch[x86_64]
06:50:44.279 DEBUG --> GET https://api.sonarcloud.io/analysis/jres?os=linux&arch=x86_64
06:50:45.445 DEBUG <-- 401 https://api.sonarcloud.io/analysis/jres?os=linux&arch=x86_64 (1165ms, 83-byte body)
06:50:45.445 INFO  EXECUTION FAILURE
06:50:45.446 INFO  Total time: 1.694s
06:50:45.447 ERROR Error during SonarScanner CLI execution
java.lang.IllegalStateException: Error status returned by url [https://api.sonarcloud.io/analysis/jres?os=linux&arch=x86_64]: 401
	at org.sonarsource.scanner.lib.internal.http.ServerConnection.callUrl(ServerConnection.java:182)
	at org.sonarsource.scanner.lib.internal.http.ServerConnection.callApi(ServerConnection.java:145)
	at org.sonarsource.scanner.lib.internal.http.ServerConnection.callRestApi(ServerConnection.java:123)
	at org.sonarsource.scanner.lib.internal.JavaRunnerFactory.getJreMetadata(JavaRunnerFactory.java:159)
	at org.sonarsource.scanner.lib.internal.JavaRunnerFactory.getJreFromServer(JavaRunnerFactory.java:138)
	at org.sonarsource.scanner.lib.internal.JavaRunnerFactory.createRunner(JavaRunnerFactory.java:85)
	at org.sonarsource.scanner.lib.internal.ScannerEngineLauncherFactory.createLauncher(ScannerEngineLauncherFactory.java:53)
	at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.bootstrap(ScannerEngineBootstrapper.java:118)
	at org.sonarsource.scanner.cli.Main.analyze(Main.java:75)
	at org.sonarsource.scanner.cli.Main.main(Main.java:63)
```
- new: WARN The properties 'sonar.login' and 'sonar.password' are deprecated and will be removed in the future. Please pass a token with the 'sonar.token' property instead.
- fix tests: colon removed after ERROR, INFO, WARN
- get_url_from_log: INFO is now without colon
- fix warnings in integration tests: scanner using different formats/texts
  • Loading branch information
guwirth committed Aug 20, 2024
1 parent 776c530 commit 388e176
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 46 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cxx-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ jobs:
java: [ '17' ]
distribution: [ 'temurin' ]
sonarqube: [ '10.6.0.92116' ]
sonarscanner: [ '5.0.1.3006' ]
sonarscanner: [ '6.1.0.4477' ]

runs-on: ${{ matrix.os }}
needs: [build-linux, verify-rules]
Expand Down Expand Up @@ -450,7 +450,7 @@ jobs:
java: [ '17' ]
distribution: [ 'temurin' ]
sonarqube: [ '10.6.0.92116' ]
sonarscanner: [ '5.0.1.3006' ]
sonarscanner: [ '6.1.0.4477' ]

runs-on: ${{ matrix.os }}
# needs build-linux because of JAR artifacts
Expand Down
7 changes: 4 additions & 3 deletions integration-tests/features/boosttest.feature
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Feature: Providing test execution measures
And the analysis in server has completed
And the analysis log contains no error/warning messages except those matching:
"""
.*WARN.*Unable to get a valid mac address, will use a dummy address
.*WARN.*The properties 'sonar\.login' and 'sonar\.password' are deprecated and will be removed in the future.*
"""
And the following metrics have following values:
| metric | value |
Expand All @@ -57,7 +57,7 @@ Feature: Providing test execution measures
And the analysis in server has completed
And the analysis log contains no error/warning messages except those matching:
"""
.*WARN.*Unable to get a valid mac address, will use a dummy address
.*WARN.*The properties 'sonar\.login' and 'sonar\.password' are deprecated and will be removed in the future.*
"""
And the following metrics have following values:
| metric | value |
Expand All @@ -78,8 +78,9 @@ Feature: Providing test execution measures
And the analysis in server has completed
And the analysis log contains no error/warning messages except those matching:
"""
.*WARN.*Unable to get a valid mac address, will use a dummy address
.*WARN.*The properties 'sonar\.login' and 'sonar\.password' are deprecated and will be removed in the future.*
.*WARN.*cannot find the sources for '.*'
.*WARN.*Preprocessor:.*
"""
And the following metrics have following values:
| metric | value |
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/features/clangtidy.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Feature: Importing Clang-Tidy reports
And the server log (if locatable) contains no error/warning messages
And the analysis log contains no error/warning messages except those matching:
"""
.*WARN.*Unable to get a valid mac address, will use a dummy address
.*WARN.*The properties 'sonar\.login' and 'sonar\.password' are deprecated and will be removed in the future.*
"""
And the number of violations fed is <violations>
Examples:
Expand Down
10 changes: 3 additions & 7 deletions integration-tests/features/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,11 @@ def analyse_log(logpath, toignore=None):
return badlines, errors, warnings

def get_url_from_log(lines):
url = ''
for line in lines:
if 'INFO: More about the report processing at' in line:
url = line.split('INFO: More about the report processing at')[1].strip()

if 'INFO - More about the report processing at' in line:
url = line.split('INFO - More about the report processing at')[1].strip()
if 'More about the report processing at' in line:
return line.split('at ')[1].strip()

return url
return ''

def analyse_log_lines(lines, toignore=None):
badlines = []
Expand Down
10 changes: 6 additions & 4 deletions integration-tests/features/coverage.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ Feature: Importing coverage data
And the analysis in server has completed
And the analysis log contains no error/warning messages except those matching:
"""
.*WARN.*Unable to get a valid mac address, will use a dummy address
.*WARN.*The properties 'sonar\.login' and 'sonar\.password' are deprecated and will be removed in the future.*
.*WARN.*cannot find the sources for '#include <iostream>'
.*WARN.*Preprocessor:.*
"""
And the following metrics have following values:
| metric | value |
Expand All @@ -29,7 +30,7 @@ Feature: Importing coverage data
And the analysis in server has completed
And the analysis log contains no error/warning messages except those matching:
"""
.*WARN.*Unable to get a valid mac address, will use a dummy address
.*WARN.*The properties 'sonar\.login' and 'sonar\.password' are deprecated and will be removed in the future.*
"""
And the following metrics have following values:
| metric | value |
Expand All @@ -51,9 +52,10 @@ Feature: Importing coverage data
And the analysis in server has completed
And the analysis log contains no error/warning messages except those matching:
"""
.*WARN.*Unable to get a valid mac address, will use a dummy address
.*WARN.*The properties 'sonar\.login' and 'sonar\.password' are deprecated and will be removed in the future.*
.*WARN.*cannot find the sources for '#include <iostream>'
.*WARN.*Cannot find a report for '.*'
.*WARN.*Property 'sonar.cxx.cobertura.reportPaths': cannot find any files.*
.*WARN.*Preprocessor:.*
"""
And the following metrics have following values:
| metric | value |
Expand Down
11 changes: 6 additions & 5 deletions integration-tests/features/cppcheck.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Feature: Importing Cppcheck reports
And the server log (if locatable) contains no error/warning messages
But the analysis log contains a line matching
"""
WARN: The 'Cppcheck V2' report is empty.*skipping
WARN The 'Cppcheck V2' report is empty.*skipping
"""
And the number of violations fed is 0

Expand All @@ -35,7 +35,7 @@ Feature: Importing Cppcheck reports
And the server log (if locatable) contains no error/warning messages
But the analysis log contains a line matching
"""
WARN: Cannot find the file.*skipping
WARN Cannot find the file 'component1\.cc'.*skipping
"""
And the number of violations fed is 0

Expand Down Expand Up @@ -70,7 +70,7 @@ Feature: Importing Cppcheck reports
And the server log (if locatable) contains no error/warning messages
But the analysis log contains a line matching
"""
WARN: The 'Cppcheck V2' report is invalid.*skipping
WARN The 'Cppcheck V2' report is invalid.*skipping
"""
And the number of violations fed is <violations>
Examples:
Expand All @@ -93,7 +93,7 @@ Feature: Importing Cppcheck reports
And the server log (if locatable) contains no error/warning messages
And the analysis log contains no error/warning messages except those matching:
"""
.*WARN.*Unable to get a valid mac address, will use a dummy address
.*WARN.*The properties 'sonar\.login' and 'sonar\.password' are deprecated and will be removed in the future.*
"""
And the number of violations fed is <violations>
Examples:
Expand All @@ -116,7 +116,8 @@ Feature: Importing Cppcheck reports
And the server log (if locatable) contains no error/warning messages
And the analysis log contains no error/warning messages except those matching:
"""
.*WARN.*Unable to get a valid mac address, will use a dummy address
.*WARN.*The properties 'sonar\.login' and 'sonar\.password' are deprecated and will be removed in the future.*
.*WARN.*Preprocessor:.*
"""
And the number of violations fed is <violations>
Examples:
Expand Down
15 changes: 9 additions & 6 deletions integration-tests/features/googletest.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ Feature: Providing test execution measures
And the analysis in server has completed
And the analysis log contains no error/warning messages except those matching:
"""
.*WARN.*Unable to get a valid mac address, will use a dummy address
.*WARN.*The properties 'sonar\.login' and 'sonar\.password' are deprecated and will be removed in the future.*
.*WARN.*cannot find the sources for '#include <gtest/gtest\.h>'
.*WARN.*cannot find the sources for '#include <unistd\.h>'
.*WARN.*Preprocessor:.*
"""
And the following metrics have following values:
| metric | value |
Expand All @@ -55,7 +56,7 @@ Feature: Providing test execution measures
Then the analysis breaks
And the analysis log contains a line matching:
"""
ERROR: Invalid xUnit report.*stop analysis
ERROR Invalid xUnit report.*stop analysis
"""


Expand All @@ -70,9 +71,10 @@ Feature: Providing test execution measures
And the analysis in server has completed
And the analysis log contains no error/warning messages except those matching:
"""
.*WARN.*Unable to get a valid mac address, will use a dummy address
.*WARN.*The properties 'sonar\.login' and 'sonar\.password' are deprecated and will be removed in the future.*
.*WARN.*cannot find the sources for '#include <gtest/gtest\.h>'
.*WARN.*cannot find the sources for '#include <unistd\.h>'
.*WARN.*Preprocessor:.*
"""
And the following metrics have following values:
| metric | value |
Expand All @@ -95,11 +97,12 @@ Feature: Providing test execution measures
And the analysis in server has completed
And the analysis log contains no error/warning messages except those matching:
"""
.*WARN.*Unable to get a valid mac address, will use a dummy address
.*WARN.*The properties 'sonar\.login' and 'sonar\.password' are deprecated and will be removed in the future.*
.*WARN.*cannot find the sources for '#include <gtest/gtest\.h>'
.*WARN.*cannot find the sources for '#include <unistd\.h>'
.*WARN.*The report.*seems to be empty, ignoring\.
.*WARN.*Cannot find a report for '.*'
.*WARN .*The xUnit report.*seems to be empty, ignoring\.
.*WARN.*Property 'sonar\.cxx\.xunit\.reportPaths': cannot find any files.*
.*WARN.*Preprocessor:.*
"""
And the following metrics have following values:
| metric | value |
Expand Down
3 changes: 2 additions & 1 deletion integration-tests/features/json-db.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Feature: JSON Compilation Database support
And the analysis in server has completed
And the analysis log contains no error/warning messages except those matching:
"""
.*WARN.*Unable to get a valid mac address, will use a dummy address
.*WARN.*The properties 'sonar\.login' and 'sonar\.password' are deprecated and will be removed in the future.*
.*ERROR.*preprocessor: /another/include/dir.*
"""
And the following metrics have following values:
| metric | value |
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/features/regex.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Feature: Regex
And the analysis in server has completed
And the analysis log contains no error/warning messages except those matching:
"""
.*WARN.*Unable to get a valid mac address, will use a dummy address
.*WARN.*The properties 'sonar\.login' and 'sonar\.password' are deprecated and will be removed in the future.*
"""
And the following metrics have following values:
| metric | value |
Expand All @@ -28,7 +28,7 @@ Feature: Regex
And the analysis in server has completed
And the analysis log contains no error/warning messages except those matching:
"""
.*WARN.*Unable to get a valid mac address, will use a dummy address
.*WARN.*The properties 'sonar\.login' and 'sonar\.password' are deprecated and will be removed in the future.*
"""
And the following metrics have following values:
| metric | value |
Expand All @@ -45,7 +45,7 @@ Feature: Regex
And the analysis in server has completed
And the analysis log contains no error/warning messages except those matching:
"""
.*WARN.*Unable to get a valid mac address, will use a dummy address
.*WARN.*The properties 'sonar\.login' and 'sonar\.password' are deprecated and will be removed in the future.*
"""
And the following metrics have following values:
| metric | value |
Expand Down
24 changes: 15 additions & 9 deletions integration-tests/features/smoketest.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ Feature: Smoketests
And the analysis in server has completed
And the analysis log contains no error/warning messages except those matching:
"""
.*WARN.*Unable to get a valid mac address, will use a dummy address
.*WARN.*The properties 'sonar\.login' and 'sonar\.password' are deprecated and will be removed in the future.*
.*WARN.*cannot find the sources for '#include <gtest/gtest\.h>'
.*WARN.*cannot find the sources for '#include <iostream>'
.*WARN.*Cannot find the file '.*component_XXX.cc', skipping
.*WARN.*Cannot find the file '.*component_XXX\.cc'.*skipping
.*WARN.*Cannot find a report for '.*'
.*WARN.*Preprocessor:.*
"""
And the following metrics have following values:
| metric | value |
Expand Down Expand Up @@ -81,11 +82,12 @@ Feature: Smoketests
And the analysis in server has completed
And the analysis log contains no error/warning messages except those matching:
"""
.*WARN.*Unable to get a valid mac address, will use a dummy address
.*WARN.*The properties 'sonar\.login' and 'sonar\.password' are deprecated and will be removed in the future.*
.*WARN.*cannot find the sources for '#include <gtest/gtest\.h>'
.*WARN.*cannot find the sources for '#include <iostream>'
.*WARN.*Cannot find the file '.*component_XXX.cc', skipping
.*WARN.*Cannot find the file '.*component_XXX\.cc'.*skipping
.*WARN.*Cannot find a report for '.*'
.*WARN.*Preprocessor:.*
"""
And the following metrics have following values:
| metric | value |
Expand Down Expand Up @@ -145,11 +147,12 @@ Feature: Smoketests
And the analysis in server has completed
And the analysis log contains no error/warning messages except those matching:
"""
.*WARN.*Unable to get a valid mac address, will use a dummy address
.*WARN.*The properties 'sonar\.login' and 'sonar\.password' are deprecated and will be removed in the future.*
.*WARN.*cannot find the sources for '#include <gtest/gtest\.h>'
.*WARN.*cannot find the sources for '#include <iostream>'
.*WARN.*Cannot find the file '.*component_XXX.cc', skipping
.*WARN.*Cannot find the file '.*component_XXX\.cc'.*skipping
.*WARN.*Cannot find a report for '.*'
.*WARN.*Preprocessor:.*
"""
And the following metrics have following values:
| metric | value |
Expand Down Expand Up @@ -218,12 +221,15 @@ Feature: Smoketests
And the analysis in server has completed
And the analysis log contains no error/warning messages except those matching:
"""
.*WARN.*Unable to get a valid mac address, will use a dummy address
.*WARN.*to create a dependency with 'PathHandling/PathHandle.h'
.*WARN.*The properties 'sonar\.login' and 'sonar\.password' are deprecated and will be removed in the future.*
.*WARN.*to create a dependency with 'PathHandling/PathHandle\.h'
.*WARN.*cannot find the sources for '#include <unistd\.h>'
.*WARN.*Cannot find the file '.*gtestmock.1.7.2.*', ignoring coverage measures
.*WARN.*Cannot find the file '.*gtestmock\.1\.7\.2.*', ignoring coverage measures
.*WARN.*Cannot find a report for '.*'
.*WARN.*cannot find the sources for '#include.*
.*WARN.*Preprocessor:.*
.*WARN.*Using absolute path pattern is deprecated.*
.*WARN.*Cannot sanitize file path.*
"""
And the following metrics have following values:
| metric | value |
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/features/steps/test_execution_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def step_impl(context):

@then('the analysis log contains a line matching')
def step_impl(context):
assert _contains_line_matching(context.log, context.text)
assert _contains_line_matching(context.log, context.text), f"The analysis log does not contain a line matching '{context.text}'"


@when('I run "{command}"')
Expand All @@ -241,13 +241,13 @@ def step_impl(context, command):

@when('I run sonar-scanner with "{params}"')
def step_impl(context, params):
_run_command(context, 'sonar-scanner -Dsonar.login=' + SONAR_LOGIN + ' -Dsonar.password=' + SONAR_PASSWORD + ' ' + params)
_run_command(context, 'sonar-scanner -Dsonar.host.url=http://localhost:9000 -Dsonar.login=' + SONAR_LOGIN + ' -Dsonar.password=' + SONAR_PASSWORD + ' ' + params)


@when('I run sonar-scanner with following options')
def step_impl(context):
arguments = [line for line in context.text.split('\n') if line != '']
command = 'sonar-scanner -Dsonar.login=' + SONAR_LOGIN + ' -Dsonar.password=' + SONAR_PASSWORD + ' ' + ' '.join(arguments)
command = 'sonar-scanner -Dsonar.host.url=http://localhost:9000 -Dsonar.login=' + SONAR_LOGIN + ' -Dsonar.password=' + SONAR_PASSWORD + ' ' + ' '.join(arguments)
_run_command(context, command)


Expand Down Expand Up @@ -344,7 +344,7 @@ def _run_command(context, command):
print('cmd: ' + command, flush=True)
with open(context.log, 'r', encoding='utf8') as log:
for line in log:
if 'WARN:' in line or 'ERROR:' in line:
if 'WARN' in line or 'ERROR' in line:
print(line, flush=True)

context.rc = proc.returncode
2 changes: 1 addition & 1 deletion integration-tests/features/webapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def web_api_get(url, log=False):
url = SONAR_URL + url
response = None
if log:
print(f"\n'{url}' response:", flush=True)
print(f"\n'{url}' response:", flush=True)
response = requests.get(url, timeout=60, auth=HTTPBasicAuth(SONAR_LOGIN, SONAR_PASSWORD))
response.raise_for_status()
if not response.text:
Expand Down

0 comments on commit 388e176

Please sign in to comment.