Class SonarQubeVersion
- java.lang.Object
-
- org.sonar.api.SonarQubeVersion
-
@ScannerSide @ServerSide @ComputeEngineSide @Immutable @Deprecated public class SonarQubeVersion extends java.lang.Object
Deprecated.since 7.8 UseSonarRuntime
instead.Version of SonarQube at runtime, but not at compilation time. 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 API.Example: a plugin extension needs a new feature of API 6.0 without breaking compatibility with version 5.6 at runtime. This new feature would be disabled when plugin is executed within SonarQube 5.6.
// Component provided by sonar-plugin-api // @since 5.6 public interface AnApi { // implicitly since 5.6 public void foo(); // @since 6.0 public void bar(); } // Component provided by plugin public class MyExtension { private final SonarQubeVersion sonarQubeVersion; private final AnApi api; public MyExtension(SonarQubeVersion sonarQubeVersion, AnApi api) { this.sonarQubeVersion = sonarQubeVersion; this.api = api; } public void doSomething() { // assume that runtime is 5.6+ api.foo(); if (sonarQubeVersion.isGreaterThanOrEqual(Version.create(6, 0))) { api.bar(); } } }
Note that
Sensor
extensions can directly getSonarQubeVersion
throughSensorContext.getSonarQubeVersion()
, without using constructor injection:public class MySensor implements Sensor { public void execute(SensorContext context) { if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(6, 0)) { context.newMethodIntroducedIn6_0(); } } }
The minimal supported version of SonarQube is verified at runtime. As plugin is built with sonar-plugin-api 6.0, we assume that the plugin requires v6.0 or greater at runtime. As the plugin codebase is compatible with 5.6, the plugin must define what is the effective minimal supported version through the configuration of sonar-packaging-maven-plugin 1.16+:
<packaging>sonar-plugin</packaging> <dependencies> <dependency> <groupId>org.sonarsource.sonarqube</groupId> <artifactId>sonar-plugin-api</artifactId> <version>6.0</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 6.0 which is guessed from sonar-plugin-api dependency --> <sonarQubeMinVersion>5.6</sonarQubeMinVersion> </configuration> </plugin> </plugins> </build>
The component
SonarRuntime
, introduced in version 6.0, is more complete. It is preferred overSonarQubeVersion
if compatibility with version 5.6 Long Term Support is not required.- Since:
- 5.5
- See Also:
SonarRuntime
-
-
Constructor Summary
Constructors Constructor Description SonarQubeVersion(Version version)
Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Version
get()
Deprecated.boolean
isGreaterThanOrEqual(Version than)
Deprecated.
-
-
-
Constructor Detail
-
SonarQubeVersion
public SonarQubeVersion(Version version)
Deprecated.
-
-