如何解决此重复资源错误?

时间:2014-02-07 13:30:53

标签: sonarqube sonar-runner

我有一个用coffeescript编写的nodejs项目,我使用声纳javascript插件进行分析。

我将所有资源都放在名为“src”的文件夹中,并在名为“test”的文件夹中进行测试。

测试文件与源文件具有相同的名称。

当我运行测试时

  • 将coffescript编译为javascript并复制到“lib / src”和“lib / test”
  • 然后检测javascript的覆盖范围并复制到“lib-cov / lib / src”和“lib-cov / lib / test”(实际上只有src被检测,测试只是再次复制以维护相对路径)

在对已检测代码运行测试后,我得到2个报告“reports / lcov.info”和“reports / TEST-all.xml”

这适用于我的一个项目,但在另一个项目中,我从2个源文件中得到重复的资源错误(我无法弄清楚它们的特殊之处)

“sonar-project.properties”如下所示:

sonar.projectKey=ddm:ddm-server
sonar.projectName=D4A Dependency Manager Server
sonar.projectVersion=1.0

sonar.sources=lib/src
sonar.exclusions=index.js
sonar.language=js

sonar.javascript.jstestdriver.reportsPath=reports
sonar.javascript.lcov.reportPath=reports/lcov.info  

“lib / src”目录中的文件是(没有子目录):

  • Archive.js
  • Get.js
  • index.js
  • Library.js
  • Post.js
  • Registry.js
  • Version.js

只有“Archive.js”和“Post.js”会导致问题

并导致以下错误:

ERROR: Caused by: Duplicate source for resource: org.sonar.api.resources.File@16d828ef[key=Archive.js,dir=<null>,filename=Archive.js,language=JavaScript]

如果我排除“Archive.js”和“Post.js”,一切正常 - 这些名称有什么特别之处吗?

仅供参考:Jenkins的声纳跑步者的完整输出是:

