SonarQube and Lcov report Could not resolve file paths
Asked Answered
N

3

10

We are trying to make a SonarQube code coverage report for our angular application. We have used Karma to generate a code coverage report and import it into SonarQube analyzer.

The SonarQube already has C# coverage for our project, now we want to add JavaScript code coverage as well.

Teamcity calls, Karma and it creates a code coverage and put the lcov file and report files into src\Planning.Spa\Coverage\report folder.

LCOV File

TN:
SF:E:/a03/work/bb52cb33e083fc9/src/Planning.Spa/Offer/app/app.component.js
FN:5,(anonymous_1)
FN:6,AppComponent
FN:8,(anonymous_3)
FN:9,(anonymous_4)

Teamcity has the following MSBuild parameters configured to generate a C# code coverage and JavaScript coverage.

SonarQube MSBuild Configuration

$sonar=%system.MSBUILD_SONARQUBE_RUNNER%\MSBuild.SonarQube.Runner.exe 
begin /k:"com.test:Test" /n:"MyProject" /v:"%build.number%" 
/d:sonar.cs.dotcover.reportsPaths="$coverageReport" 
/d:sonar.cs.nunit.reportsPaths="$testResults" 
/d:sonar.javascript.lcov.reportPaths="coverage\report\lcov.info"

While running SonarQube analysis we get the following error

[14:35:56][Step 13/13] 14:35:56.243 WARN: Could not resolve 114 file paths in
 [E:\a03\work\bb52cb33e083fc9\src\Planning.Spa\coverage\report\lcov.info], 
first unresolved path: E:/a03/work/bb52cb33e083fc9/src/Planning.Spa/Offer/app/app.component.js

We don't find any example for running both C# and JavaScript using MSBuild runner. Also could not find any answer related to this Could not resolve file paths

We are trying to make it work for last 2 weeks and could not find any useful example or answer. Similar questions were unanswered here and here

Update Sonar Analysis with more info

