Get Project Configuration in Compute Engine

Hi there,

According to the API docs, the Configuration interface should provide project-level settings for Compute Engine extensions:

https://javadoc.io/doc/org.sonarsource.sonarqube/sonar-plugin-api/latest/org/sonar/api/config/Configuration.html

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

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

However if implementing a PostProjectAnalysisTask it appears to not be the case, only the global configuration is available - any global setting that was overridden at a project-level is not reflected in the Configuration object.

Example:

    PropertyDefinition.builder("DEMO_SETTING")
                .category("DEMO PLUGIN")
                .onQualifiers(Qualifiers.PROJECT)
                .build()
public class DemoTask implements PostProjectAnalysisTask {

    private final Configuration config;

    public DemoTask(Configuration config) {
        this.config = config;
    }

    @Override
    public String getDescription() {
        return "Demo";
    }

    @Override
    public void finished(Context context) {
        String setting = this.config.get("DEMO_SETTING")
        // THE VALUE OF "setting" IS THE GLOBAL VALUE, NOT THE PROJECT-LEVEL VALUE
    }

Are you able to confirm if this is a bug or if it is intended behaviour, in which case the API documentation should probably be updated :slight_smile:

Thanks!

Sam

Hello @Sam_Anthonisz,

Indeed it is a bug. Currently the injected instance of Configuration will be ServerConfigurationAdapter, which holds org.sonar.server.setting.ThreadLocalSettings under the hood, which doesn’t have project specific settings.

I’ve created a ticket which you can track for fix: https://jira.sonarsource.com/browse/SONAR-13711