123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- /*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info 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.scanner.ScannerSide;
- import org.sonar.api.batch.sensor.Sensor;
- import org.sonar.api.batch.sensor.SensorContext;
- 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, 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.
- *
- * <p>
- * 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.
- * </p>
- * <pre>
- * // 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();
- * }
- * }
- * }
- * </pre>
- *
- * <p>
- * Note that {@link Sensor} extensions can directly get {@link SonarQubeVersion} through
- * {@link SensorContext#getSonarQubeVersion()}, without using constructor injection:
- * </p>
- * <pre>
- * public class MySensor implements Sensor {
- *
- * public void execute(SensorContext context) {
- * if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(6, 0)) {
- * context.newMethodIntroducedIn6_0();
- * }
- * }
- *
- * }
- * </pre>
- * <p>
- * 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+:
- * <p>
- * <pre>
- * <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>
- * </pre>
- *
- * <p>
- * The component {@link SonarRuntime}, introduced in version 6.0, is more complete.
- * It is preferred over {@link SonarQubeVersion} if compatibility with version 5.6 Long Term Support
- * is not required.
- * </p>
- *
- * @see SonarRuntime
- * @deprecated since 7.8 Use {@link SonarRuntime} instead.
- * @since 5.5
- */
- @ScannerSide
- @ServerSide
- @ComputeEngineSide
- @Immutable
- @Deprecated
- public class SonarQubeVersion {
-
- private final Version version;
-
- public SonarQubeVersion(Version version) {
- requireNonNull(version);
- this.version = version;
- }
-
- public Version get() {
- return this.version;
- }
-
- public boolean isGreaterThanOrEqual(Version than) {
- return this.version.isGreaterThanOrEqual(than);
- }
- }
|