【问题标题】:Sonarqube scanner cannot resolve relative file path in PHPUnit coverage XML fileSonarqube 扫描仪无法解析 PHPUnit 覆盖 XML 文件中的相对文件路径
【发布时间】:2017-03-26 20:54:22
【问题描述】:

使用以下示例项目执行声纳扫描器时: https://github.com/SonarSource/sonar-examples/tree/b0ebd45081e58c3cb7c660287d5ed7fb9c64bb17/projects/languages/php/php-sonar-runner-unit-tests

我收到以下警告,覆盖数据未发送到 Sonar 主机:

WARN: Could not resolve 1 file paths in phpunit.coverage.xml, first unresolved path: src/Math.php

命令的完整输出:

root@46e4a60694f9:/home/test/sonar-examples-master/projects/languages/php/php-sonar-runner-unit-tests# /home/sonar-scanner-2.8/bin/sonar-scanner
INFO: Scanner configuration file: /home/sonar-scanner-2.8/conf/sonar-scanner.properties
INFO: Project root configuration file: /home/test/sonar-examples-master/projects/languages/php/php-sonar-runner-unit-tests/sonar-project.properties
INFO: SonarQube Scanner 2.8
INFO: Java 1.8.0_111 Oracle Corporation (64-bit)
INFO: Linux 4.4.27-boot2docker amd64
INFO: User cache: /root/.sonar/cache
INFO: Load global repositories
INFO: Load global repositories (done) | time=240ms
INFO: User cache: /root/.sonar/cache
INFO: Load plugins index
INFO: Load plugins index (done) | time=24ms
INFO: SonarQube server 6.1
INFO: Default locale: "en", source code encoding: "UTF-8"
INFO: Process project properties
INFO: Load project repositories
INFO: Load project repositories (done) | time=141ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=55ms
INFO: Load active rules
INFO: Load active rules (done) | time=141ms
WARN: SCM provider autodetection failed. No SCM provider claims to support this project. Please use sonar.scm.provider to define SCM of your project.
INFO: Publish mode
INFO: -------------  Scan PHP :: PHPUnit :: SonarQube Scanner
INFO: Language is forced to php
INFO: Load server rules
INFO: Load server rules (done) | time=76ms
INFO: Base dir: /home/test/sonar-examples-master/projects/languages/php/php-sonar-runner-unit-tests
INFO: Working dir: /home/test/sonar-examples-master/projects/languages/php/php-sonar-runner-unit-tests/.sonar
INFO: Source paths: src
INFO: Test paths: tests
INFO: Source encoding: UTF-8, default locale: en
INFO: Index files
INFO: 3 files indexed
INFO: Quality profile for php: Sonar way
INFO: Sensor Lines Sensor
INFO: Sensor Lines Sensor (done) | time=25ms
INFO: Sensor NoSonar Sensor
INFO: Sensor NoSonar Sensor (done) | time=65ms
INFO: Sensor SCM Sensor
INFO: No SCM system was detected. You can use the 'sonar.scm.provider' property to explicitly specify it.
INFO: Sensor SCM Sensor (done) | time=0ms
INFO: Sensor PHP sensor
INFO: 2 source files to be analyzed
INFO: 2/2 source files have been analyzed
INFO: Analyzing PHPUnit test report: reports/phpunit.xml with org.sonar.plugins.php.phpunit.PhpUnitResultParser@31ddd4a4
INFO: Analyzing PHPUnit unit test coverage report: reports/phpunit.coverage.xml with PHPUnit Unit Test Coverage Result Parser
WARN: Could not resolve 1 file paths in phpunit.coverage.xml, first unresolved path: src/Math.php
INFO: No PHPUnit integration test coverage report provided (see 'sonar.php.coverage.itReportPath' property)
INFO: No PHPUnit overall coverage report provided (see 'sonar.php.coverage.overallReportPath' property)
INFO: Sensor PHP sensor (done) | time=1419ms
INFO: Sensor Analyzer for "php.ini" files
INFO: Sensor Analyzer for "php.ini" files (done) | time=11ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=49ms
INFO: Sensor Code Colorizer Sensor
INFO: Sensor Code Colorizer Sensor (done) | time=1ms
INFO: Sensor CPD Block Indexer
INFO: DefaultCpdBlockIndexer is used for php
INFO: Sensor CPD Block Indexer (done) | time=2ms
INFO: Calculating CPD for 2 files
INFO: CPD calculation finished
INFO: Analysis report generated in 96ms, dir size=27 KB
INFO: Analysis reports compressed in 18ms, zip size=13 KB
INFO: Analysis report uploaded in 115ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://***.elasticbeanstalk.com/dashboard/index/org.sonarqube:php-ut-sq-scanner
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://***.elasticbeanstalk.com/api/ce/task?id=AVhaEXKjVjsdBlz4sGdU
INFO: Task total time: 3.511 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 5.098s
INFO: Final Memory: 42M/149M
INFO: ------------------------------------------------------------------------

当我在 phpunit.coverage.xml 中将路径更改为绝对路径时,它似乎在 Linux 中工作。在 Windows docker 快速启动终端 (MINGW64) 上,使其工作的唯一方法是使用 Windows 样式的绝对路径: C:\Users\username\projects\php-sonar-runner-unit-tests

有没有办法让它与相对路径一起工作?

【问题讨论】:

    标签: sonarqube sonarqube-scan


    【解决方案1】:

    引用自述文件(在您链接的同一页面上):

    • 在“reports/phpunit.coverage.xml”中,将路径“src/Math.php”更改为该文件在您机器上的完整路径。

    您必须使用绝对路径。它不适用于相对路径。

    请注意,这只是一个示例覆盖率报告文件,使用的是 PHPUnit 预先生成的文件(在 README 中也提到过)。通常,您在运行 SonarQube 分析之前自己生成覆盖率报告文件,在这种情况下,它将在您的系统中具有正确的绝对路径。

    【讨论】:

    • 谢谢贾诺斯。我完全错过了关于更改路径的评论。我实际上正在使用自己生成的覆盖文件。但是我在我的 docker 容器中运行 phpunit,所以它会生成 linux 风格的路径。声纳扫描仪但是我从 Windows 主机运行。在这种情况下,我想我别无选择,只能对报告文件进行搜索和替换。
    • 你不能在 docker 容器中运行声纳扫描仪吗?
    • 我能做到。由于它是一个 PHP 项目,我不想在其中安装 Java。今天我尝试了另一种方法:我将 PHP 文件作为卷映射到基于 Java 的声纳扫描器容器中,然后效果很好。
    • 酷,考虑到您的环境,这听起来是一个非常好的解决方案。
    猜你喜欢
    • 2019-03-09
    • 2016-08-22
    • 2010-11-24
    • 2018-05-12
    • 2019-01-23
    • 1970-01-01
    • 1970-01-01
    • 2017-09-18
    • 2013-05-28
    相关资源
    最近更新 更多