Plugin Development / Project-Level Settings have no effect in CE

sonarqube

(Gerald Mücke) #1

Hi all,

I’m developing a custom plugin which defines a project-level setting. When I make any change to the project level setting (a boolean on/off flag), the setting is not effective in the computation engine, for example in a Computer implementation in the custom plugin.

I tried it on both version 6.7.4 and 7.2.1 versions used

The only setting that is effective is a global-level property.
I tried it with both global+project and project-only, either way the project-level settings is not visible.

Via debugger I tracked it down to the DatabaseSettingsLoader::load() method, which is called via this stack

load:40, DatabaseSettingLoader (org.sonar.server.setting)
load:122, ThreadLocalSettings (org.sonar.server.setting)
get:114, ThreadLocalSettings (org.sonar.server.setting)
getRawString:95, Settings (org.sonar.api.config)
getString:145, Settings (org.sonar.api.config)
get:55, ConfigurationProvider$ServerConfigurationAdapter (org.sonar.server.config)
getBoolean:130, Configuration (org.sonar.api.config)
compute:76, MutationScoreComputer (ch.devcon5.sonar.plugins.mutationanalysis.metrics)
(..)

The load method always fetches the globalProperty

PropertyDto dto = dbClient.propertiesDao().selectGlobalProperty(key);

I’d expect a property that is set for project scope to be effective in the compute engine as well, not only global properties.

I’d appreciate if someone could either verify this issue or point me to where I’m wrong :slight_smile:


(Sam Anthonisz) #2

Hi,

I have also recently encountered this issue while developing a plugin. I’ve tried on versions 7.1 and 7.3 and have seen that @ScannerSide extensions are using the project scope as expected, yet @ComputeEngineSide extensions are retrieving the global configuration. I’ve used both the deprecated Settings class and the new Configuration classes via dependency injection with the same results.

This would appear to directly contradict the published JavaDocs e.g. http://javadocs.sonarsource.org/7.3/apidocs/org/sonar/api/config/Configuration.html

Component to get effective configuration. Values of properties depend on the runtime environment:

  • immutable project or module configuration in scanner.
  • global configuration in web server. It does not allow to get the settings overridden on projects.
  • project configuration in Compute Engine.

Like Gerald, I’d also appreciate some feedback from SonarSource as to whether this is indeed an issue or if it is intentional.

Thanks!


(Julien Lancelot) #5

Hi guys,

Sorry for coming late on this subject.

Could you please share the following stuff :

  • PropertyDefinition usage
  • Measure Computer implementation example.

Thanks !
Regards


(Julien Lancelot) #6

I’d also like to add that project settings should be taken into account in a MeasureComputer.