我正在尝试使用C#项目的Sonar 3.2(唯一的插件是C#Core和C#FX Cop)并使用Simple Java Runner。
在单个项目的解决方案上运行良好,但当我尝试使用包含2个项目的解决方案进行分析时,我总是会收到以下错误:
17:01:41.775 INFO .s.b.b.ProjectModule - ------------- Analyzing Project1 17:01:42.055 INFO .s.b.ProfileProvider - Selected quality profile : [name=Custom C#,language=cs] 17:01:42.075 INFO nPluginsConfigurator - Configure maven plugins... 17:01:42.125 INFO org.sonar.INFO - Compare to previous analysis 17:01:42.155 INFO org.sonar.INFO - Compare over 5 days (2012-09-27) 17:01:42.175 INFO org.sonar.INFO - Compare over 30 days (2012-09-02) 17:01:42.215 INFO .b.p.SensorsExecutor - Initializer ProjectFileSystemLogger... 17:01:42.215 INFO jectFileSystemLogger - Source directories: 17:01:42.215 INFO jectFileSystemLogger - $(Solution folder)\Project1 17:01:42.215 INFO .b.p.SensorsExecutor - Initializer ProjectFileSystemLogger done: 0 ms 17:01:42.225 INFO .b.p.SensorsExecutor - Initializer CSharpProjectInitializer... 17:01:42.225 INFO .b.p.SensorsExecutor - Initializer CSharpProjectInitializer done: 0 ms 17:01:42.255 INFO o.s.p.cpd.CpdSensor - Detection of duplicated code is not supported for C#. Total time: 8.442s Final Memory: 5M/118M Exception in thread "main" org.sonar.runner.RunnerException: java.lang.NullPointerException at org.sonar.runner.Runner.delegateExecution(Runner.java:288) at org.sonar.runner.Runner.execute(Runner.java:151) at org.sonar.runner.Main.execute(Main.java:84) at org.sonar.runner.Main.main(Main.java:56) Caused by: java.lang.NullPointerException at org.sonar.plugins.csharp.api.sensor.AbstractRegularCSharpSensor.assembliesFound(AbstractRegularCSharpSensor.java:101) at org.sonar.plugins.csharp.api.sensor.AbstractRegularCSharpSensor.shouldExecuteOnProject(AbstractRegularCSharpSensor.java:81) at org.sonar.plugins.csharp.api.sensor.AbstractRuleBasedCSharpSensor.shouldExecuteOnProject(AbstractRuleBasedCSharpSensor.java:48) at org.sonar.api.batch.BatchExtensionDictionnary.shouldKeep(BatchExtensionDictionnary.java:109) at org.sonar.api.batch.BatchExtensionDictionnary.getFilteredExtensions(BatchExtensionDictionnary.java:99) at org.sonar.api.batch.BatchExtensionDictionnary.select(BatchExtensionDictionnary.java:57) at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:57) at org.sonar.batch.phases.Phases.execute(Phases.java:93) at org.sonar.batch.bootstrap.ProjectModule.doStart(ProjectModule.java:139) at org.sonar.batch.bootstrap.Module.start(Module.java:83) at org.sonar.batch.bootstrap.BatchModule.analyze(BatchModule.java:131) at org.sonar.batch.bootstrap.BatchModule.analyze(BatchModule.java:126) at org.sonar.batch.bootstrap.BatchModule.doStart(BatchModule.java:121) at org.sonar.batch.bootstrap.Module.start(Module.java:83) at org.sonar.batch.bootstrap.BootstrapModule.doStart(BootstrapModule.java:121) at org.sonar.batch.bootstrap.Module.start(Module.java:83) at org.sonar.batch.Batch.execute(Batch.java:104) at org.sonar.runner.internal.batch.Launcher.executeBatch(Launcher.java:69) at org.sonar.runner.internal.batch.Launcher.execute(Launcher.java:61) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.sonar.runner.Runner.delegateExecution(Runner.java:285) ... 3 more
解决方案文件夹包含以下sonar-project.properties:
# Project identification
sonar.projectKey=com.project.btg
sonar.projectVersion=1.0
sonar.projectName=BTG
# Info required for Sonar
sonar.sources=.
sonar.language=cs
sonar.dotnet.visualstudio.solution.file=Sonar.project.sln
sonar.dotnet.buildPlatform=x86
sonar.dotnet.buildConfiguration=Debug
sonar.modules=Project1,Project2
#modules specific configuration
Project1:sonar.sources=.\Project1
Project1:sonar.projectName=Project 1
Project2:sonar.sources=.\Project2
Project2:sonar.sources=Project 2
解决方案只有这两个项目。
我尝试在每个项目的sonar-project.properties中添加模块配置,只需:
# Project identification
sonar.projectName=Project 1
对于我用过的单项目:
# Project identification
sonar.projectKey=com.Project1
sonar.projectVersion=1.0
sonar.projectName=Project 1
# Info required for Sonar
sonar.sources=.
sonar.language=cs
我觉得我错过了一些非常简单的事情,但我找不到太多关于此的信息。
如果有人可以帮助我,我还有一个问题: 你能分析一下C ++和C#项目的混合解决方案吗?
由于
答案 0 :(得分:4)
多模块的支持是内置的C#插件,你不需要(并且不应该)指定:
sonar.modules=Project1,Project2
#modules specific configuration
Project1:sonar.sources=.\Project1
Project1:sonar.projectName=Project 1
Project2:sonar.sources=.\Project2
Project2:sonar.sources=Project 2
,也不在每个模块中添加“sonar-project.properties”。
C#插件依赖SLN文件自动发现模块。看看our sample application,只需用一个“sonar-project.properties”替换Maven POM文件。