How to install custom RulesDefinition using resources in external jar file

I’m working on a custom Sonar Plugin that will implement a custom RulesDefinition. I am generating the rules from resources contained in a jar file. Before generating the rules, I have to explode the jar to a org.sonar.api.batch.fs.FileSystem.
So far I only know how to access fs.FileSystem via SensorContext.fileSystem().
I’m trying to define the rules in the custom RulesDefinition inside define(Context), using NewRepository.
I can think of three possible ways to bridge the gap:

  1. Navigate (somehow) from org.sonar.api.server.rule.Context to org.sonar.api.batch.fs.FileSystem
  2. Ensure that the external jar is exploded before custom RulesDefinition define(Context) is called.
  3. Have the plugin initially install the custom RulesDefinition with an empty set of rules; provide a link from the RulesDefinition to the Sensor; call the RulesDefinition define(Context) from within the Sensor.execute(SensorContext)

Does anyone have any suggestions or advice?

Thanks in advance!

Sorry, it looks like I was on a newbie’s fool’s errand. I thought there was something special about org.sonar.api.batch.fs.FileSystem.baseDir but actually plain old Java NIO worked just as well.
So in the end I had no difficulty locating the target directory and copying files from the source jar into it.

1 Like