diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2018-02-05 14:48:50 +0100 |
---|---|---|
committer | Janos Gyerik <janos.gyerik@sonarsource.com> | 2018-02-06 09:13:51 +0100 |
commit | 3c42d5d2e6b362d389c0058e069897bf26ef65f7 (patch) | |
tree | 567be18ebbb7c081e6f06ebe5ad65fd25048bd41 /sonar-plugin-api/src/main/java/org/sonar/api/Plugin.java | |
parent | ea77a805bfccb66c5943eb0bcaf36df3cb905227 (diff) | |
download | sonarqube-3c42d5d2e6b362d389c0058e069897bf26ef65f7.tar.gz sonarqube-3c42d5d2e6b362d389c0058e069897bf26ef65f7.zip |
Add Java API Plugin.Context#getBootConfiguration()
That allows plugins to check configuration when providing the list
of extensions.
Diffstat (limited to 'sonar-plugin-api/src/main/java/org/sonar/api/Plugin.java')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/Plugin.java | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/Plugin.java b/sonar-plugin-api/src/main/java/org/sonar/api/Plugin.java index 9dd31141f1e..b52e628f66d 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/Plugin.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/Plugin.java @@ -22,6 +22,7 @@ package org.sonar.api; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import org.sonar.api.config.Configuration; import org.sonar.api.utils.Version; import static java.util.Arrays.asList; @@ -67,18 +68,22 @@ import static java.util.Objects.requireNonNull; * </project> * </pre> * - * <p>Example of test + * <p>Example of Test * <pre> *{@literal @}Test * public void test_plugin_extensions_compatible_with_5_6() { * SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(5, 6), SonarQubeSide.SCANNER); - * Plugin.Context context = new Plugin.Context(runtime); - * new MyPlugin().define(context); + * Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build(); + * MyPlugin underTest = new MyPlugin(); + * + * underTest.define(context); + * * assertThat(context.getExtensions()).hasSize(4); * } * </pre> * * @since 5.5 + * @see org.sonar.api.internal.PluginContextImpl for unit tests */ public interface Plugin { @@ -86,8 +91,13 @@ public interface Plugin { private final SonarRuntime sonarRuntime; private final List extensions = new ArrayList(); + /** + * For unit tests only. It's recommended to use {@link org.sonar.api.internal.PluginContextImpl.Builder} + * to create instances of {@link Plugin.Context}. + * The configuration returned by {@see #getBootConfiguration()} is empty. + */ public Context(SonarRuntime sonarRuntime) { - this.sonarRuntime = sonarRuntime; + this.sonarRuntime = requireNonNull(sonarRuntime, "sonarRuntime is null"); } /** @@ -152,6 +162,18 @@ public interface Plugin { return extensions; } + /** + * The configuration that contains only the few properties required to bootstrap the process, for example: + * - conf/sonar.properties and persisted properties on web server and Compute Engine sides. The default values + * defined by plugins are ignored. + * - command-line arguments on scanner side. Default values or properties persisted in server are ignored. + * + * @since 7.1 + */ + public Configuration getBootConfiguration() { + throw new UnsupportedOperationException("Unit tests should create Plugin.Context with org.sonar.api.internal.PluginContextImpl#Builder"); + } + } /** |