Custom Plugin development

I have defined a SchedulerProperties class below for my scheduler to get values like accessToken and organization/ I have also defined one property that is a toggle which allows the plugin to start the scheduler and further post data.
package org.sonarsource.plugins.example.settings;

import org.sonar.api.PropertyType;
import org.sonar.api.config.PropertyDefinition;

import java.util.List;

import static java.util.Arrays.asList;

public class SchedulerProperties {

  public static final String SCHEDULER_KEY = "sonar.scheduler.schedulerKey";
  public static final String ORGANIZATION = "sonar.scheduler.organization";
  public static final String ACCESS_TOKEN = "sonar.scheduler.accessToken";
  public static final String CATEGORY = "Scheduler Properties";

  private SchedulerProperties() {
    // only statics

  public static List<PropertyDefinition> getProperties() {
    return asList(
        .description("Set Scheduler to fetch the updated sonar report data and save it to the smart contract")
        .build(), PropertyDefinition.builder(ORGANIZATION)
                    .description("Organization Name for the Smart Contract")
                    .build(), PropertyDefinition.builder(ACCESS_TOKEN)
                    .name("Access Token")
                    .description("Access Token for the Smart Contract")

I am checking the values of the properties by overriding a onChange function in the class SchedulerSettingsChangeListener which extends GlobalPropertyChangeHandler.

    public void onChange(PropertyChange change) {
        System.out.println("In onChange function: ");
        Loggers.get(getClass()).info("In onChange function: ");
        if(change.getKey().equals("sonar.scheduler.schedulerKey")) {
            Loggers.get(getClass()).info("In onChange function if: ");
            Loggers.get(getClass()).info("scheduler key: " + change.getNewValue());
            Loggers.get(getClass()).info("Server URL getPublicRootUrl() : " + server.getPublicRootUrl());

            if (change.getNewValue().equals("true")) {
                configuration.get(SchedulerProperties.ORGANIZATION).ifPresentOrElse(value -> organization = value, () -> organization = "");
                Loggers.get(getClass()).info("In toggle true logic organization: " + organization);
                configuration.get(SchedulerProperties.ACCESS_TOKEN).ifPresentOrElse(value -> accessToken = value, () -> accessToken = "");
                Loggers.get(getClass()).info("In toggle true logic accessToken: " + accessToken);
                if (StringUtils.isNotEmpty(organization) && StringUtils.isNotEmpty(accessToken)) {
                    scheduler = Executors.newScheduledThreadPool(1);
                    scheduler.scheduleAtFixedRate(() -> {
                        Loggers.get(getClass()).info("Scheduler start: ");
                        List<PostData> postDataList = new ArrayList<>();
                        fetchDataFromAPI(SONAR_HOST_URL, postDataList);
                    }, initialDelay, period, TimeUnit.SECONDS);
                else {
                    Loggers.get(getClass()).info("Organization or accessToken is empty. Setting scheduler key to false");
            else {
                Loggers.get(getClass()).info("In else condition Scheduler shutdown: ");
                if(scheduler != null) {
                    Loggers.get(getClass()).info("Scheduler is not Null Scheduler shutdown: ");
        if(change.getKey().equals("sonar.scheduler.organization")) {
            Loggers.get(getClass()).info("In onChange function: ");
            Loggers.get(getClass()).info("organization: " + change.getNewValue());
            organization = change.getNewValue();
        if(change.getKey().equals("sonar.scheduler.accessToken")) {
            Loggers.get(getClass()).info("In onChange function: ");
            Loggers.get(getClass()).info("accessToken: " + change.getNewValue());
            accessToken = change.getNewValue();

Q: I want to reset the toggle value programmatically if organization or accessToken is empty. I am not able to find any set function in the org.sonar.api.config.Configuration nor in the org.sonar.api.ce.measure.Settings class. Can anyone suggest how should I do that?


Could you explain what you’re trying to accomplish?


Hi Ann,
Thanks for the reply, I am trying to read the sonarqube report details and posting it to my application using the plugin (plugin code that have been shared in the documentation).


Sorry, but we just don’t support that. What you can do though is

  • get the Quality Gate metric values sent to the location of your choice using a webhook
  • use the Web API to pull data to craft your report external to SonarQube