Unable to read plugin configuration in 7.x

scanner
(Igor Matlin) #1

Help! My plugin code that reads project-specific plugin configuration no longer works with 7.x versions of SQ. It works fine with 6.5.x LTS version.

The code follows the guide here: http://javadocs.sonarsource.org/7.7/apidocs/org/sonar/api/config/Configuration.html. Specifically, this template:

// Scanner sensor can get the reference on Configuration directly through SensorContext, without injecting the component into constructor.
public class MySensor implements Sensor {
@Override
public void execute(SensorContext context) {
String fooValue = context.config().get(“sonar.foo”).orElse(null);
// …
}
}

The configuration properties are not part of the context object, and therefore get() returns null. Setting configuration via UI works fine. While building properties in plugin’s define() method, I can see the plugins settings being properly added to context.extensions list, but once it gets to reading these settings in the sensor’s execute() method, none of the properties are there.

What’s changed in 7.x?