问题描述
我们正在尝试为我们的 Angular 应用程序制作 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 文件和报告文件放入 srcPlanning.SpaCoverageeport
文件夹.
Teamcity calls, Karma and it creates a code coverage and put the lcov file and report files into srcPlanning.SpaCoverageeport
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
eportlcov.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:a03workb52cb33e083fc9srcPlanning.Spacoverage
eportlcov.info],
first unresolved path: E:/a03/work/bb52cb33e083fc9/src/Planning.Spa/Offer/app/app.component.js
我们没有找到任何使用 MSBuild 运行程序同时运行 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 周内正常工作,但找不到任何有用的示例或答案.这里和没有回答类似的问题href="https://stackoverflow.com/questions/39853126/sonar-runner-info-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
更新声纳分析提供更多信息
[14:35:43][Step 13/13] 14:35:43.751 INFO: Base dir: E:a03workb52cb33e083fc9srcPlanning.Spa
[14:35:43][Step 13/13] 14:35:43.751 INFO: Working dir: E:a03workb52cb33e083fc9.sonarqubeout.sonarcom.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:a03workb52cb33e083fc9srcPlanning.Spacoverage
eportlcov.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:a03workb52cb33e083fc9srcPlanning.Spacoverage
eportlcov.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
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:
阅读您的研究和摘要,我认为您引用的伊斯坦布尔问题不适用,因为 lcov
文件包含绝对路径.我的猜测是您必须提供: sonar.sources
和 sonar.tests
属性.
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.suffixes
: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
:我记得我必须提供这些,因为没有它们,sonar 无法找到要处理的任何源.我清楚地记得这一点,因为我从来不需要为我的 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 报告无法解析文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!