From 9097b10693f9c4fe2c7bde4bccdbca151ebfa452 Mon Sep 17 00:00:00 2001 From: Jacek Date: Mon, 30 May 2022 18:50:42 +0200 Subject: SONAR-16232 Use plugin api version for SonarRuntime impl - introduce internal SonarQubeVersion --- .../org/sonar/core/platform/SonarQubeVersion.java | 55 ++++++++++++++++++++++ .../sonar/core/platform/SonarQubeVersionTest.java | 39 +++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 sonar-core/src/main/java/org/sonar/core/platform/SonarQubeVersion.java create mode 100644 sonar-core/src/test/java/org/sonar/core/platform/SonarQubeVersionTest.java (limited to 'sonar-core') diff --git a/sonar-core/src/main/java/org/sonar/core/platform/SonarQubeVersion.java b/sonar-core/src/main/java/org/sonar/core/platform/SonarQubeVersion.java new file mode 100644 index 00000000000..322fcc372ff --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/platform/SonarQubeVersion.java @@ -0,0 +1,55 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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.core.platform; + +import javax.annotation.concurrent.Immutable; +import org.sonar.api.ce.ComputeEngineSide; +import org.sonar.api.scanner.ScannerSide; +import org.sonar.api.server.ServerSide; +import org.sonar.api.utils.Version; + +import static java.util.Objects.requireNonNull; + +@ScannerSide +@ServerSide +@ComputeEngineSide +@Immutable +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); + } + + @Override + public String toString() { + return version.toString(); + } +} diff --git a/sonar-core/src/test/java/org/sonar/core/platform/SonarQubeVersionTest.java b/sonar-core/src/test/java/org/sonar/core/platform/SonarQubeVersionTest.java new file mode 100644 index 00000000000..5a457f05034 --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/platform/SonarQubeVersionTest.java @@ -0,0 +1,39 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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.core.platform; + +import org.junit.Test; +import org.sonar.api.utils.Version; + +import static org.assertj.core.api.Assertions.assertThat; + +public class SonarQubeVersionTest { + + @Test + public void verify_methods() { + var version = Version.create(9, 5); + SonarQubeVersion underTest = new SonarQubeVersion(version); + assertThat(underTest).extracting(SonarQubeVersion::toString, SonarQubeVersion::get) + .containsExactly("9.5", version); + + var otherVersion = Version.create(8, 5); + assertThat(underTest.isGreaterThanOrEqual(otherVersion)).isTrue(); + } +} -- cgit v1.2.3