diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2016-06-10 09:45:15 +0200 |
---|---|---|
committer | Julien HENRY <henryju@yahoo.fr> | 2016-07-07 09:56:20 +0200 |
commit | 2d20c0f3f27356ad1f9aa430f3e5925c50756cfc (patch) | |
tree | 916658329d7245f97f3f390c1dee5c8659bde03b /sonar-plugin-api/src | |
parent | a4e0563f753bf04f6560f7014a974d2d4f248d84 (diff) | |
download | sonarqube-2d20c0f3f27356ad1f9aa430f3e5925c50756cfc.tar.gz sonarqube-2d20c0f3f27356ad1f9aa430f3e5925c50756cfc.zip |
SONAR-7751, SONAR-7756 SonarLint API
Diffstat (limited to 'sonar-plugin-api/src')
19 files changed, 391 insertions, 58 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/ExtensionProvider.java b/sonar-plugin-api/src/main/java/org/sonar/api/ExtensionProvider.java index 5602be54411..b0e19e236b4 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/ExtensionProvider.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/ExtensionProvider.java @@ -19,16 +19,20 @@ */ package org.sonar.api; +import org.sonar.api.batch.BatchSide; +import org.sonar.api.ce.ComputeEngineSide; +import org.sonar.api.server.ServerSide; + /** - * Factory of extensions. It allows to dynamically create extensions depending upon runtime context. A use-case is + * Factory of extensions. It allows to dynamically create extensions depending upon runtime context. One use-case is * to create one rule repository by language. * * <p>Notes : * <ul> * <li>the provider is declared in Plugin.getExtensions()</li> - * <li>the provider must also implement ServerExtension and/or BatchExtension</li> + * <li>the provider must also add annotation {@link ServerSide}, {@link ComputeEngineSide} and/or {@link BatchSide}</li> * <li>the provider can accept dependencies (parameters) in its constructors.</li> - * <li>the method provide() is executed once by sonar</li> + * <li>the method provide() is executed once by the platform</li> * <li>the method provide() must return an object, a class or an Iterable of objects. <strong>Arrays are excluded</strong>.</li> * </ul> * @@ -36,7 +40,8 @@ package org.sonar.api; * <p>Example: * <pre> * {@code - * public class RuleRepositoryProvider extends ExtensionProvider implements ServerExtension { + * {@literal @}ServerSide + * public class RuleRepositoryProvider extends ExtensionProvider { * private Language[] languages; * * public RuleRepositoryProvider(Language[] languages) { @@ -59,7 +64,8 @@ package org.sonar.api; * @deprecated since 6.0 should no more be used */ @Deprecated -public abstract class ExtensionProvider implements Extension { +@ExtensionPoint +public abstract class ExtensionProvider { public abstract Object provide(); } 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 21832e1754e..aa1a6f9511a 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 @@ -85,18 +85,29 @@ import static java.util.Objects.requireNonNull; public interface Plugin { class Context { - private final Version version; + private final Version runtimeApiVersion; private final List extensions = new ArrayList(); + private final boolean sonarlintRuntime; - public Context(Version version) { - this.version = version; + public Context(Version runtimeApiVersion, boolean sonarlintRuntime) { + this.runtimeApiVersion = runtimeApiVersion; + this.sonarlintRuntime = sonarlintRuntime; } /** - * Runtime version of SonarQube + * @deprecated since 6.0 */ + @Deprecated public Version getSonarQubeVersion() { - return version; + return runtimeApiVersion; + } + + /** + * Runtime API version. Can be use to conditionnaly add some extensions. + * @since 6.0 + */ + public Version getRuntimeApiVersion() { + return runtimeApiVersion; } /** @@ -141,6 +152,14 @@ public interface Plugin { public List getExtensions() { return extensions; } + + /** + * Test if plugin is currently executed in SonarLint. Can be use to conditionnaly add some extensions. + * @since 6.0 + */ + public boolean isSonarlintRuntime() { + return sonarlintRuntime; + } } /** diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/RuntimeApiVersion.java b/sonar-plugin-api/src/main/java/org/sonar/api/RuntimeApiVersion.java new file mode 100644 index 00000000000..e221f6f9f8e --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/RuntimeApiVersion.java @@ -0,0 +1,161 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.api; + +import javax.annotation.concurrent.Immutable; +import org.sonar.api.batch.BatchSide; +import org.sonar.api.batch.sensor.Sensor; +import org.sonar.api.ce.ComputeEngineSide; +import org.sonar.api.server.ServerSide; +import org.sonar.api.utils.Version; + +import static java.util.Objects.requireNonNull; + +/** + * Version of SonarQube at runtime. This component can be injected as a dependency + * of plugin extensions. The main usage for a plugin is to benefit from new APIs + * while keeping backward-compatibility with previous versions of SonarQube. + * <br><br> + * + * Example 1: a {@link Sensor} wants to use an API introduced in version 5.5 and still requires to support older versions + * at runtime. + * <pre> + * public class MySensor implements Sensor { + * + * public void execute(SensorContext context) { + * if (context.getRuntimeApiVersion().isGreaterThanOrEqual(RuntimeApiVersion.V5_5)) { + * context.newMethodIntroducedIn5_5(); + * } + * } + * } + * </pre> + * + * Example 2: a plugin needs to use an API introduced in version 5.6 ({@code AnApi} in the following + * snippet) and still requires to support version 5.5 at runtime. + * <br> + * <pre> + * // Component provided by sonar-plugin-api + * // @since 5.5 + * public interface AnApi { + * // implicitly since 5.5 + * public void foo(); + * + * // @since 5.6 + * public void bar(); + * } + * + * // Component provided by plugin + * public class MyExtension { + * private final RuntimeApiVersion runtimeApiVersion; + * private final AnApi api; + * + * public MyExtension(RuntimeApiVersion runtimeApiVersion, AnApi api) { + * this.runtimeApiVersion = runtimeApiVersion; + * this.api = api; + * } + * + * public void doSomething() { + * // assume that runtime is 5.5+ + * api.foo(); + * + * if (runtimeApiVersion.isGreaterThanOrEqual(SonarQubeVersion.V5_6)) { + * api.bar(); + * } + * } + * } + * </pre> + * <p> + * The minimal supported version of plugin API is verified at runtime. As plugin is built + * with sonar-plugin-api 5.6, we assume that the plugin requires v5.6 or greater at runtime. + * For this reason the plugin must default which is the minimal supported version + * in the configuration of sonar-packaging-maven-plugin 1.16+: + * <p> + * <pre> + * <packaging>sonar-plugin</packaging> + * + * <dependencies> + * <dependency> + * <groupId>org.sonarsource.sonarqube</groupId> + * <artifactId>sonar-plugin-api</artifactId> + * <version>5.6</version> + * <scope>provided</scope> + * </dependency> + * </dependencies> + * + * <build> + * <plugins> + * <plugin> + * <groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId> + * <artifactId>sonar-packaging-maven-plugin</artifactId> + * <version>1.16</version> + * <extensions>true</extensions> + * <configuration> + * <!-- Override the default value 5.6 which is guessed from sonar-plugin-api dependency --> + * <sonarQubeMinVersion>5.5</sonarQubeMinVersion> + * </configuration> + * </plugin> + * </plugins> + * </build> + * </pre> + * + * + * @since 6.0 + */ +@BatchSide +@ServerSide +@ComputeEngineSide +@Immutable +public class RuntimeApiVersion { + + /** + * Constant for version 5.5 + */ + public static final Version V5_5 = Version.create(5, 5); + + /** + * Constant for version 5.6 + */ + public static final Version V5_6 = Version.create(5, 6); + + private final Version version; + private final boolean sonarlint; + + public RuntimeApiVersion(Version version, boolean sonarlint) { + requireNonNull(version); + this.version = version; + this.sonarlint = sonarlint; + } + + public Version get() { + return this.version; + } + + public boolean isGreaterThanOrEqual(Version than) { + return this.version.isGreaterThanOrEqual(than); + } + + /** + * @since 6.0 Test if current runtime is SonarLint. Can be used to implement a different behavior. + */ + public boolean isSonarlintRuntime() { + return sonarlint; + } + +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/SonarQubeVersion.java b/sonar-plugin-api/src/main/java/org/sonar/api/SonarQubeVersion.java index cbd08aa0090..6b8a1e5cdbd 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/SonarQubeVersion.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/SonarQubeVersion.java @@ -26,8 +26,6 @@ import org.sonar.api.ce.ComputeEngineSide; import org.sonar.api.server.ServerSide; import org.sonar.api.utils.Version; -import static java.util.Objects.requireNonNull; - /** * Version of SonarQube at runtime. This component can be injected as a dependency * of plugin extensions. The main usage for a plugin is to benefit from new APIs @@ -117,36 +115,17 @@ import static java.util.Objects.requireNonNull; * * * @since 5.5 + * @deprecated since 6.0 replaced by {@link RuntimeApiVersion} */ @ScannerSide @ServerSide @ComputeEngineSide @Immutable -public class SonarQubeVersion { - - /** - * Constant for version 5.5 - */ - public static final Version V5_5 = Version.create(5, 5); - - /** - * Constant for version 5.6 - */ - public static final Version V5_6 = Version.create(5, 6); - - private final Version version; - - public SonarQubeVersion(Version version) { - requireNonNull(version); - this.version = version; - } - - public Version get() { - return this.version; - } +@Deprecated +public class SonarQubeVersion extends RuntimeApiVersion { - public boolean isGreaterThanOrEqual(Version than) { - return this.version.isGreaterThanOrEqual(than); + public SonarQubeVersion(Version version, boolean sonarlint) { + super(version, sonarlint); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/Sensor.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/Sensor.java index 2eae58b055a..6a776b5974c 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/Sensor.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/Sensor.java @@ -22,6 +22,7 @@ package org.sonar.api.batch.sensor; import org.sonar.api.ExtensionPoint; import org.sonar.api.batch.ScannerSide; import org.sonar.api.batch.sensor.internal.SensorContextTester; +import org.sonarsource.api.sonarlint.SonarLintSide; /** * <p> @@ -34,6 +35,7 @@ import org.sonar.api.batch.sensor.internal.SensorContextTester; * @since 5.1 */ @ScannerSide +@SonarLintSide @ExtensionPoint public interface Sensor { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java index bb1aa0fd922..4970132e71a 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java @@ -64,9 +64,22 @@ public interface SensorContext { /** * @since 5.5 + * @deprecated since 6.0 replaced by {@link #getRuntimeApiVersion()} */ + @Deprecated Version getSonarQubeVersion(); + /** + * @since 6.0 + */ + Version getRuntimeApiVersion(); + + /** + * Test if plugin is currently executed in SonarLint. This can allow to implement a different behavior. + * @since 6.0 + */ + boolean isSonarLintRuntime(); + // ----------- MEASURES -------------- /** diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java index 12cd04842db..9c3c8476028 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java @@ -58,7 +58,7 @@ import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure; import org.sonar.api.batch.sensor.symbol.NewSymbolTable; import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable; import org.sonar.api.config.Settings; -import org.sonar.api.internal.SonarQubeVersionFactory; +import org.sonar.api.internal.RuntimeApiVersionFactory; import org.sonar.api.measures.Metric; import org.sonar.api.utils.System2; import org.sonar.api.utils.Version; @@ -95,7 +95,7 @@ public class SensorContextTester implements SensorContext { this.activeRules = new ActiveRulesBuilder().build(); this.sensorStorage = new InMemorySensorStorage(); this.module = new DefaultInputModule("projectKey"); - this.sqVersion = SonarQubeVersionFactory.create(System2.INSTANCE); + this.sqVersion = RuntimeApiVersionFactory.create(System2.INSTANCE, false); } public static SensorContextTester create(File moduleBaseDir) { @@ -145,8 +145,18 @@ public class SensorContextTester implements SensorContext { return sqVersion.get(); } - public SensorContextTester setSonarQubeVersion(Version version) { - this.sqVersion = new SonarQubeVersion(version); + @Override + public Version getRuntimeApiVersion() { + return sqVersion.get(); + } + + @Override + public boolean isSonarLintRuntime() { + return sqVersion.isSonarlintRuntime(); + } + + public SensorContextTester setRuntime(Version version, boolean isSonarLint) { + this.sqVersion = new SonarQubeVersion(version, isSonarLint); return this; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/internal/SonarQubeVersionFactory.java b/sonar-plugin-api/src/main/java/org/sonar/api/internal/RuntimeApiVersionFactory.java index db85c3feaf1..fd098bd4a64 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/internal/SonarQubeVersionFactory.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/internal/RuntimeApiVersionFactory.java @@ -30,19 +30,19 @@ import org.sonar.api.utils.Version; /** * For internal use only. */ -public class SonarQubeVersionFactory { +public class RuntimeApiVersionFactory { private static final String FILE_PATH = "/sq-version.txt"; - private SonarQubeVersionFactory() { + private RuntimeApiVersionFactory() { // prevents instantiation } - public static SonarQubeVersion create(System2 system) { + public static SonarQubeVersion create(System2 system, boolean isSonarLint) { try { URL url = system.getResource(FILE_PATH); String versionInFile = Resources.toString(url, StandardCharsets.UTF_8); - return new SonarQubeVersion(Version.parse(versionInFile)); + return new SonarQubeVersion(Version.parse(versionInFile), isSonarLint); } catch (IOException e) { throw new IllegalStateException("Can not load " + FILE_PATH + " from classpath", e); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Language.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Language.java index 4143453f79e..cb46f76912a 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Language.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Language.java @@ -24,6 +24,7 @@ import org.sonar.api.batch.ScannerSide; import org.sonar.api.batch.InstantiationStrategy; import org.sonar.api.ce.ComputeEngineSide; import org.sonar.api.server.ServerSide; +import org.sonarsource.api.sonarlint.SonarLintSide; /** * The extension point to define a new language @@ -35,6 +36,7 @@ import org.sonar.api.server.ServerSide; @ScannerSide @InstantiationStrategy(InstantiationStrategy.PER_BATCH) @ServerSide +@SonarLintSide @ComputeEngineSide @ExtensionPoint public interface Language { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java index a09bd9df96b..722b7ed6233 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java @@ -40,13 +40,14 @@ import javax.annotation.concurrent.Immutable; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.sonar.api.ExtensionPoint; +import org.sonar.api.ce.ComputeEngineSide; import org.sonar.api.rule.RuleStatus; import org.sonar.api.rule.Severity; import org.sonar.api.rules.RuleType; -import org.sonar.api.ce.ComputeEngineSide; import org.sonar.api.server.ServerSide; import org.sonar.api.server.debt.DebtRemediationFunction; import org.sonar.api.utils.log.Loggers; +import org.sonarsource.api.sonarlint.SonarLintSide; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; @@ -149,6 +150,7 @@ import static org.apache.commons.lang.StringUtils.trimToNull; */ @ServerSide @ComputeEngineSide +@SonarLintSide @ExtensionPoint public interface RulesDefinition { @@ -672,6 +674,7 @@ public interface RulesDefinition { private final Set<String> tags = Sets.newTreeSet(); private final Map<String, NewParam> paramsByKey = Maps.newHashMap(); private final DebtRemediationFunctions functions; + private boolean activatedByDefault; private NewRule(String repoKey, String key) { this.repoKey = repoKey; @@ -696,6 +699,15 @@ public interface RulesDefinition { return this; } + /** + * Should this rule be enabled by default. For example in SonarLint standalone. + * @since 6.0 + */ + public NewRule setActivatedByDefault(boolean activatedByDefault) { + this.activatedByDefault = activatedByDefault; + return this; + } + public NewRule setSeverity(String s) { checkArgument(Severity.ALL.contains(s), "Severity of rule %s is not correct: %s", this, s); this.severity = s; @@ -915,6 +927,7 @@ public interface RulesDefinition { private final Set<String> tags; private final Map<String, Param> params; private final RuleStatus status; + private final boolean activatedByDefault; private Rule(Repository repository, NewRule newRule) { this.repository = repository; @@ -936,6 +949,7 @@ public interface RulesDefinition { paramsBuilder.put(newParam.key, new Param(newParam)); } this.params = paramsBuilder.build(); + this.activatedByDefault = newRule.activatedByDefault; } public Repository repository() { @@ -976,6 +990,14 @@ public interface RulesDefinition { return template; } + /** + * Should this rule be enabled by default. For example in SonarLint standalone. + * @since 6.0 + */ + public boolean activatedByDefault() { + return activatedByDefault; + } + public RuleStatus status() { return status; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionAnnotationLoader.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionAnnotationLoader.java index 9be365feb29..d1d1e7399db 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionAnnotationLoader.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionAnnotationLoader.java @@ -54,8 +54,7 @@ public class RulesDefinitionAnnotationLoader { .put(Boolean.class, RuleParamType.BOOLEAN) .put(boolean.class, RuleParamType.BOOLEAN) .build(), - RuleParamType.STRING - ); + RuleParamType.STRING); public void load(RulesDefinition.NewExtendedRepository repo, Class... annotatedClasses) { for (Class annotatedClass : annotatedClasses) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionI18nLoader.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionI18nLoader.java index 8876b6b4cc8..0094564287b 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionI18nLoader.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionI18nLoader.java @@ -21,8 +21,6 @@ package org.sonar.api.server.rule; import org.apache.commons.lang.StringUtils; import org.sonar.api.i18n.RuleI18n; -import org.sonar.api.ce.ComputeEngineSide; -import org.sonar.api.server.ServerSide; /** * Loads the English bundles of rules (name, description and parameters) that are @@ -36,8 +34,6 @@ import org.sonar.api.server.ServerSide; * @see org.sonar.api.server.rule.RulesDefinition for an example * @since 4.3 */ -@ServerSide -@ComputeEngineSide public class RulesDefinitionI18nLoader { private final RuleI18n i18n; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java index 71020e0b28d..0f21dd71306 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java @@ -32,13 +32,14 @@ import javax.xml.stream.XMLStreamException; import org.codehaus.staxmate.SMInputFactory; import org.codehaus.staxmate.in.SMHierarchicCursor; import org.codehaus.staxmate.in.SMInputCursor; +import org.sonar.api.ce.ComputeEngineSide; import org.sonar.api.rule.RuleStatus; import org.sonar.api.rule.Severity; import org.sonar.api.rules.RuleType; -import org.sonar.api.ce.ComputeEngineSide; import org.sonar.api.server.ServerSide; import org.sonar.api.server.debt.DebtRemediationFunction; import org.sonar.check.Cardinality; +import org.sonarsource.api.sonarlint.SonarLintSide; import static java.lang.String.format; import static org.apache.commons.lang.StringUtils.equalsIgnoreCase; @@ -180,6 +181,7 @@ import static org.apache.commons.lang.StringUtils.trim; */ @ServerSide @ComputeEngineSide +@SonarLintSide public class RulesDefinitionXmlLoader { private enum DescriptionFormat { diff --git a/sonar-plugin-api/src/main/java/org/sonarsource/api/sonarlint/SonarLintSide.java b/sonar-plugin-api/src/main/java/org/sonarsource/api/sonarlint/SonarLintSide.java new file mode 100644 index 00000000000..3be3aa27477 --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonarsource/api/sonarlint/SonarLintSide.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonarsource.api.sonarlint; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Marker annotation for all the components available in container of sonarlint. Note that + * injection of dependencies by constructor is used : + * <pre> + * {@literal @}SonarLintSide + * public class Foo { + * + * } + * {@literal @}SonarLintSide + * public class Bar { + * private final Foo foo; + * public Bar(Foo f) { + * this.foo = f; + * } + * } + * + * </pre> + * + * @since 6.0 + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface SonarLintSide { +} diff --git a/sonar-plugin-api/src/main/java/org/sonarsource/api/sonarlint/package-info.java b/sonar-plugin-api/src/main/java/org/sonarsource/api/sonarlint/package-info.java new file mode 100644 index 00000000000..2806d2a47da --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonarsource/api/sonarlint/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +@ParametersAreNonnullByDefault +package org.sonarsource.api.sonarlint; + +import javax.annotation.ParametersAreNonnullByDefault; 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 6a2602a5450..853a48bd59c 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 @@ -23,13 +23,13 @@ import java.util.Arrays; import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; -import static org.sonar.api.SonarQubeVersion.V5_5; +import static org.sonar.api.RuntimeApiVersion.V5_5; public class PluginTest { @Test public void test_context() { - Plugin.Context context = new Plugin.Context(V5_5); + Plugin.Context context = new Plugin.Context(V5_5, true); assertThat(context.getSonarQubeVersion()).isEqualTo(V5_5); assertThat(context.getExtensions()).isEmpty(); diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/RuntimeApiVersionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/RuntimeApiVersionTest.java new file mode 100644 index 00000000000..e7fb658e2eb --- /dev/null +++ b/sonar-plugin-api/src/test/java/org/sonar/api/RuntimeApiVersionTest.java @@ -0,0 +1,45 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.api; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.utils.Version; + +import static org.assertj.core.api.Assertions.assertThat; + +public class RuntimeApiVersionTest { + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Test + public void isGte() { + Version version = Version.parse("1.2.3"); + RuntimeApiVersion apiVersion = new RuntimeApiVersion(version, false); + assertThat(apiVersion.get()).isEqualTo(version); + assertThat(apiVersion.isSonarlintRuntime()).isFalse(); + assertThat(apiVersion.isGreaterThanOrEqual(version)).isTrue(); + assertThat(apiVersion.isGreaterThanOrEqual(Version.parse("1.1"))).isTrue(); + assertThat(apiVersion.isGreaterThanOrEqual(Version.parse("1.3"))).isFalse(); + } + +} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/SonarQubeVersionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/SonarQubeVersionTest.java index 50bc4b1c2ec..e5ef829db69 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/SonarQubeVersionTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/SonarQubeVersionTest.java @@ -34,8 +34,9 @@ public class SonarQubeVersionTest { @Test public void isGte() { Version version = Version.parse("1.2.3"); - SonarQubeVersion qubeVersion = new SonarQubeVersion(version); + SonarQubeVersion qubeVersion = new SonarQubeVersion(version, true); assertThat(qubeVersion.get()).isEqualTo(version); + assertThat(qubeVersion.isSonarlintRuntime()).isTrue(); assertThat(qubeVersion.isGreaterThanOrEqual(version)).isTrue(); assertThat(qubeVersion.isGreaterThanOrEqual(Version.parse("1.1"))).isTrue(); assertThat(qubeVersion.isGreaterThanOrEqual(Version.parse("1.3"))).isFalse(); diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/internal/SonarQubeVersionFactoryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/internal/RuntimeApiVersionFactoryTest.java index d37f7693d10..69b3cca8c54 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/internal/SonarQubeVersionFactoryTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/internal/RuntimeApiVersionFactoryTest.java @@ -31,16 +31,17 @@ import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; -public class SonarQubeVersionFactoryTest { +public class RuntimeApiVersionFactoryTest { @Rule public ExpectedException expectedException = ExpectedException.none(); @Test public void create() { - SonarQubeVersion version = SonarQubeVersionFactory.create(System2.INSTANCE); + SonarQubeVersion version = RuntimeApiVersionFactory.create(System2.INSTANCE, true); assertThat(version).isNotNull(); assertThat(version.get().major()).isGreaterThanOrEqualTo(5); + assertThat(version.isSonarlintRuntime()).isTrue(); } @Test @@ -50,7 +51,7 @@ public class SonarQubeVersionFactoryTest { System2 system = spy(System2.class); when(system.getResource(anyString())).thenReturn(new File("target/unknown").toURI().toURL()); - SonarQubeVersionFactory.create(system); + RuntimeApiVersionFactory.create(system, false); } } |