SonarQube和Lcov报告无法解析文件路径 [英] SonarQube and Lcov report Could not resolve file paths

查看:270
本文介绍了SonarQube和Lcov报告无法解析文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试为角度应用程序制作SonarQube代码覆盖率报告。我们使用Karma生成代码覆盖率报告并将其导入SonarQube分析器。

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.

SonarQube已经为我们的项目提供了C#覆盖,现在我们也希望添加JavaScript代码覆盖率。

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

Teamcity调用,Karma并创建代码覆盖率并将lcov文件和报告文件放入 src\Planning.Spa\Coverage\report 文件夹。

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文件

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有以下MSBuild参数配置为生成C#代码覆盖率和JavaScript覆盖率。

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

SonarQube MSBuild配置

$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"

在运行SonarQube分析时,我们收到以下错误

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

我们没有找到使用MSBuild runner运行C#和JavaScript的任何示例。也找不到与此相关的任何答案无法解析文件路径

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

我们正努力使其工作过去2周,找不到任何有用的例子或答案。类似的问题没有得到答复这里这里

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

更新更多信息的声纳分析

[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]

更新 SonarJS实际java代码

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

不知怎的,sonarqube忽略了我的文件系统的绝对路径,并将inputFile设置为null

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));

我尝试用Gulp将绝对值修改为相对值并更改 \ / 。但没有任何作用。

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


SonarQube版本 6.5.0.27846

SonarJs版本 3.2.0.5506

SonarJs Version 3.2.0.5506


推荐答案

我的用例有点类似,但对于不同的技术堆栈:Java + React + Gradle。以下是让声纳在sonarqube 5.6 + SonarJS 3.x上显示我的javascript模块的覆盖信息所需要做的事情:

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:

阅读你的研究和片段,我认为您引用的istanbul问题不适用,因为 lcov 文件包含绝对路径。
我的猜测是你必须提供: sonar.sources sonar.tests property。

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.

为了完整起见,我将在下面发布我的gradle配置的整个片段,并将为其下面的每个属性提供解释:

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.suf修复:AFAIR我必须提供它来安抚gradle sonarqube插件,因为我在sonarqube服务器中看到的默认值是相同的。

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 :它也导致处理文件时出错,但我认为这是因为我的本地设置。

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

sonar.sources sonar.tests :I记得我必须提供这些,因为声纳无法在没有它们的情况下找到我的任何来源。我清楚地记得这一点,因为我从来没有为我的java源提供任何此类信息。

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 :需要获取正确的覆盖率信息。

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

sonar.test.inclusions :sonarjs插件需要识别我的测试文件。

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

sonar.genericcoverage.unitTestReportPaths :我还希望在我的仪表板中看到单元测试贡献,所以我有将我的笑话报告处理成通用的声纳格式。

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.

这篇关于SonarQube和Lcov报告无法解析文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