diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-04-11 10:57:05 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-04-11 10:57:50 +0200 |
commit | 50e2bb1db1b097cac4fb73b4aa211a37ba2184b5 (patch) | |
tree | ad58a49eca1f00585dc2e15ae53b9ad23fddc50e | |
parent | a5338f2a09043c24f2cae4fc50ac4fc82891eaaf (diff) | |
download | sonarqube-50e2bb1db1b097cac4fb73b4aa211a37ba2184b5.tar.gz sonarqube-50e2bb1db1b097cac4fb73b4aa211a37ba2184b5.zip |
Change return type of Plugin#getSonarQubeVersion()
and improve Javadoc
5 files changed, 32 insertions, 18 deletions
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java index 69cc0823895..76198a3ac70 100644 --- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java +++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java @@ -21,7 +21,6 @@ package org.sonar.xoo; import org.junit.Test; import org.sonar.api.Plugin; -import org.sonar.api.SonarQubeVersion; import org.sonar.api.utils.Version; import org.sonar.xoo.lang.CpdTokenizerSensor; @@ -32,11 +31,11 @@ public class XooPluginTest { @Test public void provide_extensions_for_5_5() { - Plugin.Context context = new Plugin.Context(new SonarQubeVersion(V5_5)); + Plugin.Context context = new Plugin.Context(V5_5); new XooPlugin().define(context); assertThat(context.getExtensions()).hasSize(39).contains(CpdTokenizerSensor.class); - context = new Plugin.Context(new SonarQubeVersion(Version.parse("5.4"))); + context = new Plugin.Context(Version.parse("5.4")); new XooPlugin().define(context); assertThat(context.getExtensions()).hasSize(38).doesNotContain(CpdTokenizerSensor.class); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/ServerExtensionInstaller.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/ServerExtensionInstaller.java index 931b3e7779c..fef6ed8a484 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/plugins/ServerExtensionInstaller.java +++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/ServerExtensionInstaller.java @@ -60,7 +60,7 @@ public abstract class ServerExtensionInstaller { Plugin plugin = pluginRepository.getPluginInstance(pluginKey); container.addExtension(pluginInfo, plugin); - Plugin.Context context = new Plugin.Context(sonarQubeVersion); + Plugin.Context context = new Plugin.Context(sonarQubeVersion.get()); plugin.define(context); for (Object extension : context.getExtensions()) { if (installExtension(container, pluginInfo, extension, true) != null) { 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 bf097a28939..3fa26caa9ee 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 @@ -23,6 +23,7 @@ import com.google.common.annotations.Beta; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import org.sonar.api.utils.Version; import static java.util.Arrays.asList; import static java.util.Objects.requireNonNull; @@ -31,11 +32,11 @@ import static java.util.Objects.requireNonNull; * Entry-point for plugins to inject extensions into SonarQube. * <p>The JAR manifest must declare the name of the implementation class in the property <code>Plugin-Class</code>. * This property is automatically set by sonar-packaging-maven-plugin when building plugin.</p> - * <p>Example of implementation: + * <p>Example of implementation</p> * <pre> * package com.mycompany.sonarqube; * public class MyPlugin implements Plugin { - * {@literal @}Override + * {@literal @}Override * public void define(Context context) { * context.addExtensions(MySensor.class, MyRules.class); * if (context.getSonarQubeVersion().isGreaterThanOrEqual(SonarQubeVersion.V5_6)) { @@ -46,8 +47,8 @@ import static java.util.Objects.requireNonNull; * } * } * </pre> - * </p> - * <p>Example of pom.xml:</p> + * + * <p>Example of pom.xml</p> * <pre> * <project> * ... @@ -68,20 +69,35 @@ import static java.util.Objects.requireNonNull; * </project> * </pre> * + * <p>Example of test</p> + * <pre> + * MyPlugin underTest = new MyPlugin(); + * + *{@literal @}Test + * public void test_plugin_extensions_compatible_with_5_5() { + * Plugin.Context context = new Plugin.Context(SonarQubeVersion.V5_5); + * underTest.define(context); + * assertThat(context.getExtensions()).hasSize(4); + * } + * </pre> + * * @since 5.5 */ @Beta public interface Plugin { class Context { - private final SonarQubeVersion version; + private final Version version; private final List extensions = new ArrayList(); - public Context(SonarQubeVersion version) { + public Context(Version version) { this.version = version; } - public SonarQubeVersion getSonarQubeVersion() { + /** + * Runtime version of SonarQube + */ + public Version getSonarQubeVersion() { return version; } @@ -89,10 +105,10 @@ public interface Plugin { * Add an extension as : * <ul> * <li>a Class that is annotated with {@link org.sonar.api.batch.BatchSide}, {@link org.sonar.api.server.ServerSide} - * or {@link org.sonar.api.server.ComputeEngineSide}.</li> - * The extension will be instantiated once. Its dependencies are injected through constructor parameters.</li> + * or {@link org.sonar.api.ce.ComputeEngineSide}. The extension will be instantiated once. Its dependencies are + * injected through constructor parameters.</li> * <li>an instance that is annotated with {@link org.sonar.api.batch.BatchSide}, {@link org.sonar.api.server.ServerSide} - * or {@link org.sonar.api.server.ComputeEngineSide}.</li> + * or {@link org.sonar.api.ce.ComputeEngineSide}.</li> * </ul> * Only a single component can be registered for a class. It's not allowed for example to register: * <ul> diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/PluginTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/PluginTest.java index 204a430dde3..6a2602a5450 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/PluginTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/PluginTest.java @@ -29,9 +29,9 @@ public class PluginTest { @Test public void test_context() { - Plugin.Context context = new Plugin.Context(new SonarQubeVersion(V5_5)); + Plugin.Context context = new Plugin.Context(V5_5); - assertThat(context.getSonarQubeVersion().get()).isEqualTo(V5_5); + assertThat(context.getSonarQubeVersion()).isEqualTo(V5_5); assertThat(context.getExtensions()).isEmpty(); context.addExtension("foo"); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java index dfab90ea7e8..5794a8a0314 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java @@ -23,7 +23,6 @@ import java.util.List; import javax.annotation.Nullable; import org.sonar.api.ExtensionProvider; import org.sonar.api.Plugin; -import org.sonar.api.SonarPlugin; import org.sonar.api.SonarQubeVersion; import org.sonar.api.batch.AnalysisMode; import org.sonar.core.platform.ComponentContainer; @@ -52,7 +51,7 @@ public class ExtensionInstaller { // plugin extensions for (PluginInfo pluginInfo : pluginRepository.getPluginInfos()) { Plugin plugin = pluginRepository.getPluginInstance(pluginInfo.getKey()); - Plugin.Context context = new Plugin.Context(sonarQubeVersion); + Plugin.Context context = new Plugin.Context(sonarQubeVersion.get()); plugin.define(context); for (Object extension : context.getExtensions()) { doInstall(container, matcher, pluginInfo, extension); |