Question

I'm trying Sonar 3.2 with C# projects (the only plugins are C# Core and C# FX Cop) and using the Simple Java Runner.

It worked fine on a solution with a single project, but when I tried to analyse using a solution with 2 projects I always get the following error:

    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

The solution folder contains the following 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

The solution only has this 2 projects.

I tried adding the modules configuration in a sonar-project.properties for each project with just:

# Project identification
sonar.projectName=Project 1

For the single project I used I had:

# Project identification
sonar.projectKey=com.Project1
sonar.projectVersion=1.0
sonar.projectName=Project 1

# Info required for Sonar
sonar.sources=.
sonar.language=cs

I feel I'm missing something very simple, but I couldn't find much information on this.

If someone can help me with this I have an additional question: Can you analyse a hybrid solution of C++ and C# project?

Thanks

Was it helpful?

Solution

The support of multi-module is built-in for the C# plugins, you don't need to (and should not) specify:

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

, nor add a "sonar-project.properties" inside each module.

The C# Plugins rely on the SLN file to automatically discover the modules. Take a look at our sample application, and just replace the Maven POM by a single "sonar-project.properties" file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top