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

Hi @jacek.poreda is there an update on the status of this. I reviewed the ticket in JIRA and it hasn’t had any further comments after the request for more information.

I am also trying to develop a plugin that uses the PostProjectAnalysisTask and would like to have per project settings. Is there a way to get the fix prioritized?

Thanks

Hello @john ,

There is no specific order in which we will tackle bug tickets. I would advise you to vote for it, so that it would gain more visibility on our side.

For now I will assign it to 9.3 version, but I don’t guarantee it will be fixed.

Thanks for the update I have voted for it and hopefully it gets fixed :slight_smile:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.