Sonarqube扫描程序无法解析PHPUnit coverage XML文件中的相对文件路径

时间:2016-11-12 21:56:56

标签: sonarqube sonarqube-scan

使用以下示例项目执行声纳扫描仪时: 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 \用户名\项目\ PHP-声纳的亚军单元测试

有没有办法让它适用于相对路径?

1 个答案:

答案 0 :(得分:2)

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

  
      
  • 在" reports / phpunit.coverage.xml"中,更改路径" src / Math.php"到你机器上这个文件的完整路径。
  •   

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

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