2016-06-23 58 views
0

我想在一個非常基本的C++項目上使用SonarQube。我使用CppUnit進行我的測試,它會生成一個xml報告。
我使用SonarQube C++社區插件,但我沒有設法在SonarQube中顯示我的測試結果。Sonarqube無法看到我的cppunit報告

這裏是我的sonar-project.properties文件

# Required metadata 
sonar.projectKey=test 
sonar.projectName=C++ Project Test 
sonar.projectVersion=1.0 

# Comma-separated paths to directories with sources (required) 
sonar.sources=./ 

# Language 
sonar.language=c++ 

# Encoding of the source files 
sonar.sourceEncoding=UTF-8 

# Path to the directory containing the CPPUnit reports 

sonar.cxx.xunit.xsltURL=report/cppunit/cppunit-1.x-to-junit-1.0.xsl 
sonar.cxx.xunit.reportPath=report/cppunit/cppunit-report.xml 

我發現需要一個XSLT轉換爲SonarQube能夠閱讀的CppUnit報道互聯網上。
我在我的項目文件夾中運行sonar-runner -X以開始分析。
- 當我嘗試在沒有xslt轉換的情況下使用它時,我沒有任何錯誤,但沒有提到有關SonarQube Web界面測試的內容(如未執行)。
- 當我使用XSLT轉換我有這樣的錯誤:

Transforming the report using xslt 'report/cppunit/cppunit-1.x-to-junit-1.0.xsl' 
10:21:36.793 DEBUG - Transforming: try to access external XSLT via URL 
10:21:36.794 ERROR - Cannot feed the data into SonarQube, details: 'java.net.MalformedURLException: no protocol: report/cppunit/cppunit-1.x-to-junit-1.0.xsl' 
INFO: ------------------------------------------------------------------------ 
INFO: EXECUTION FAILURE 
INFO: ------------------------------------------------------------------------ 
Total time: 7.589s 
Final Memory: 21M/292M 
INFO: ------------------------------------------------------------------------ 
ERROR: Error during Sonar runner execution 
org.sonar.runner.impl.RunnerException: Unable to execute Sonar 
at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:91) 
at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75) 
at java.security.AccessController.doPrivileged(Native Method) 
at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69) 
at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50) 
at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102) 
at org.sonar.runner.api.Runner.execute(Runner.java:100) 
at org.sonar.runner.Main.executeTask(Main.java:70) 
at org.sonar.runner.Main.execute(Main.java:59) 
at org.sonar.runner.Main.main(Main.java:53) 
Caused by: java.lang.IllegalStateException: Cannot feed the data into SonarQube, details: 'java.net.MalformedURLException: no protocol: report/cppunit/cppunit-1.x-to-junit-1.0.xsl' 
at org.sonar.plugins.cxx.tests.xunit.CxxXunitSensor.analyse(CxxXunitSensor.java:159) 
at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:58) 
at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:50) 
at org.sonar.batch.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:83) 
at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:192) 
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142) 
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127) 
at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:241) 
at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:236) 
at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:226) 
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142) 
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127) 
at org.sonar.batch.task.ScanTask.execute(ScanTask.java:47) 
at org.sonar.batch.task.TaskContainer.doAfterStart(TaskContainer.java:86) 
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142) 
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127) 
at org.sonar.batch.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:106) 
at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:119) 
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:79) 
at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:48) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:498) 
at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:87) 
... 9 more 
Caused by: java.net.MalformedURLException: no protocol: report/cppunit/cppunit-1.x-to-junit-1.0.xsl 
at java.net.URL.<init>(URL.java:593) 
at java.net.URL.<init>(URL.java:490) 
at java.net.URL.<init>(URL.java:439) 
at org.sonar.plugins.cxx.tests.xunit.CxxXunitSensor.transformReport(CxxXunitSensor.java:265) 
at org.sonar.plugins.cxx.tests.xunit.CxxXunitSensor.analyse(CxxXunitSensor.java:135) 
... 33 more 

任何人有關於如何解決這個問題的想法?或者是一個教程或其他的東西,說明如何在SonarQube中使用CppUnit報告?我搜索了幾個小時,但我沒有找到任何解決辦法。

回答

0

我的問題已修復。 看起來xslt轉換文件的路徑從cppunit xml文件所在的位置開始。

就我而言,我不得不更換這樣的:通過這個

sonar.cxx.xunit.xsltURL=report/cppunit/cppunit-1.x-to-junit-1.0.xsl 

sonar.cxx.xunit.xsltURL=cppunit-1.x-to-junit-1.0.xsl