[DDM_SERVER_CONTINUOUS_BUILD_AND_TEST] $ /home/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/Sonar_Runner_2.3/sonar-runner-2.3/bin/sonar-runner -Dsonar.jdbc.driver=com.mysql.jdbc.Driver -Dsonar.jdbc.url=jdbc:mysql://sonar.lgcoreapps.com:3306/sonar?autoReconnect=true&useUnicode=true&characterEncoding=utf8 ******** ******** -Dsonar.host.url=http://sonar.lgcoreapps.com ******** ******** -Dsonar.projectBaseDir=<http://jenkins.lgcoreapps.com/job/DDM_SERVER_CONTINUOUS_BUILD_AND_TEST/ws/> -Dsonar.exclusions=index.js
SonarQube Runner 2.3
Java 1.7.0_09-icedtea Oracle Corporation (64-bit)
Linux 2.6.32-358.el6.x86_64 amd64
INFO: Runner configuration file: /home/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/Sonar_Runner_2.3/sonar-runner-2.3/conf/sonar-runner.properties
INFO: Project configuration file: <http://jenkins.lgcoreapps.com/job/DDM_SERVER_CONTINUOUS_BUILD_AND_TEST/ws/sonar-project.properties>
INFO: Default locale: "en_US", source code encoding: "US-ASCII" (analysis is platform dependent)
INFO: Work directory: <http://jenkins.lgcoreapps.com/job/DDM_SERVER_CONTINUOUS_BUILD_AND_TEST/ws/.sonar>
INFO: SonarQube Server 3.5.1
13:46:58.260 INFO  - Load batch settings
13:46:58.349 INFO  - User cache: /home/jenkins/.sonar/cache
13:46:58.351 INFO  - Install plugins
13:46:59.109 INFO  - -------------  Executing Project Scan
13:46:59.750 INFO  - Install JDBC driver
13:46:59.754 INFO  - Apply project exclusions
13:46:59.758 INFO  - Create JDBC datasource for jdbc:mysql://sonar.lgcoreapps.com:3306/sonar?autoReconnect=true&useUnicode=true&characterEncoding=utf8
13:47:00.110 INFO  - Initializing Hibernate
13:47:03.520 INFO  - -------------  Inspecting D4A Dependency Manager Server
13:47:03.525 INFO  - Load module settings
13:47:04.145 INFO  - Quality profile : [name=Sonar way,language=js]
13:47:04.171 INFO  - Excluded sources: 
13:47:04.172 INFO  -   index.js
13:47:04.172 INFO  - Excluded tests: 
13:47:04.172 INFO  -   **/package-info.java
13:47:04.203 INFO  - Configure Maven plugins
13:47:04.309 INFO  - Compare to previous analysis (2014-02-07)
13:47:04.335 INFO  - Compare over 5 days (2014-02-02, analysis of 2014-02-07 12:04:17.0)
13:47:04.352 INFO  - Compare over 30 days (2014-01-08, analysis of 2014-02-07 12:04:17.0)
13:47:04.654 INFO  - Base dir: <http://jenkins.lgcoreapps.com/job/DDM_SERVER_CONTINUOUS_BUILD_AND_TEST/ws/>
13:47:04.654 INFO  - Working dir: <http://jenkins.lgcoreapps.com/job/DDM_SERVER_CONTINUOUS_BUILD_AND_TEST/ws/.sonar>
13:47:04.654 INFO  - Source dirs: <http://jenkins.lgcoreapps.com/job/DDM_SERVER_CONTINUOUS_BUILD_AND_TEST/ws/lib/src>
13:47:04.654 INFO  - Source encoding: US-ASCII, default locale: en_US
13:47:04.676 INFO  - Sensor JavaScriptSourceImporter...
13:47:04.797 INFO  - Sensor JavaScriptSourceImporter done: 121 ms
13:47:04.797 INFO  - Sensor JavaScriptSquidSensor...
13:47:05.858 INFO  - Sensor JavaScriptSquidSensor done: 1061 ms
13:47:05.858 INFO  - Sensor LCOVSensor...
13:47:05.859 INFO  - Analysing <http://jenkins.lgcoreapps.com/job/DDM_SERVER_CONTINUOUS_BUILD_AND_TEST/ws/reports/lcov.info>
13:47:05.902 INFO  - Sensor LCOVSensor done: 44 ms
13:47:05.903 INFO  - Sensor JsTestDriverSensor...
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 8.617s
Final Memory: 9M/28M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: Duplicate source for resource: org.sonar.api.resources.File@563e2119[key=Archive.js,dir=<null>,filename=Archive.js,language=JavaScript]
ERROR: 
ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with the -e switch.
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.
Build step 'Invoke Standalone Sonar Analysis' marked build as failure

编辑:在未提交测试报告确认分析完成后,这里是报告目录中的TEST-all.xml,以防它也提供线索

