fs.baseDir() returns test project directory instead of baseDir

Hi, I’m developing a plugin for SonarQube that will analyze the mutation testing results of .NET projects. But there is an issue I’ve been facing.

org.sonar.api.batch.fs.baseDir() always returns my project’s “tests” directory as a base directory, that’s why, I cant access to the files under src folder.

Is there any way to set baseDir as a directory where i’ve run dotnet-sonarscanner my .NET project? In general purpose sonar-scanner fs.baseDir() is set as directory where you’ve run sonar-scanner cli.

Thanks :slight_smile:


PS: As it can be seen, there are lots of people suffering from this issue. To me, I want to develop a plugin for Sonar to let people use it, but SonarScanner itself blocks me :slight_smile:

Hi, is there any workaround for this bug if there are no planned development? If not, I’ll try to make my plugin compatible with general purpose sonar-scanner


what the base class of your plugin? Is it the global one that runs once per project (.NET Solution), or the one that’s invoked per module (and therefore per .NET project with different file system and base path)?

Hi Pavel,

To make things clear, I’ve created a fresh .NET project which has the same folder structure as my corporate project that I’ve run into issue. Here is it.

So the steps I follow are like that:

  1. I install my plugin to a local SonarQube instance which runs on docker
  2. I run mutation tests on my project (I run it in /tests folder) which generates a JSON report file in tests/StrykerOutput directory. (Thats what the plugin I’ve been developing does. It parses that JSON file and creates issues on Sonar.)
  3. I run sonar.sh script that runs dotnet-sonarscanner. (Which means, I run dotnet-sonarscanner in the root directory where .sln file places)

After dotnet-sonarscanner runs, it runs my plugin which is installed in my local sonar instance that runs on Docker.

Then I start debugging my plugin.

The problem starts here. All of the Sonar plugins’ entrypoint is “execute” method which takes SonarContext as a parameter. This SonarContext object returns some project related info from dotnet-sonarscanner. But context.fs.baseDir directory returns /Users/mustafa.yumurtaci/workspace/Example/src which is wrong, because i didn’t run dotnet-sonarscanner in this directory, I’ve run it in /Users/mustafa.yumurtaci/workspace/Example which is root directory. So the context.fs.baseDir (which is an info that dotnet-sonarscanner returns to the plugin) should be the root directory.

The detailed info can bee seen in the screenshot below:

I’ve also tried general purpose sonar-scanner, and it returns context.fs.baseDir as root directory which is correct.

So this is the bug I’ve been talking about. I hope it’s more clear now.

Thank you for your time :slight_smile:

Btw, I’ve also tried different versions of dotnet sonarscanner if the problem is specific to the latest version.

HI @mustafayumurtaci,

You’re implementing wrong interface for your sensor.
For org.sonar.api.batch.sensor.Sensor:

A sensor is invoked once for each module of a project, starting from leaf modules. The sensor can parse a flat file, connect to a web server… Sensors are used to add measure and issues at file level.

That means that your sensor is invoked for each SonarQube module. SonarQube module is .NET Project. Each project has it’s own file system with it’s own root directory (src and tests in your case).

You need to implement org.sonar.api.scanner.sensor.ProjectSensor:

A sensor is invoked once for each project analysis. Sensors are mainly used to add measures and issues on {@link org.sonar.api.batch.fs.InputFile}s.

Where project means SonarQube project. SonarQube project is .NET Solution. If you implement this, you’ll get your global solution filesystem root path as you expect.

Hi Pavel,

Thanks for the reply! I’ve followed what you say and now it works great. I’ll deploy the plugin to the marketplace ASAP. Best!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.