How to get the "Base dir:" in SonarQube Java custom rule

How to get the “Base dir:” in SonarQube Java custom rule.

I want to pick the “Base dir:” , which is printed as an info, from custom rules.

INFO: Indexing files of module ‘gv-core-itf’
INFO: Base dir: C:\Users\asishs.jenkins\workspace\Test\devel\gv-core\gv-core-itf

Hi Asish,

I don’t think it’s possible to access to org.sonar.api.batch.fs.FileSystem#baseDir() from the JavaFileScannerContext of a rule or to the sonar.projectBaseDir property.
But, it should be possible to inject FileSystem fs to any class added as an extension in your class that implements Plugin (like context.addExtension(MyJavaFileCheckRegistrar.class);).
To do so add a public constructor with a FileSystem fs argument, and the container will inject it.

@SonarLintSide
@ScannerSide
public class MyClass {
  public MyClass(FileSystem fs) {
    // find a hack to pass the fs argument to the rules...
  }
}

For example, you could add a constructor to your class that implements CheckRegistrar.

Hi @alban.auzeill,

Thank you very much.