<testsuite name="Mocha Tests" tests="36" failures="0" errors="0" skipped="0" timestamp="Fri, 07 Feb 2014 10:23:12 GMT" time="1.073">
<testcase classname="Archive" name="should respond with 404 Not Found if pathInfo is not &quot;/&quot; or &quot;&quot;" time="0.005"/>
<testcase classname="Archive when the archive does not exist" name="should respond with 404 not Found" time="0.002"/>
<testcase classname="Archive when the archive exists" name="should respond with the archive" time="0.004"/>
<testcase classname="Get with an empty repository" name="should respond with an empty list of libraries" time="0.003"/>
<testcase classname="Get with a single library in the repository" name="should respond with a single entry list of libraries" time="0.002"/>
<testcase classname="Get with a multiple libraries in the repository" name="should respond with a list of libraries" time="0.004"/>
<testcase classname="Get with a multiple libraries in the repository" name="should prepend the root path to library paths correctly" time="0.001"/>
<testcase classname="Get with a multiple libraries in the repository" name="should pass requests with pathInfo not equal to &quot;/&quot; or &quot;&quot; to a Library instance" time="0.001"/>
<testcase classname="Library with an empty repository" name="should respond with 404 not Found" time="0.003"/>
<testcase classname="Library with an empty library (no versions)" name="should respond with an empty list of versions" time="0.003"/>
<testcase classname="Library with a single version" name="should respond with a single entry list of versions" time="0.002"/>
<testcase classname="Library with multiple versions" name="should respond with a list of versions" time="0.002"/>
<testcase classname="Library with multiple versions" name="should prepend the root path to library paths correctly" time="0.002"/>
<testcase classname="Library with multiple versions" name="should pass requests with pathInfo not equal to &quot;/&quot; or &quot;&quot; to a Version instance" time="0.001"/>
<testcase classname="Post" name="should respond with 400 Bad Request if the name is not specified" time="0.001"/>
<testcase classname="Post" name="should respond with 400 Bad Request if the version is not specified" time="0.001"/>
<testcase classname="Post" name="should respond with 415 Unsupported Media Type if the content-type is not application/octet-stream" time="0.001"/>
<testcase classname="Post" name="should respond with a new resource on success and write the archive and dependencies to the file system" time="0.015"/>
<testcase classname="Post" name="should respond with 400 Bad Request if dependencies are specified in an invalid format" time="0.005"/>
<testcase classname="Post" name="should add the dependencies to the new resource if present in the headers" time="0.015"/>
<testcase classname="Post" name="should prepend the root path to library paths correctly" time="0.011"/>
<testcase classname="Post" name="should respond with 405 Method Not Allowed if pathInfo is not &quot;/&quot; or &quot;&quot;" time="0.001"/>
<testcase classname="Registry GET" name="should be handled by an instance of Get" time="0.001"/>
<testcase classname="Registry POST" name="should be handled by an instance of Post" time="0"/>
<testcase classname="Registry UNKNOWN" name="should respond with 405 Method Not Allowed" time="0"/>
<testcase classname="Version when the version does not exist" name="should respond with 404 not Found" time="0.003"/>
<testcase classname="Version when the version exists" name="should respond with the version details and an empty list of dependencies" time="0.002"/>
<testcase classname="Version when the version exists" name="should pass requests with pathInfo equal to &quot;/archive&quot; to an Archive instance" time="0.001"/>
<testcase classname="Version when the version exists" name="should respond with 404 Not Found if pathInfo is not &quot;/&quot; or &quot;&quot; or &quot;/archive&quot;" time="0"/>
<testcase classname="Version when the version exists with a dependencies.json file" name="should respond with the list of dependencies" time="0.005"/>
<testcase classname="Version when the version exists with a dependencies.json file" name="should prepend the root path to library paths correctly" time="0.004"/>
<testcase classname="index with an empty repository GET &quot;/&quot;" name="should return an empty list of libraries" time="0.022"/>
<testcase classname="index with an empty repository after posting a library to &quot;/&quot; GET &quot;/&quot;" name="should respond with a single entry list of libraries" time="0.005"/>
<testcase classname="index with an empty repository after posting a library to &quot;/&quot; GET &quot;/library&quot;" name="should respond with a single entry list of versions" time="0.005"/>
<testcase classname="index with an empty repository after posting a library to &quot;/&quot; GET &quot;/library/0.0.0&quot;" name="should respond with the library resource" time="0.009"/>
<testcase classname="index with an empty repository after posting a library to &quot;/&quot; GET &quot;/library/0.0.0/archive&quot;" name="should respond with the library archive" time="0.006"/>
</testsuite>

1 个答案:

答案 0 :(得分:0)

因此确认问题是由包含反映源文件名的类名的测试报告引起的。我面临着选择重组测试或使用不同的摩卡记者的选择。据我所知,默认的mocha xunit报告器误用了classname字段(至少使用了BDD测试),并且我的测试结构的变化使我无法接受。

解决方案是实现并使用npm注册表中现在提供的"mocha-sonar-reporter"