Uploaded image for project: 'SonarQube'
  1. SonarQube
  2. SONAR-10405

Java API: ability to use configuration when initializing a plugin

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 7.1
    • Component/s: Plugin API, Settings
    • Labels:
      None

      Description

      A plugin should be able to define its extensions depending on configuration. A use-case is to completely disable a feature if a specific property is set.
      For technical reasons the component org.sonar.api.config.Configuration can't be injected in implementations of class org.sonar.api.Plugin. That's why the configuration should be provided by the Plugin.Context:

      public class MyPlugin implements Plugin {
         @Override
          public void define(Context context) {
            if (context.getBootConfiguration().getBoolean("foo.enabled").orElse(false)) {
              context.addExtension(MyExtension.class);
            }
          }
        }
      

        Attachments

          Activity

            People

            Assignee:
            simon.brandhof Simon Brandhof (Inactive)
            Reporter:
            simon.brandhof Simon Brandhof (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: