SonarQube and Lcov report Could not resolve file paths

Murali Murugesan picture Murali Murugesan · Aug 16, 2018 · Viewed 7.6k times · Source

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

Answer

dubes picture dubes · Aug 21, 2018

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.