【问题标题】:SonarQube SonarSwift plugin exception when parsing Coverage file generated by Xcode 9解析 Xcode 9 生成的 Coverage 文件时 SonarQube SonarSwift 插件异常
【发布时间】:2018-07-11 07:19:16
【问题描述】:

在尝试将覆盖率报告推送到 SonarQube 服务器时,使用 SonarQube > SonarSwift 插件时出现错误。 我使用 Xcode 命令行生成了报告:

xcodebuild test -enableCodeCoverage YES -scheme iOS_Template -workspace iOS_Template.xcworkspace -destination 'platform=iOS Simulator,name=iPhone X'

当我运行sonar-scanner 扫描代码并上传报告时,我收到以下错误:

 INFO: Parse coverage report
(DerivedData/iOS_Template/Build/ProfileData/DDA1A82C-EB41-4E45-8DCF-428D3E879067/Coverage.profdata)
 ERROR: Can't parse coverage report file
 (DerivedData/iOS_Template/Build/ProfileData/DDA1A82C-EB41-4E45-8DCF-428D3E879067/Coverage.profdata).
 No coverage information will be saved.
 java.lang.IllegalStateException: Can not parse line: HƢ�F
 _T0SS17iOS_TemplateTestsE11isValidatedSbAA10ValidationO10validation_tF�.�������k(_T09Alamofire12TaskDelegateC10urlSessionySo10URLSessionC_So0fB0C4taskySo11InputStreamCSgc011needNewBodyI0t3��6K�2@_T09Alamofire14SessionManagerC5retrySbAA7RequestC383��J��Z8_T09Alamofire7AFErrorO31ResponseValidationFailureReasonO22acceptableContentTypesSaySSGSgf6(��W��N

[...similar set of unknown characters...] 

at com.sonar.swift.plugin.B.A(Unknown Source)
at com.sonar.swift.plugin.B.A(Unknown Source)
at java.util.Optional.ifPresent(Optional.java:159)
at com.sonar.swift.plugin.B.A(Unknown Source)
at com.sonar.swift.plugin.B.A(Unknown Source)
at com.sonar.swift.plugin.B.A(Unknown Source)
at com.sonar.swift.plugin.D.A(Unknown Source)
at com.sonar.swift.plugin.D.execute(Unknown Source)
at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:53)
.....

我检查了 Sonarswift 插件,它似乎不支持 XCode9+(我的 Xcode 版本是 Xcode 9.2)并且想知道它是否导致了异常

【问题讨论】:

    标签: sonarqube code-coverage xcode9 sonarqube-scan


    【解决方案1】:

    事实证明,通过添加一个命令来“生成”一个覆盖率报告文件以供 SonarSwift 加载来解决。 命令是xcrun llvm-cov show -instr-profile

    【讨论】:

      【解决方案2】:

      看看这个SonarQube documentation 页面。您必须先翻译输出,然后再将其发送到 SonarQube:

      xcodebuild -scheme <schemeName> -enableCodeCoverage YES -derivedDataPath . clean build test
      xcrun llvm-cov show -instr-profile=Build/Intermediates/CodeCoverage/Coverage.profdata <path to instrumented executable> > <coverage report file>
      

      同时检查您的 sonar.swift.coverage.reportPath 设置。该文档还包含一个示例项目的链接。

      【讨论】:

      • xcodebuild 生成的输出已经是报告格式(.profdata),而第二个命令仅用于在控制台中显示报告....所以我想知道 SonarSwift 插件是否支持 .profdata 格式或它需要翻译成其他格式(文件没有提到)
      猜你喜欢
      • 2020-11-24
      • 1970-01-01
      • 2018-05-06
      • 2017-09-22
      • 2015-09-13
      • 1970-01-01
      • 2016-04-27
      • 2016-02-28
      • 1970-01-01
      相关资源
      最近更新 更多