我们正在尝试为我们的 Angular 应用程序制作 SonarQube 代码覆盖率报告。我们使用 Karma 生成代码覆盖率报告并将其导入 SonarQube 分析器。
SonarQube 已经为我们的项目提供了 C# 覆盖,现在我们还想添加 JavaScript 代码覆盖。
Teamcity 调用 Karma 并创建代码覆盖率并将 lcov 文件和报告文件放入src\Planning.Spa\Coverage\report
文件夹中。
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 覆盖率。
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 分析时,我们收到以下错误
[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 的示例。也找不到与此相关的任何答案Could not resolve file paths
我们正在努力使其在过去 2 周内正常工作,但找不到任何有用的示例或答案。类似的问题在这里和这里都没有得到解答
使用更多信息更新声纳分析
[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 代码
不知何故,sonarqube 忽略了我从其文件系统中的绝对路径并将 inputFile 设置为 null
InputFile inputFile = context.fileSystem().inputFile(context.fileSystem().predicates().hasPath(filePath));
我尝试使用 Gulp 将 absolute 修改为 relative 并\
使用/
. 但没有任何效果。
SonarQube 版本6.5.0.27846
SonarJs 版本3.2.0.5506