[14:35:43][Step 13/13] 14:35:43.751 INFO: Base dir: E:\a03\work\bb52cb33e083fc9\src\Planning.Spa
[14:35:43][Step 13/13] 14:35:43.751 INFO: Working dir: E:\a03\work\bb52cb33e083fc9\.sonarqube\out\.sonar\com.Planning_com.Planning_6CC487F0-8283-4351-9B65-F1698B1B804E
[14:35:43][Step 13/13] 14:35:43.755 INFO: Source paths: Offer/App/app.component.js, Offer/App/app.component.js.map, Offer/App/Common/order-by.pipe.js
[14:35:43][Step 13/13] 14:35:43.755 INFO: Source encoding: UTF-8, default locale: en_US
[14:35:43][Step 13/13] 14:35:43.755 INFO: Index files
[14:35:43][Step 13/13] 14:35:43.756 INFO: Excluded sources: 
[14:35:43][Step 13/13] 14:35:43.756 INFO:   Offer/Scripts/**
[14:35:43][Step 13/13] 14:35:43.756 INFO:   Offer/libs/**
[14:35:43][Step 13/13] 14:35:43.757 INFO: Analyzer working directory contains 5 .pb file(s)

[14:35:43][Step 13/13] 14:35:43.898 DEBUG: 'Offer/App/app.component.js' indexed with language 'js'
[14:35:43][Step 13/13] 14:35:43.898 DEBUG: 'Offer/App/app.component.js.map' indexed with language 'null'
[14:35:43][Step 13/13] 14:35:43.953 INFO: 1010 files indexed
[14:35:43][Step 13/13] 14:35:43.953 INFO: 111 files ignored because of inclusion/exclusion patterns
[14:35:43][Step 13/13] 14:35:43.953 INFO: Quality profile for cs: Sonar C# Planning SIM
[14:35:43][Step 13/13] 14:35:43.953 INFO: Quality profile for js: Sonar way


[14:35:43][Step 13/13] 14:35:43.979 DEBUG: 'JavaSquidSensor' skipped because there is no related file in current project
[14:35:43][Step 13/13] 14:35:43.980 DEBUG: Sensors : CSS Analyzer Sensor -> Embedded CSS Analyzer Sensor -> JavaScript Squid Sensor -> C# -> SonarJavaXmlFileSensor -> Web -> XML Sensor
[14:35:43][Step 13/13] 14:35:43.980 INFO: Sensor CSS Analyzer Sensor [css]

[14:35:51][Step 13/13] 14:35:51.314 INFO: Sensor JavaScript Squid Sensor [javascript]
[14:35:51][Step 13/13] 14:35:51.316 INFO: 57/57 source files have been analyzed
[14:35:51][Step 13/13] 14:35:51.344 INFO: 153 source files to be analyzed

[14:35:55][Step 13/13] 14:35:55.145 DEBUG: 'Offer/App/app.component.js' generated metadata  with charset 'UTF-8'

[14:35:56][Step 13/13] 14:35:56.243 WARN: Could not resolve 114 file paths in [E:\a03\work\bb52cb33e083fc9\src\Planning.Spa\coverage\report\lcov.info], first unresolved path: E:/a03/work/bb52cb33e083fc9/src/Planning.Spa/Offer/app/app.component.js
[14:35:56][Step 13/13] 14:35:56.237 INFO: Test Coverage Sensor is started
[14:35:56][Step 13/13] 14:35:56.239 INFO: Analysing [E:\a03\work\bb52cb33e083fc9\src\Planning.Spa\coverage\report\lcov.info]
[14:35:56][Step 13/13] 14:35:56.243 INFO: Sensor JavaScript Squid Sensor [javascript] (done) | time=4929ms
[14:35:56][Step 13/13] 14:35:56.243 INFO: Sensor C# [csharp]

Update SonarJS actual java code

https://github.com/SonarSource/SonarJS/blob/3.2.0.5506/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/lcov/LCOVParser.java#L146

Somehow sonarqube ignores my absolute path from its file system and sets inputFile as null

InputFile inputFile = context.fileSystem().inputFile(context.fileSystem().predicates().hasPath(filePath));

I have tried with Gulp to modify absolute to relative and changed \ with /. But nothing works.

SonarQube Version 6.5.0.27846

SonarJs Version 3.2.0.5506

Newmown answered 16/8, 2018 at 13:57 Comment(7)
which versions of sonarqube and sonarJS plugin are you using?Byword
@Byword it is SonarQube 6.5Newmown
SonarJS is 4.x? or still using 3?Byword
@dubes, Sorry I am not having access to the sonarqube server to check it.Newmown
I think your sonarjs plugin is 3.x based on the fact that you are using sonar.javascript.lcov.reportPath and the documentation: docs.sonarqube.org/display/PLUG/… says that it was removed from 4.0. I have provided my answer with those assumptionsByword
@dubes, I have updated my question as earlier i got a warning Since SonarQube 6.2 property 'sonar.javascript.lcov.reportPath' is deprecated. Use 'sonar.javascript.lcov.reportPaths' instead.Newmown
Let us continue this discussion in chat.Newmown
B
4

My usecase was kind of similar, but for a different tech stack: Java + React+ Gradle. Here is what I had to do to get sonar to display the coverage information for my javascript module on sonarqube 5.6 + SonarJS 3.x:

Reading your research and snippets, I think the istanbul issue you are referencing does not apply, as the lcov file contains the absolute path. My guess is that you have to provide: sonar.sources and sonar.tests property.

For the sake of completeness I am posting the entire snippet of my gradle configuration below and will provide explanations for each property below it:

sonarqube {
    properties {
        property "sonar.javascript.file.suffixes", ".js,.jsx"
        property "sonar.sourceEncoding", "UTF-8"
        property 'sonar.sources', 'public, src'
        property 'sonar.tests', 'src'
        property 'sonar.coverage.exclusions', '**/__tests__/**'
        property 'sonar.test.inclusions', '**/__tests__/**'
        property 'sonar.javascript.lcov.reportPath', 'coverage/lcov.info'
        property 'sonar.genericcoverage.unitTestReportPaths', 'testResults/sonar-report.xml'
    }
}

sonar.javascript.file.suffixes : AFAIR I had to provide it to appease the gradle sonarqube plugin, as the defaults I see in sonarqube server are the same.

sonar.sourceEncoding : it was also causing errors in processing the files, but I think it was because of my local settings.

sonar.sources and sonar.tests : I remember I had to provide these as sonar was not able to find any of my sources to process without them. I remember this distinctly as I never had to provide any such information for my java sources.

sonar.coverage.exclusions : Was required to get the correct coverage information.

sonar.test.inclusions : Was required for the sonarjs plugin to identify my test files.

sonar.genericcoverage.unitTestReportPaths : I also wanted to see the unit tests contribution in my dashboard, so I had to process my jest reports into a generic sonar format.

Byword answered 21/8, 2018 at 8:16 Comment(6)
I have not specified sonar.test.inclusions as the spec.js files are in same level/folder where we have .js files. Could you please show me how lcov path looks like in your case? I am not sure how to create a .xml unit test report from Karma. I will check that too.Newmown
Everything works now and it seems to be a problem in our server. I have no idea, what they have updated. But same configuration works fine. You have helped a lot to understand how it works :) Worth to offer a bounty to you!Newmown
Thank you! Glad to have been of help!Byword
What plugin you have used to generate sonar-report.xml file? I also need to update the counts in dashboard. I am using github.com/karma-runner/karma-coverage but unfortunately it does not have xml report to send it to SonarQubeNewmown
I used npmjs.com/package/jest-sonar-reporter, this looks promising for karma npmjs.com/package/karma-sonarqube-reporterByword
I am trying with github.com/karma-runner/karma-junit-reporter as the sonar qube version is fork of this. Not sure what additions it has. Thanks!Newmown
P
0

For me the issue was caused by running sonar-scanner inside a symlinked directory. The file paths were definitely all valid. I had to cd into the non-symlinked directory to fix the error.

Pa answered 17/11, 2022 at 7:37 Comment(0)
D
0

In my scenario, the generated lcov.info file used relative paths for coverage instead of absolute paths (I was using nyc with the --reporter option) causing SonarQube to be unable to resolve it. Following some research, I discovered the "nyc-report-lcov-absolute" --reporter option, which facilitates the generation of the file with absolute paths. https://www.npmjs.com/package/nyc-report-lcov-absolute

In my case, the usage is as simple as "nyc --reporter=nyc-report-lcov-absolute"

Deniable answered 16/1 at 13:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.